Fix for issue #23: null panic if logger obj is null due no active syslog sink

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2020-02-17 00:02:28 -08:00
parent 9ffeab2456
commit c2c43c1c50
2 changed files with 33 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
// Priority is the logger priority // Priority is the logger priority
type Priority = sl.Priority type Priority = sl.Priority
// Writer is a syslog Writer // Writer is a syslog Writer
type Writer = sl.Writer type Writer = sl.Writer
@ -75,50 +76,81 @@ func New(flags Priority, tag string) (w *Writer, e error) {
// Alert returns a log Alert error // Alert returns a log Alert error
func Alert(s string) error { func Alert(s string) error {
if l != nil {
return l.Alert(s) return l.Alert(s)
}
return nil
} }
// LogClose closes the log Writer. // LogClose closes the log Writer.
func LogClose() error { func LogClose() error {
if l != nil {
return l.Close() return l.Close()
}
return nil
} }
// LogCrit returns a log Alert error // LogCrit returns a log Alert error
func LogCrit(s string) error { func LogCrit(s string) error {
if l != nil {
return l.Crit(s) return l.Crit(s)
}
return nil
} }
// LogDebug returns a log Debug error // LogDebug returns a log Debug error
func LogDebug(s string) error { func LogDebug(s string) error {
if l != nil {
return l.Debug(s) return l.Debug(s)
}
return nil
} }
// LogEmerg returns a log Emerg error // LogEmerg returns a log Emerg error
func LogEmerg(s string) error { func LogEmerg(s string) error {
if l != nil {
return l.Emerg(s) return l.Emerg(s)
}
return nil
} }
// LogErr returns a log Err error // LogErr returns a log Err error
func LogErr(s string) error { func LogErr(s string) error {
if l != nil {
return l.Err(s) return l.Err(s)
}
return nil
} }
// LogInfo returns a log Info error // LogInfo returns a log Info error
func LogInfo(s string) error { func LogInfo(s string) error {
if l != nil {
return l.Info(s) return l.Info(s)
}
return nil
} }
// LogNotice returns a log Notice error // LogNotice returns a log Notice error
func LogNotice(s string) error { func LogNotice(s string) error {
if l != nil {
return l.Notice(s) return l.Notice(s)
}
return nil
} }
// LogWarning returns a log Warning error // LogWarning returns a log Warning error
func LogWarning(s string) error { func LogWarning(s string) error {
if l != nil {
return l.Warning(s) return l.Warning(s)
}
return nil
} }
// LogWrite writes to the logger at default level // LogWrite writes to the logger at default level
func LogWrite(b []byte) (int, error) { func LogWrite(b []byte) (int, error) {
if l != nil {
return l.Write(b) return l.Write(b)
}
return len(b),nil
} }

View File

@ -41,9 +41,9 @@ import (
"time" "time"
hkex "blitter.com/go/herradurakex" hkex "blitter.com/go/herradurakex"
"blitter.com/go/xs/logger"
"blitter.com/go/kyber" "blitter.com/go/kyber"
"blitter.com/go/newhope" "blitter.com/go/newhope"
"blitter.com/go/xs/logger"
) )
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/