-
Notifications
You must be signed in to change notification settings - Fork 94
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
Test logging interface #463
base: main
Are you sure you want to change the base?
Conversation
da2edcc
to
d85c5c5
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.
Thanks!
tests/common/mod.rs
Outdated
pub log_writer: TestLogWriter, | ||
} | ||
|
||
impl Default for TestConfig { |
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.
No need for this impl
, just add Default
to the derive
above.
tests/common/mod.rs
Outdated
@@ -251,6 +253,34 @@ pub(crate) enum TestChainSource<'a> { | |||
BitcoindRpc(&'a BitcoinD), | |||
} | |||
|
|||
#[derive(Clone)] | |||
pub(crate) enum TestLogWriter { |
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.
While TestConfig
could have some general utility going forward, I'm not quite convinced we need all this boilerplate just to switch the logger in a one-off test. We could at least simplify this enum
, no?
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.
Simplified it a bit to this. We don't really need the fields in the FileWriter
variant as we are not really testing this, but the facade and custom variants are left as we test both of them.
#[derive(Clone)]
pub(crate) enum TestLogWriter {
FileWriter,
LogFacade(LogLevel),
Custom(Arc<dyn LogWriter>),
}
tests/common/mod.rs
Outdated
pub(crate) fn init_log_logger(level: LevelFilter) -> Arc<MockLogger> { | ||
let logger = Arc::new(MockLogger::new()); | ||
log::set_boxed_logger(Box::new(logger.clone())).unwrap(); | ||
log::set_max_level(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.
Hmm, if this is part of the log
API anyways, should we drop our max_log_level
value in the log facade related builder methods and LogWriter
variants? Do you have an opinion here? Do we gain much by also limiting on our end?
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.
@enigbe Gentle ping here, as we're looking to ship v0.5 in the coming days. Do you think it makes sense to drop the max_log_level
for the log facade logger, too, or do we need it?
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, if this is part of the
log
API anyways, should we drop ourmax_log_level
value in the log facade related builder methods andLogWriter
variants? Do you have an opinion here? Do we gain much by also limiting on our end
If we keep the max_log_level
, we'd have to nudge users to align the facade level with the LevelFilter
given that they can be compared directly. However, we won't have any control over this because setting the max level should be done by the active log implementation.
Do you think it makes sense to drop the max_log_level for the log facade logger, too, or do we need it?
It'd be cleaner to removemax_log_level
.
If we are going with the latter, would it be okay to add a commit for it to this PR?
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.
Also, apologies for the late changes. I am ramping up into LDK
and got side-tracked.
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.
If we keep the max_log_level, we'd have to nudge users to align the facade level with the LevelFilter given that they can be compared directly. However, we won't have any control over this because setting the max level should be done by the active log implementation.
Right then it might be better to drop it, at least for now.
If we are going with the latter, would it be okay to add a commit for it to this PR?
Yeah, feel free to append another commit here for it.
Also, apologies for the late changes. I am ramping up into LDK and got side-tracked.
No worries!
tests/integration_tests_rust.rs
Outdated
|
||
let logger = init_log_logger(LevelFilter::Trace); | ||
let mut config = random_config(false); | ||
config.log_writer = TestLogWriter::LogFacade { max_log_level: LogLevel::Gossip }; |
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.
See above, a bit awkward that we have an additional filter on the level.
d85c5c5
to
bff5778
Compare
@tnull. |
bff5778
to
30bee82
Compare
tests/common/mod.rs
Outdated
TestLogWriter::FileWriter => { | ||
let file_path = format!("{}/{}", DEFAULT_STORAGE_DIR_PATH, DEFAULT_LOG_FILENAME); | ||
let max_log_level = DEFAULT_LOG_LEVEL; | ||
builder.set_filesystem_logger(Some(file_path), Some(max_log_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.
If we're using defaults anyways, why are we overriding them here? Shouldn't we just use None
s instead?
30bee82
to
4e59771
Compare
This is in need of a rebase now. |
4e59771
to
7e27939
Compare
Rebased. |
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.
Excuse the delay here, I wasn't realizing you previously addressed the comments.
Basically LGTM, please feel free to squash the fixups.
General improvements: - Add TestConfig wrapper around Config to allow per-test log field overrides while preserving the general test setup. - Test facade logger. - Add logging module and validate log entries. - Improve UniFFI logging adding UniFFI flag for relevant log objects. - Remove facade level, because the concrete `Log` impl controls max log level.
7e27939
to
56d5dc9
Compare
Thanks once again for your reviews @tnull. Squashed all fixes. |
What this PR does
This is another follow-up PR to #407 where we test the
log
facade and custom logging interfaces.It follows an earlier conversation to address testing without explicitly configuring the logger in all test cases.
cc @tnull