enhance systemd integration
* log level identification * manual activation with flag * automatic systemd launch detection
This commit is contained in:
parent
3edc9ff0b0
commit
c58023a9ba
8 changed files with 59 additions and 19 deletions
24
fs/log.go
24
fs/log.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
sysdjournald "github.com/iguanesolutions/go-systemd/v5/journald"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -70,7 +71,28 @@ func (l *LogLevel) Type() string {
|
|||
|
||||
// LogPrint sends the text to the logger of level
|
||||
var LogPrint = func(level LogLevel, text string) {
|
||||
text = fmt.Sprintf("%-6s: %s", level, text)
|
||||
var prefix string
|
||||
if Config.LogSystemdSupport {
|
||||
switch level {
|
||||
case LogLevelDebug:
|
||||
prefix = sysdjournald.DebugPrefix
|
||||
case LogLevelInfo:
|
||||
prefix = sysdjournald.InfoPrefix
|
||||
case LogLevelNotice:
|
||||
prefix = sysdjournald.NoticePrefix
|
||||
case LogLevelWarning:
|
||||
prefix = sysdjournald.WarningPrefix
|
||||
case LogLevelError:
|
||||
prefix = sysdjournald.ErrPrefix
|
||||
case LogLevelCritical:
|
||||
prefix = sysdjournald.CritPrefix
|
||||
case LogLevelAlert:
|
||||
prefix = sysdjournald.AlertPrefix
|
||||
case LogLevelEmergency:
|
||||
prefix = sysdjournald.EmergPrefix
|
||||
}
|
||||
}
|
||||
text = fmt.Sprintf("%s%-6s: %s", prefix, level, text)
|
||||
_ = log.Output(4, text)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue