generated from PlexSheep/baserepo
refactor(log): remove depereciated Logger::build()
cargo devel CI / cargo CI (push) Failing after 1m37s
Details
cargo devel CI / cargo CI (push) Failing after 1m37s
Details
This commit is contained in:
parent
9b94c25234
commit
73f935d9b2
|
@ -373,167 +373,6 @@ impl Logger {
|
|||
LoggerBuilder::default()
|
||||
}
|
||||
|
||||
/// ## initializes the logger
|
||||
///
|
||||
/// Will enable the logger to be used.
|
||||
///
|
||||
/// Assumes some defaults, use [`init_customized`](Self::init_customized) for more control
|
||||
#[deprecated(since = "0.4.1", note = "use Logger::builder() instead")]
|
||||
pub fn build(log_dir: Option<PathBuf>, max_level: Option<Level>, uptime: bool) -> Result<Self> {
|
||||
#[allow(deprecated)]
|
||||
Self::build_customized(
|
||||
log_dir.is_some(),
|
||||
log_dir.unwrap_or(PathBuf::from(DEFAULT_LOG_DIR)),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
max_level.unwrap_or(DEFAULT_LOG_LEVEL),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
uptime,
|
||||
)
|
||||
}
|
||||
|
||||
/// ## initializes the logger
|
||||
///
|
||||
/// Will enable the logger to be used. This is a version that shows less information,
|
||||
/// useful in cases with only one sender to the logging framework.
|
||||
///
|
||||
/// Assumes some defaults, use [`init_customized`](Self::init_customized) for more control
|
||||
#[deprecated(since = "0.4.1", note = "use Logger::builder() instead")]
|
||||
pub fn build_mini(max_level: Option<Level>) -> Result<Self> {
|
||||
#[allow(deprecated)]
|
||||
Self::build_customized(
|
||||
false,
|
||||
PathBuf::from(DEFAULT_LOG_DIR),
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
max_level.unwrap_or(DEFAULT_LOG_LEVEL),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
/// ## initializes the logger
|
||||
///
|
||||
/// Will enable the logger to be used.
|
||||
#[deprecated(since = "0.4.1", note = "use Logger::builder() instead")]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn build_customized(
|
||||
log_to_file: bool,
|
||||
log_dir: PathBuf,
|
||||
ansi: bool,
|
||||
display_filename: bool,
|
||||
display_level: bool,
|
||||
display_target: bool,
|
||||
max_level: Level,
|
||||
display_thread_ids: bool,
|
||||
display_thread_names: bool,
|
||||
display_line_number: bool,
|
||||
pretty: bool,
|
||||
show_time: bool,
|
||||
uptime: bool, // uptime instead of system time
|
||||
) -> Result<Self> {
|
||||
// only init if no init has been performed yet
|
||||
if INITIALIZED.load(Ordering::Relaxed) {
|
||||
warn!("trying to reinitialize the logger, ignoring");
|
||||
bail!(Error::Usage("logging is already initialized".to_string()));
|
||||
}
|
||||
let subscriber = tracing_subscriber::fmt::Subscriber::builder()
|
||||
.with_level(display_level)
|
||||
.with_max_level(max_level)
|
||||
.with_ansi(ansi)
|
||||
.with_target(display_target)
|
||||
.with_file(display_filename)
|
||||
.with_thread_ids(display_thread_ids)
|
||||
.with_line_number(display_line_number)
|
||||
.with_thread_names(display_thread_names)
|
||||
.with_span_events(FmtSpan::FULL);
|
||||
// I know this is hacky, but I couldn't get it any other way. I couldn't even find a
|
||||
// project that could do it any other way. You can't apply one after another, because the
|
||||
// type is changed every time. When using Box<dyn Whatever>, some methods complain about
|
||||
// not being in trait bounds.
|
||||
// TODO: somehow find a better solution for this
|
||||
match (log_to_file, show_time, pretty, uptime) {
|
||||
(true, true, true, true) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(log_dir))
|
||||
.with_timer(time::uptime())
|
||||
.pretty()
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, true, true, false) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(log_dir))
|
||||
.pretty()
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, false, true, _) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(log_dir))
|
||||
.without_time()
|
||||
.pretty()
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, true, false, true) => {
|
||||
let subscriber = subscriber
|
||||
.with_writer(new_file_appender(log_dir))
|
||||
.with_timer(time::uptime())
|
||||
.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, true, false, false) => {
|
||||
let subscriber = subscriber.with_writer(new_file_appender(log_dir)).finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(true, false, false, _) => {
|
||||
let file_appender = tracing_appender::rolling::daily(log_dir.clone(), "log");
|
||||
let (file_writer, _guard) = tracing_appender::non_blocking(file_appender);
|
||||
let subscriber = subscriber.with_writer(file_writer).without_time().finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, true, true) => {
|
||||
let subscriber = subscriber.pretty().with_timer(time::uptime()).finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, true, false) => {
|
||||
let subscriber = subscriber.pretty().with_timer(time::uptime()).finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, false, true, _) => {
|
||||
let subscriber = subscriber.without_time().pretty().finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, false, true) => {
|
||||
let subscriber = subscriber.with_timer(time::uptime()).finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, true, false, false) => {
|
||||
let subscriber = subscriber.finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
(false, false, false, _) => {
|
||||
let subscriber = subscriber.without_time().finish();
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
}
|
||||
}
|
||||
INITIALIZED.store(true, Ordering::Relaxed);
|
||||
Ok(Logger {})
|
||||
}
|
||||
|
||||
/// ## logging at [`Level::ERROR`]
|
||||
pub fn error<T>(&self, printable: T)
|
||||
where
|
||||
|
|
Reference in New Issue