2022-03-14 20:58:13 +00:00
|
|
|
//go:build linux
|
2020-10-14 00:10:57 +00:00
|
|
|
|
|
|
|
package journald
|
|
|
|
|
|
|
|
import (
|
2023-04-17 04:22:34 +00:00
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/coreos/go-systemd/journal"
|
|
|
|
"github.com/sirupsen/logrus"
|
2020-10-14 00:10:57 +00:00
|
|
|
)
|
|
|
|
|
2023-04-17 04:22:34 +00:00
|
|
|
// Enable adds the Journal hook if journal is enabled
|
|
|
|
// Sets log output to ioutil.Discard so stdout isn't captured.
|
2020-10-14 00:10:57 +00:00
|
|
|
func Enable() error {
|
2023-04-17 04:22:34 +00:00
|
|
|
if !journal.Enabled() {
|
|
|
|
logrus.Warning("Journal not available but user requests we log to it. Ignoring")
|
|
|
|
} else {
|
|
|
|
logrus.AddHook(&JournalHook{})
|
|
|
|
logrus.SetOutput(io.Discard)
|
|
|
|
}
|
2020-10-14 00:10:57 +00:00
|
|
|
return nil
|
|
|
|
}
|