-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
systemd journal support #66
Comments
Doesn't |
@sirupsen: So, strictly speaking, systemd's journal can consume stdout / stderr, but it can also understand structure logs, eg |
For syslog we actually have it as a hook, but still log to stdout/stderr. Is the simplest approach here to pass an Actually... that's not really great either, because hooks are fired before the formatter and ordering is not guaranteed so it quickly turns into a hack. hm |
For now I'd probably recommend doing that, and then being explicit about making it the last hook. |
going to be implementing this internally. The use-case for us is journald will only read up to LINE_MAX characters per line, and our lines are a bit longer. LMK if anyone's interested and will see about open sourcing it. |
@mwhooker how are you going implement it? |
@sirupsen it's actually pretty simple func (hook *JournaldHook) Fire(entry *logrus.Entry) error {
return journal.Send(entry.Message, severityMap[entry.Level], stringifyEntries(entry.Data))
} where stringifyEntries has the signature I didn't see the same points above about wanting a formatter since journal wants a string message and a map of key/values. We also have to |
Here's the published library. https://github.com/wercker/journalhook happy to take comments |
It looks like this was removed from the readme. Is there any particular reason? Is this still a valid approach? |
you can use stdout / stderr with systemd but systemd doesn't set the log-level accordingly to circumvent that you have to do syslog or direct systemd journal logging |
Yeah, I need the specific log levels implemented properly. |
pauldotknopf wrote:
Well, the readme now links to a long hook list in the wiki which still includes the original systemd journald hook link. I presume that at some point the hook list was moved to a separate page because it grew to long. |
I couldn't find a proper place to ask for help so I figured I'll try in this issue since the hook page is archived. Using the journalhook with logs with fields like in
Logging with the journalhook I'll see the message "Finshed adding att" but would not get the fields. |
@potuz the problem relies on the If you can't find another journalhook that uses the formatter, then copy that hook code into your project and make it use the formatter in your func (hook *JournalHook) Fire(entry *logrus.Entry) error {
message, err := entry.String()
if err == nil {
return journal.Send(message, severityMap[entry.Level], stringifyEntries(entry.Data))
}
return err
} Logrus is not responsible for hooks not using the formatters. |
Systemd's journal support could be added by using the
go-systemd
lib:https://github.com/coreos/go-systemd/blob/master/journal/send.go
It is kinda funny however to make it a "Hook" -- you kinda want it to be a log formatter, but the current interface for formatters assumes an io.Copy() interface, while for
journal.Send
you would want the 'formatter' to handle the 'write'.A quick hack would be to allow Formatters to return
nil
, and in that case skip the io.Copy paths?The text was updated successfully, but these errors were encountered: