Skip to content
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

Apply env_logger module filters on Dart & UniFFI binding loggers #874

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

erdemyerebasmaz
Copy link
Contributor

@erdemyerebasmaz erdemyerebasmaz commented Mar 19, 2024

This PR addresses the issue where env_logger's module filters were not applying to logs listened through Dart & UniFFI binding loggers.

Changelist:

  • Filter Dart & UniFFI binding logs through env_logger module filters
  • Move loggers under logger.rs
  • Make filter levels customizable for each logger
  • Log node-logs according to their level
  • Apply changes to bindings & generate them
    • Create LevelFilter struct that's usable from bindings.
    • Add optional filter_level param to binding logger init & setters
    • Map models:LevelFilter to log::LevelFilter.
      • Set LevelFilter::TRACE as default filter level

TODO:

@erdemyerebasmaz
Copy link
Contributor Author

Depends on:

});
}

pub struct UniFFILogger {
Copy link
Member

Choose a reason for hiding this comment

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

Why taking the specific loggers out of their specific crates?
Doesn't UniFFILogger belong to the sdk-bindings crate?

Copy link
Contributor Author

@erdemyerebasmaz erdemyerebasmaz Mar 27, 2024

Choose a reason for hiding this comment

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

Not necessarily, the loggers are not exposed through bindings.

I had brought them together to see the differences to find the root cause of the issue, and I prefer having them together, but we can bring them back to uniffi_bindings.rs & bindings.rs with little to no change.

If we expand upon logger settings as mentioned on #892, it would be hard to miss applying new changes on bindings when they are grouped together like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree putting these in the bindings crate seems logical

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

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

Concept ACK! A few nits. (And ofcourse this needs a rebase, which will be painful)

Comment on lines 21 to 54
debug,
breez_sdk_core::backup=info,
breez_sdk_core::breez_services=info,
breez_sdk_core::input_parser=warn,
breez_sdk_core::persist::reverseswap=info,
breez_sdk_core::reverseswap=info,
gl_client::node=info,
gl_client::node::service=info,
gl_client::tls=info,
gl_client::scheduler=info,
gl_client::signer=info,
gl_client=debug,
h2=warn,
h2::client=info,
h2::codec::framed_read=warn,
h2::codec::framed_write=warn,
h2::proto::connection=info,
h2::proto::settings=info,
hyper=warn,
hyper::client::connect::dns=info,
hyper::client::connect::https=info,
lightning_signer=warn,
lightning_signer::node=warn,
reqwest=warn,
reqwest::connect=warn,
rustls=warn,
rustls::anchors=warn,
rustls::conn=warn,
rustls::client::common=warn,
rustls::client::hs=warn,
rustls::client::tls13=warn,
rustyline=warn,
rusqlite_migration=warn,
tower::buffer::worker=warn,
vls_protocol_signer=warn,
vls_protocol_signer::handler::HandlerBuilder::do_build=warn
Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE: I've changed the log filters in #1098

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the missing sdk_common=debug, should be enough imo.

We can make the necessary individual changes after making comparisons if there are any.

writeln!(
buf,
"[{} {} {}:{}] {}",
Local::now().format("%Y-%m-%d %H:%M:%S%.3f"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use UTC if possible with ISO8601 format

Copy link
Contributor Author

Choose a reason for hiding this comment

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

});
}

pub struct UniFFILogger {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree putting these in the bindings crate seems logical

- Create LevelFilter struct that's usable from bindings.
- Add optional filter_level param to binding logger init & setters
- Map models:LevelFilter to log::LevelFilter.
  - Set LevelFilter::TRACE as default filter level
Log `UNUSUAL` level node logs at `Error` level
Copy link
Contributor

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

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

Added a few comments

);
}
*guard = Some(stream_sink);
drop(guard)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is done automatically when the guard goes out of scope.

use log::{
max_level, set_boxed_logger, set_max_level, warn, Log, Metadata, Record, STATIC_MAX_LEVEL,
};
use parking_lot::RwLock;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason to use parking_lot here? Can we use std::sync::RwLock or tokio::sync::RwLock?

let prefix_len = l.line.find(':').map_or(0, |len| len + 2);
let log_message = l.line.split_at(prefix_len).1.trim_start();
match l.line.to_ascii_lowercase().as_str() {
s if s.starts_with("unusual") => error!("node-logs: {}", log_message),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think unusual can be warn

And broken needs to be added as error

Comment on lines +19 to +30
breez_sdk_core::backup=info,
breez_sdk_core::breez_services=info,
breez_sdk_core::input_parser=warn,
breez_sdk_core::persist::reverseswap=info,
breez_sdk_core::reverseswap=info,
sdk_common=debug,
gl_client::node=info,
gl_client::node::service=info,
gl_client::tls=info,
gl_client::scheduler=info,
gl_client::signer=info,
gl_client=debug,
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, debug level logs would be filtered out regardless of the client's loglevel. I would put all these at debug, or even trace, because they would eventually be filtered out by the client log level.

/* env_logger */

const ENV_LOGGER_FILTER: &str = r#"
debug,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should either depend on client log level or be info in my opinion

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should create one of these filter statements per log level

Copy link
Collaborator

@dangeross dangeross left a comment

Choose a reason for hiding this comment

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

These RN codegen changes in breez/breez-sdk-rn-generator#23 should be applied in libs/sdk-bindings/bindings-react-native

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.

Print logs from Dart & UniFFI binding loggers on LogCat & OSLog
4 participants