Switched to tracing for logging

This commit is contained in:
2024-05-02 16:50:05 +03:00
parent 4ac34a73bb
commit e8be611404
4 changed files with 152 additions and 74 deletions

View File

@ -1,4 +1,5 @@
use std::fmt::{Debug, Display};
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
#[derive(thiserror::Error, Debug)]
#[error("No user info found")]
@ -20,12 +21,20 @@ pub enum InvalidCommand {
UnknownLocale,
}
#[inline]
pub fn init_logger() {
tracing_subscriber::registry()
.with(fmt::layer().pretty())
.with(EnvFilter::from_default_env())
.init();
}
#[inline]
pub fn handle_error<T>(error: T)
where
T: Debug + Display,
{
log::error!("{error}\n{error:?}");
tracing::error!(error_debug = ?error, error_message = %error);
}
pub struct ErrorHandler;

View File

@ -88,7 +88,7 @@ fn get_dispatcher(
#[tokio::main]
async fn main() -> Result<()> {
let _ = dotenv();
pretty_env_logger::init_timed();
errors::init_logger();
locales::LocaleStore::init();