pretty up logging
This commit is contained in:
parent
246de9a018
commit
bbefe801d3
14
log.go
14
log.go
|
@ -25,7 +25,7 @@ import (
|
||||||
|
|
||||||
// log.Default() not added until go 1.16
|
// log.Default() not added until go 1.16
|
||||||
func logdefault() *log.Logger {
|
func logdefault() *log.Logger {
|
||||||
return log.New(os.Stderr, os.Args[0], log.LstdFlags)
|
return log.New(os.Stderr, "", log.LstdFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
var elog = logdefault()
|
var elog = logdefault()
|
||||||
|
@ -50,28 +50,28 @@ func initLogging(elogname, ilogname, dlogname string) {
|
||||||
|
|
||||||
func openlog(name string, prio syslog.Priority) *log.Logger {
|
func openlog(name string, prio syslog.Priority) *log.Logger {
|
||||||
if name == "stderr" {
|
if name == "stderr" {
|
||||||
return log.New(os.Stderr, os.Args[0], log.LstdFlags)
|
return log.New(os.Stderr, "", log.LstdFlags)
|
||||||
}
|
}
|
||||||
if name == "stdout" {
|
if name == "stdout" {
|
||||||
return log.New(os.Stdout, os.Args[0], log.LstdFlags)
|
return log.New(os.Stdout, "", log.LstdFlags)
|
||||||
}
|
}
|
||||||
if name == "null" {
|
if name == "null" {
|
||||||
return log.New(ioutil.Discard, os.Args[0], log.LstdFlags)
|
return log.New(ioutil.Discard, "", log.LstdFlags)
|
||||||
}
|
}
|
||||||
if name == "syslog" {
|
if name == "syslog" {
|
||||||
logger, err := syslog.NewLogger(syslog.LOG_UUCP|prio, 0)
|
w, err := syslog.New(syslog.LOG_UUCP|prio, "honk")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
elog.Printf("can't create syslog: %s", err)
|
elog.Printf("can't create syslog: %s", err)
|
||||||
return logdefault()
|
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)
|
fd, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
elog.Printf("can't open log file %s: %s", name, err)
|
elog.Printf("can't open log file %s: %s", name, err)
|
||||||
return logdefault()
|
return logdefault()
|
||||||
}
|
}
|
||||||
logger := log.New(fd, os.Args[0], log.LstdFlags)
|
logger := log.New(fd, "", log.LstdFlags)
|
||||||
logger.Printf("new log started")
|
logger.Printf("new log started")
|
||||||
return logger
|
return logger
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue