-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 logger: use tracing crate for logging spans
- Loading branch information
1 parent
3435edb
commit dbb80bb
Showing
5 changed files
with
239 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::utils; | ||
|
||
use tracing_appender::non_blocking::WorkerGuard; | ||
use tracing_subscriber::prelude::*; | ||
use tracing_subscriber::EnvFilter; | ||
|
||
pub fn setup_logger() -> WorkerGuard { | ||
// set log level from RUST_LOG env var | ||
let env_filter = EnvFilter::try_from_default_env(); | ||
|
||
// create subscriber env filter | ||
let subscriber_env_filter = | ||
env_filter.unwrap_or_else(|_| EnvFilter::new("debug,i18n_embed=warn")); | ||
|
||
// create stdout layer | ||
let stdout_log = tracing_subscriber::fmt::layer().compact().with_writer(std::io::stdout); | ||
|
||
// create just a file appender, without rolling | ||
let file_appender = tracing_appender::rolling::never( | ||
utils::fix_path("~/.config/cachyos/cachyos-hello"), | ||
"cachyos-hello.log", | ||
); | ||
|
||
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); | ||
let file_log = | ||
tracing_subscriber::fmt::layer().compact().with_ansi(false).with_writer(non_blocking); | ||
|
||
tracing_subscriber::registry() | ||
.with(file_log) | ||
.with(stdout_log) | ||
.with(subscriber_env_filter) | ||
.init(); | ||
|
||
_guard | ||
} |
Oops, something went wrong.