-
Notifications
You must be signed in to change notification settings - Fork 15
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
Disable stdout logging for release builds #47
Conversation
ThomasFrans
commented
Jun 15, 2022
- disable the logo on stdout in release builds
- disable the log messages on stdout in release builds
- disable the logo on stdout in release builds - disable the log messages on stdout in release builds
This may be more of a personal preference. Maybe it's not wanted in which case, please ignore this request 🙂 But it's nice not to have unnecessary output to stdout in release builds (it's a pretty valid point in the Unix philosophy). The debug build can still have output, but it would be better to put release logs in the log file (which also shouldn't be put in the current working directory, but that's an issue for another time 😄 ). |
Thank you for your PR! Yes, you are completely right, it's nice not to have unnecessary output in stdout in release builds but I've noticed that this will remove the logging completely (also the logging into the log file). Because the logging gets configured within the config, we have two loggers configured within To change the directory where the log file is saved, we can just give the logger another directory (currently we use the current working directory). So we could modify the config option log_dir = ".config/wiki-tui/wiki_tui.log" would save the log file in the same directory as the config file. Would this way of changing the log directory be better? |
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.
To disable the logging to stdout in the release build we can change the following things in logging.rs
:
diff --git a/src/logging.rs b/src/logging.rs
index 491c3ad..67953aa 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -15,9 +15,15 @@ impl Logger {
let default_config = Config::builder()
.appender(Appender::builder().build("wiki_tui", Box::new(wiki_tui)))
.build(
+ #[cfg(debug_assertions)]
Root::builder()
.appender("wiki_tui")
.build(log::LevelFilter::Info),
+
+ #[cfg(not(debug_assertions))]
+ Root::builder()
+ .appender("wiki_tui")
+ .build(log::LevelFilter::Off),
)
.unwrap();
This will disable only the stdout logger in release builds
Cargo.toml
Outdated
@@ -22,7 +22,7 @@ blt-backend = ["cursive/blt-backend"] | |||
[dependencies] | |||
syn = "=1.0.57" | |||
serde_json = "1.0.61" | |||
log = "0.4.13" | |||
log = { version = "0.4.13", features = ["release_max_level_off"]} |
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.
Here we should remove the "release_max_level_off" feature because this disables logging completely (we need that for crash reports)
I'll try to make the changes you suggested here. One detail about the recommendation for the log dir, it should probably go in the cache directory, .config is the XDG_USER_CONFIG directory, used for configuration files only. There are some crates on crates.io that provide the standard directories on different platforms, maybe those could be used? https://crates.io/crates/directories |
Yep, that makes sense. We are already using a crate that provides the standard directories on different platforms (dirs) so it wouldn't be much of a hassle to use it to get the cache directory. I will make a PR that moves the log file in a few hours |
- disable logging to stdout - keep logging to the log file for release builds
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.
Looks good, thank you! (I will let GitHub finish the running actions, then merge the PR)