forked from DevComp/ssh-portfolio
fix(logging): not compiling in release mode due to conditional
This commit is contained in:
parent
ebddeaa21e
commit
8dad453cc6
1 changed files with 9 additions and 4 deletions
|
@ -2,7 +2,7 @@ use std::io::stderr;
|
||||||
|
|
||||||
use color_eyre::{eyre::eyre, Result};
|
use color_eyre::{eyre::eyre, Result};
|
||||||
use tracing_error::ErrorLayer;
|
use tracing_error::ErrorLayer;
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter, util::TryInitError};
|
use tracing_subscriber::{fmt, prelude::*, util::TryInitError, EnvFilter};
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ pub fn init() -> Result<()> {
|
||||||
// Build the subscriber and apply it
|
// Build the subscriber and apply it
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(env_filter)
|
.with(env_filter)
|
||||||
|
.with(ErrorLayer::default())
|
||||||
.with(
|
.with(
|
||||||
// Logging to file
|
// Logging to file
|
||||||
fmt::layer()
|
fmt::layer()
|
||||||
|
@ -66,15 +67,19 @@ pub fn init() -> Result<()> {
|
||||||
let layer = fmt::layer()
|
let layer = fmt::layer()
|
||||||
.with_writer(stderr)
|
.with_writer(stderr)
|
||||||
.with_timer(tracing_subscriber::fmt::time())
|
.with_timer(tracing_subscriber::fmt::time())
|
||||||
|
.with_thread_ids(true)
|
||||||
.with_ansi(true);
|
.with_ansi(true);
|
||||||
|
|
||||||
// Enable compact mode for release logs
|
// Enable compact mode for release logs
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
return layer.compact();
|
let layer = layer
|
||||||
#[cfg(debug_assertions)]
|
.compact()
|
||||||
|
.without_time()
|
||||||
|
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::NONE)
|
||||||
|
.with_target(false)
|
||||||
|
.with_thread_ids(false);
|
||||||
layer
|
layer
|
||||||
})
|
})
|
||||||
.with(ErrorLayer::default())
|
|
||||||
.try_init()
|
.try_init()
|
||||||
.map_err(|err: TryInitError| eyre!(err))
|
.map_err(|err: TryInitError| eyre!(err))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue