pretty up logging

This commit is contained in:
Ted Unangst 2022-02-09 16:11:35 -05:00
parent 246de9a018
commit bbefe801d3
1 changed files with 7 additions and 7 deletions

14
log.go
View File

@ -25,7 +25,7 @@ import (
// 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 initLogging(elogname, ilogname, dlogname string) {
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
}