pretty up logging
Ted Unangst tedu@tedunangst.com
Wed, 09 Feb 2022 16:11:35 -0500
1 files changed,
7 insertions(+),
7 deletions(-)
jump to
M
log.go
→
log.go
@@ -25,7 +25,7 @@ )
// log.Default() not added until go 1.16 func logdefault() *log.Logger { - return log.New(os.Stderr, os.Args[0], log.LstdFlags) + return log.New(os.Stderr, "", log.LstdFlags) } var elog = logdefault()@@ -50,28 +50,28 @@ }
func openlog(name string, prio syslog.Priority) *log.Logger { if name == "stderr" { - return log.New(os.Stderr, os.Args[0], log.LstdFlags) + return log.New(os.Stderr, "", log.LstdFlags) } if name == "stdout" { - return log.New(os.Stdout, os.Args[0], log.LstdFlags) + return log.New(os.Stdout, "", log.LstdFlags) } if name == "null" { - return log.New(ioutil.Discard, os.Args[0], log.LstdFlags) + return log.New(ioutil.Discard, "", log.LstdFlags) } if name == "syslog" { - logger, err := syslog.NewLogger(syslog.LOG_UUCP|prio, 0) + w, err := syslog.New(syslog.LOG_UUCP|prio, "honk") if err != nil { elog.Printf("can't create syslog: %s", err) return logdefault() } - return logger + return log.New(w, "", log.LstdFlags) } fd, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600) if err != nil { elog.Printf("can't open log file %s: %s", name, err) return logdefault() } - logger := log.New(fd, os.Args[0], log.LstdFlags) + logger := log.New(fd, "", log.LstdFlags) logger.Printf("new log started") return logger }