Skip to content

Add initial logging capability to agama-dbus-server#629

Merged
jreidinger merged 3 commits intomasterfrom
rust_logging
Jun 16, 2023
Merged

Add initial logging capability to agama-dbus-server#629
jreidinger merged 3 commits intomasterfrom
rust_logging

Conversation

@jreidinger
Copy link
Copy Markdown
Contributor

Problem

Currently agama-dbus-service does not provide any logging. So troubleshooting is hard.

trello: https://trello.com/c/qjrhMrmi/3378-2-agama-enable-a-logging-mechanism-in-agama-dbus-server

Solution

Add initial logging capability with systemd logger to be consistent with ruby counterpart that also logs to journal.

Testing

  • Tested manually

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 14, 2023

Coverage Status

Changes unknown
when pulling e34671c on rust_logging
into ** on master**.

@mvidner
Copy link
Copy Markdown
Contributor

mvidner commented Jun 15, 2023

Add initial logging capability with systemd logger to be consistent with ruby counterpart that also logs to journal.

No. AFAIK the Ruby part simply logs to stderr and it is the controlling daemons, systemd and dbus-daemon, that forward the output to the journal

See also this relevant example that we may want to copy, it uses more metadata when using the journal and falls back to stderr if run directly: https://codeberg.org/swsnr/systemd-journal-logger.rs/src/branch/main/examples/systemd_service.rs

@mvidner mvidner changed the title Add initial logging capability to agam-dbus-server Add initial logging capability to agama-dbus-server Jun 15, 2023

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
JournalLog::default().install().unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap...
should be used when you know better than the compiler that it cannot fail

The function is already returning a Result

Suggested change
JournalLog::default().install().unwrap();
JournalLog::default().install()?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and it turns out that you are right, it fails only if the logger has been set already
https://docs.rs/log/0.4.17/log/fn.set_boxed_logger.html

In that case I'd add a comment explaining why it can't fail. Might as well keep the ?.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will document it. As I am not big fan of Box due to its wide scope and with unwrap it will make it change to more precise error definition easier.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I am not big fan of Box due to its wide scope and with unwrap it will make it change to more precise error definition easier.

Just some nitpicking while I wait for the rustfmt CI run 😄

I think it is the dyn part, not the Box, that you object to :)

In general yes, it makes the error API too catch-all... but then we are in fn main and we can only crash... which also refutes my initial objection 🤣

Copy link
Copy Markdown
Contributor

@mvidner mvidner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// be smart with logging and log directly to journal if connected to it
if systemd_journal_logger::connected_to_journal(){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if systemd_journal_logger::connected_to_journal(){
if systemd_journal_logger::connected_to_journal() {

That reminds me, I don't know how to check for formatting problems. How? Should we make it mandatory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, I again forget to run rustfmt before submit. I will try to configure my IDE to do it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw I can add it to CI with something like find rust/agama-*/src/ | grep '.rs$' | xargs rustfmt --check --edition 2021

@mvidner
Copy link
Copy Markdown
Contributor

mvidner commented Jun 16, 2023

So it turns out automatic rustfmt is crazily nontrivial to set up, postponing that.

@jreidinger jreidinger merged commit 6461acc into master Jun 16, 2023
@jreidinger jreidinger deleted the rust_logging branch June 16, 2023 12:20
@imobachgs imobachgs mentioned this pull request Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants