Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How to set minimum log levels? #174

Closed
imbolc opened this issue Feb 12, 2021 · 5 comments
Closed

How to set minimum log levels? #174

imbolc opened this issue Feb 12, 2021 · 5 comments

Comments

@imbolc
Copy link

imbolc commented Feb 12, 2021

Is there a way to set different log levels for different crates (to filter verbose debug messages of some libs), something like RUST_LOG variable for env_logger? I can't find any configuration options after systemd::journal::JournalLog::init().

@codyps
Copy link
Owner

codyps commented Feb 13, 2021

The current journal log support in this crate is very minimal: it redirects all log messages to the journal without any filtering, and assumes one would use filtering when retrieving the logs. This is primarily because I didn't want to try to reproduce filtering here. And yes, this is likely way too noisy if some libraries that make heavy use of debug/trace messages are built in.

There may be other crates that allow control over the output to the systemd journal, or if not, one could write one that uses the APIs exposed in this crate to log output.

I've, in the past, thought about splitting out the support for log into a separate crate so that we'd be more free to add additional functionality to it.

Right now this is the extent of our logger:

https://github.com/jmesmon/rust-systemd/blob/8137b283bda83a04f58fbec7c936ca365c65a6cd/src/journal.rs#L85-L106

Modifying the enabled() entry would be needed to add hooks for filtering (whether from env_logger or elsewhere).

I'm open to accepting changes to the included logger that add some filtering functionality. Even better if there's some existing log filtering crate we can just pull in and call in enabled().

@imbolc
Copy link
Author

imbolc commented Feb 13, 2021

You're right, it makes more sense to add journal as a target to env_logger rather than copying all the filtering machinery here. I'll ask there, thank you.

@codyps
Copy link
Owner

codyps commented Feb 13, 2021

I'm not sure env_logger really has a setup for plugable outputs: it appears to just expose stderr and stdout. There are other logging systems (slog, tracing) that do have plugable outputs and have some support for filtering in similar ways to env_logger. For those, I believe the approach is to create a new crate that adapts the logging framework (slog/tracing) to the output sink (systemd journal, in this case).

(Even if the solution you go with doesn't involve updating this systemd crate to add filtering, I'd be very interested in what you end up using)

@imbolc
Copy link
Author

imbolc commented Feb 13, 2021

Yep, there's no plugins in env_logger, though they're already discussing adding a file Target, so I've opened a similar issue on journald. Tracing already has journald subscriber. It just emotionally hard for me to bring tracing into a simple cli tool with a synchronous workflow :)

@imbolc
Copy link
Author

imbolc commented Feb 16, 2021

Hey :) I ended up using tracing, here's the setup: https://gist.github.com/imbolc/f75f924f66c129f0e1e910f59fb75c0d

@codyps codyps closed this as completed Feb 16, 2021
Repository owner locked and limited conversation to collaborators Feb 16, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants