-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed syslogs function to build only for non-windows OS (#8248)
- Loading branch information
Showing
2 changed files
with
45 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//go:build !windows | ||
|
||
package logging | ||
|
||
import ( | ||
"log/syslog" | ||
"strings" | ||
|
||
"github.com/sirupsen/logrus" | ||
lSyslog "github.com/sirupsen/logrus/hooks/syslog" | ||
) | ||
|
||
func ContextUnavailableWithSysLogs(sysLogsLevel string) Logger { | ||
// wrap formatter with our own formatter that overrides caller | ||
formatterInitOnce.Do(func() { | ||
defaultLogger.SetReportCaller(true) | ||
defaultLogger.SetNoLock() | ||
defaultLogger.Formatter = logrusCallerFormatter{defaultLogger.Formatter} | ||
}) | ||
syslogOnce.Do(func() { | ||
var hook *lSyslog.SyslogHook | ||
var err error | ||
switch strings.ToLower(sysLogsLevel) { | ||
// There's no syslog level for trace, using debug instead. | ||
case "trace", "debug": | ||
hook, err = lSyslog.NewSyslogHook("", "", syslog.LOG_DEBUG, "") | ||
case "info": | ||
hook, err = lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "") | ||
case "warn", "warning": | ||
hook, err = lSyslog.NewSyslogHook("", "", syslog.LOG_WARNING, "") | ||
case "error": | ||
hook, err = lSyslog.NewSyslogHook("", "", syslog.LOG_ERR, "") | ||
case "panic", "null", "none": | ||
hook, err = lSyslog.NewSyslogHook("", "", syslog.LOG_CRIT, "") | ||
} | ||
if err != nil { | ||
defaultLogger.WithError(err).Error("failed to set syslog hook") | ||
} else { | ||
defaultLogger.AddHook(hook) | ||
} | ||
}) | ||
return &logrusEntryWrapper{ | ||
e: logrus.NewEntry(defaultLogger), | ||
} | ||
} |