-
Notifications
You must be signed in to change notification settings - Fork 139
Systemd log format activable via env var #349
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
Comments
specifically for systemd its quite easy to automatically detect being run as a daemon. |
defaults matter a lot. developers want to run their binaries in terminal and see timestamps, users want to run applications as daemons and see timestamps only once. people simply will not have a more complex setup. and this is a real issue, i am sure @RCasatta has observed this in a rust application they were running, and so have i. |
Sorry, I missed read this (being used to multi-platform system logs being rendered out of band from stdout). Looking back over #358, this is just about changing the output format.
I am open to auto-detection.
I don't think we need a specific variable to control the auto-detection: we can expose a function that matches the custom format signature and people can customize things as they want.
That is specific to binaries, not libraries, and I assume binaries will generally know they will be run in a daemon mode to support something like this. The format used in this was Box::new(|buf, record| {
writeln!(
buf,
"<{}>{}: {}",
match record.level() {
Level::Error => 3,
Level::Warn => 4,
Level::Info => 6,
Level::Debug => 7,
Level::Trace => 7,
},
record.target(),
record.args()
)
}) Where is the relevant documentation for this? My initial searches come up short. |
the format was literally copied from the example in this repository, after cross-checking with the relevant manpages to verify that this is actually a valid way to log to syslog. there is more valid ways, for example by providing a timestamp, but that gets auto-filled in by the syslog. |
I confirm I use it with systemd and it works. For example you can filter error logs via:
|
Was not aware of that example, thanks! In that case, for anything we do, we should update or remove that example. We'll also need to ensure people have a good way of discovering this functionality. |
just to be explicit here: you have tested #358 and it solves your usecase? |
i have updated the example. discoverability is not worse now, and also somewhat optional as it should just work, thats the magic of good defaults. |
@djugei what are your thoughts on the plain I laid out in #349 (comment)? To re-summarize
The main question I have is whether we provide a |
From #358 (comment)
|
If I understand correctly, you are wanting to strip Looks like Some solutions I see include
What I'm unsure of is how universal people would want this. While it is redundant, I could also see it being helpful when you have log messages coming from a variety of crates. This could also make writing of |
That seems like a sensible approach though currently i am unsure to what extent customizing the syslog format is useful. |
I updated my program with something along the lines of https://github.com/rust-cli/env_logger/blob/main/examples/syslog_friendly_format.rs to have a systemd friendly logging, however when I use other binaries using env_logger usually the same logic is not available, can we have it enable-able by default in env_logger?
ie if
RUST_LOG_STYLE=SYSTEMD
the default formatting is changed with the systemd friendly one without having to change the downstream libThe text was updated successfully, but these errors were encountered: