-
Notifications
You must be signed in to change notification settings - Fork 90
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.
@@ -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?
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.
Yes we should. I created a new CustomLogWriter
class via which we can set the log level and also test LogWriter
. Ran into some issues with NoPointer
/Pointer.NULL
when testing this (due to unfamiliarity with Kotlin) and would appreciate any pointers to resolve.
tests/common/mod.rs
Outdated
} | ||
|
||
/// 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
?
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.
NodeBuilder
is Debug
, and it fields an optional LogWriterConfig
. The config object has to be Debug
and custom log writer variant needs to implement it for this reason.
@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. |
1d57cab
to
d8eb0e1
Compare
7fa2928
to
283fe85
Compare
@enigbe Please let me know if/when this is ready for the next round of review! |
0660dfa
to
6766c60
Compare
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.
@tnull I believe this is ready for another review. I have addressed the majority of the concerns you raised in the first pass.
Regarding your concerns about testing the logging to custom loggers, I agree that the necessary refactor would be extensive and could detract from the purpose of this PR. As such, I plan to address these test-related changes in a follow-up PR.
Additionally, I encountered some challenges testing a custom logger in Kotlin and would greatly appreciate your guidance or suggestions.
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.
Did another round of review, already looks pretty good.
I took a quick look at the Kotlin failures, but also couldn't immediately spot what's up, let me know if you want me to have a closer look though.
Btw, you could consider rebasing on #426 (or on main after it lands) which generally fixes pre-existing CI failures.
src/logger.rs
Outdated
|
||
impl LogWriter for Writer { | ||
fn log(&self, record: LogRecord) { | ||
let log = format!( |
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.
Hmm, so format!
allocates a string on the heap. As we try to avoid allocations (to reduce heap fragmentation where possible), can we a) only create this string when we're sure we need it to log (i.e, after passing the log level filtering), and b) can we avoid it altogether for the CustomWriter
case, and possibly even the LogFacadeWriter
case? In the latter case we should be able to give the arguments to the respective macros directly, no?
...in/ldk-node-android/lib/src/androidTest/kotlin/org/lightningdevkit/ldknode/AndroidLibTest.kt
Show resolved
Hide resolved
322f97f
to
3b71223
Compare
src/payment/unified_qr.rs
Outdated
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.
Feel free to drop this commit and rebase cleanly on main.
* 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.
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.
…ehavior - Removed trait name in description. - Expanded the description of the `LogWriter` trait to clarify its behavior when the `uniffi` feature is enabled or disabled. - Improved explanation of the trait’s responsibilities, including handling log messages and forwarding to outputs.
- Add a custom Debug implementation for LogWriterConfig to work around NodeBuilder's Debug constraints. - Remove the Debug trait from LogWriter, as it is no longer needed due to the custom Debug impl on LogWriterConfig. - Remove the Debug implementation from Writer for consistency.
- Revert MockLogger configuration and assertions - Remove clutter from setting up LogWriter across all tests
- Remove remnants of TestLogWriter and MockLogger that will be reintroduced in a later PR to add a more structured TestConfig object.
Removes the default_log_* functions that were hitherto public functions used to share private constants. These constants (DEFAULT_LOG_LEVEL and the renamed DEFAULT_LOG_FILE_PATH) have been made public instead.
With this, we avoid cloning the log writer config before calls to setup_logger. The default behaiour is also handled at a single location.
Additionally, clone Arc to custom_log_writer idiomatically.
Replacing the FilesystemLoggerConfig previously used by the NodeBuilder to configure the logging to the filesystem.
Removes them from LogWriterConfig and new_custom_writer
3b71223
to
a61455a
Compare
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