-
Notifications
You must be signed in to change notification settings - Fork 84
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
Add configurable logging system #407
base: main
Are you sure you want to change the base?
Add configurable logging system #407
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thank you for looking into this! This already looks pretty good, but I have some comments after the first round of review.
bindings/ldk_node.udl
Outdated
@@ -27,6 +25,20 @@ dictionary EsploraSyncConfig { | |||
u64 fee_rate_cache_update_interval_secs; | |||
}; | |||
|
|||
enum LdkLevel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave this as LogLevel
. I don't think we want to start prefixing any of the types we expose in the API with Ldk
. The prefix is really only used internally when we want to introduce a local type with the same name as an LDK type.
bindings/ldk_node.udl
Outdated
|
||
dictionary FilesystemLoggerConfig { | ||
string log_file_path; | ||
LdkLevel level; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also call the field here log_level
.
@@ -28,13 +28,11 @@ class AndroidLibTest { | |||
config1.storageDirPath = tmpDir1 | |||
config1.listeningAddresses = listOf(listenAddress1) | |||
config1.network = Network.REGTEST | |||
config1.logLevel = LogLevel.TRACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still set TRACE level, just by the new means?
Cargo.toml
Outdated
@@ -75,6 +75,7 @@ libc = "0.2" | |||
uniffi = { version = "0.27.3", features = ["build"], optional = true } | |||
serde = { version = "1.0.210", default-features = false, features = ["std", "derive"] } | |||
serde_json = { version = "1.0.128", default-features = false, features = ["std"] } | |||
log = { version = "0.4.22", features = ["std"]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add default-features = false
here and only include the features we really need.
src/builder.rs
Outdated
let logger = setup_logger(&self.config)?; | ||
let writer = LogWriterConfig::default(); | ||
let log_writer_config = | ||
if let Some(config) = &self.log_writer_config { config } else { &writer }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be able to just use unwrap_or_default()
here.
src/logger.rs
Outdated
pub(crate) enum Writer { | ||
/// Writes logs to the file system. | ||
FileWriter(FilesystemLogger), | ||
/// Forwards logs to the `log` facade. | ||
LogFacadeWriter(LogFacadeLogger), | ||
/// Forwards logs to custom writer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/custom writer/a custom writer/
} | ||
|
||
/// Simple in-memory mock `log` logger for tests. | ||
#[derive(Debug)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this Debug
?
@@ -271,9 +274,18 @@ impl MockLogger { | |||
} | |||
} | |||
|
|||
/// [`MockLogger`] as `log` logger - destination for [`Writer::LogFacadeWriter`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to belong in a different commit? Also, let's not add documents on trait implementations (internal ones in particular).
tests/integration_tests_rust.rs
Outdated
@@ -828,13 +831,16 @@ fn generate_bip21_uri() { | |||
}, | |||
Err(e) => panic!("Failed to generate URI: {:?}", e), | |||
} | |||
|
|||
assert!(mock_logger.retrieve_logs().last().unwrap().contains("Invoice created: lnbcrt")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above: please avoid such potentially-flaky assert
s. Also, we should really be testing the log facade separately instead of sprinkling in these assert
s to unrelated testcases.
} | ||
|
||
#[test] | ||
fn unified_qr_send_receive() { | ||
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); | ||
let chain_source = TestChainSource::Esplora(&electrsd); | ||
|
||
// Setup `log` facade logger. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for arbitrary comments: please only add comments where they add to the context. Comments like this don't provide additional information over just reading the next line, they just increase the (visual) noise when reading code.
@enigbe Is there any update on this? Please let me know if you're hitting any blockers. This seems to need a minor rebase by now. |
No blockers on this. I'll be pushing updates later today. |
* Add flexible log writer interface for multiple destinations * Implement filesystem writing capability via FilesystemLogger * Prefix LDK-based objects with 'Ldk' for consistency * Add configuration options for log file path and log level
* Add support for user-provided custom logger to write logs to, allowing users to provide any logger that implements LogWriter * Add test to cover this use case, implementing Log- Writer for the mock, in-memory MockLogger.
1d57cab
to
d8eb0e1
Compare
This commit includes several improvements aimed at simplifying code, improving readability, and optimizing performance: - Inline enum struct fields to reduce indirection and clutter. - Rename structs to improve clarity and better reflect their purpose. - Enable specific feature flags in dependencies for a more streamlined build. - Eliminate unnecessary data allocations to optimize memory usage. - Correct minor grammatical error in documentation.
- allocates Strings only when necessary with `uniffi` feature, otherwise, keeps LogRecord fileds as lifetime references.
This commit adds a CustomLogWriter class to the kotlin library test, configuring the writer via the exposed node builder and tests the ability to log to the custom writer destination. [WIP]
Overview
This PR introduces a flexible logging system for LDK Node by implementing a
LogWriter
interface that supports writing logs to different destinations.What this PR does
LogWriter
interface, allowingWriter
variants to handle log output destinations. The supportedWriter
variants can now:LogWriter
to bindings.log
logger,LogWriter
logger.Related Issue(s)
logger
interface #309