Extract logger setup into it's own module and implement ShortTargetFormatter #902
Extract logger setup into it's own module and implement ShortTargetFormatter #902luisschwab wants to merge 3 commits intogetfloresta:masterfrom
ShortTargetFormatter #902Conversation
|
I'll update this so we only log a short module identifier when |
- Move the logger setup function into it's own module. - Rename it from `init_logging` to `start_logger`
72cebb1 to
eed6c95
Compare
ShortTargetFormatter
eed6c95 to
a340696
Compare
|
Pushed a340696 addressing @Davidson-Souza's reviews. Also moves the exit on error on logger init from |
a340696 to
8a45586
Compare
Vedd-Patel
left a comment
There was a problem hiding this comment.
also test for ShortTargetFormatter is not there
should i add a unit test for short_target mapping and formatter-level behavior under different verbosity\filter setups?
| let file_path = format!("{}/{}", data_directory, LOG_FILE); | ||
|
|
||
| // Validate the log file path (`<data_directory>/<LOG_FILE>`). | ||
| let _ = fs::OpenOptions::new() |
There was a problem hiding this comment.
start_logger exits the process inside .map_err(...) instead of returning io::Error despite exposing a Result API
this mixes concerns and makes the signature misleading
not getting if its correct or not as iam not getting the correct way to handle this pls let me know about this one!
| }); | ||
| } | ||
| // The guard must stay alive until the end of `main` to flush file logs when dropped. | ||
| let _logger_guard = start_logger( |
There was a problem hiding this comment.
start_logger(...) returns Result<Option<WorkerGuard>, io::Error> but the result is not handled
assigned to _logger_guard and dropped
any future recoverable errors would be silently ignored!
handling the results of thes explicitly will help ig
something like -
let _logger_guard = start_logger(...).unwrap_or_else(|e| { eprintln!(...); exit(1); });- keep
_logger_guardasOption<WorkerGuard>
The `ShortTargetFormatter` will match and replace the full module paths with short prefixes, when the log level is `Level::INFO` or higher. Otherwise, the full module path is kept.
8a45586 to
8d292ab
Compare
|
@Davidson-Souza fixed! |
|
ACK 8d292ab |
|
We should also log milliseconds when in debug |
a499b4a to
78692d3
Compare
|
Since you're touching logs, what about making log to file default on? This is the standard between implementations afaik |
Agreed, but this can be a follow up. We should also allow specifying a log path, like Bitcoin Core: Opened #947 for this |
|
@Davidson-Souza can you retrigger the no-std job? It's stuck |
Closes #561
This PR extracts the logger setup function into it's own module, does some minor logging-related cleanup on
main.rs, and implements a custom log formatter that replaces the full module path with a custom alias when the log level isLevel::INFOor higher.Logs on the default log level go from
2026-04-07 16:24:38 INFO floresta_wire::p2p_wire::node::chain_selector_ctx: Downloading headers from peer=9 at height=1 hash=00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048to
2026-04-07 16:22:30 INFO wire: Downloading headers from peer=10 at height=1 hash=00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048Changelog