make proper logging to file as well as writing errors to stderr. ditch idea with non_blocking because that's not async thing
This commit is contained in:
parent
8a6965a24f
commit
ae3c0a9557
2 changed files with 15 additions and 14 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
use anyhow;
|
use anyhow;
|
||||||
use sqlx::migrate::MigrateDatabase;
|
use sqlx::migrate::MigrateDatabase;
|
||||||
use sqlx::{Sqlite, SqlitePool};
|
use sqlx::{Sqlite, SqlitePool};
|
||||||
use tracing::{event, Level};
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
@ -12,6 +11,7 @@ use teloxide::dispatching::dialogue::InMemStorage;
|
||||||
use teloxide::dispatching::UpdateHandler;
|
use teloxide::dispatching::UpdateHandler;
|
||||||
use teloxide::types::InputFile;
|
use teloxide::types::InputFile;
|
||||||
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
|
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
|
||||||
|
use tracing::{event, Level};
|
||||||
|
|
||||||
use super::log::log_init;
|
use super::log::log_init;
|
||||||
use super::util::make_database_url;
|
use super::util::make_database_url;
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,26 @@
|
||||||
|
use std::io;
|
||||||
|
use tracing::level_filters::LevelFilter;
|
||||||
|
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
||||||
|
use tracing_subscriber::{fmt, layer::SubscriberExt, prelude::*};
|
||||||
|
|
||||||
use super::util::VAR_LOG;
|
use super::util::VAR_LOG;
|
||||||
use tracing::Level;
|
|
||||||
use tracing_appender::{
|
|
||||||
non_blocking,
|
|
||||||
rolling::{RollingFileAppender, Rotation},
|
|
||||||
};
|
|
||||||
use tracing_subscriber::fmt;
|
|
||||||
|
|
||||||
pub fn log_init() {
|
pub fn log_init() {
|
||||||
let file_appender = RollingFileAppender::builder()
|
let log_appender = RollingFileAppender::builder()
|
||||||
.rotation(Rotation::DAILY)
|
.rotation(Rotation::DAILY)
|
||||||
.filename_prefix("mk-dl-bot.log")
|
.filename_prefix("mk-dl-bot.log")
|
||||||
.max_log_files(7)
|
.max_log_files(7)
|
||||||
.build(VAR_LOG)
|
.build(VAR_LOG)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
//let (non_blocking, _guard) = non_blocking(file_appender);
|
let stderr_layer = fmt::layer()
|
||||||
|
.with_writer(io::stderr)
|
||||||
|
.with_filter(LevelFilter::ERROR);
|
||||||
|
|
||||||
let subscriber = fmt()
|
let file_layer = fmt::layer().with_writer(log_appender);
|
||||||
.with_writer(file_appender)
|
|
||||||
.with_ansi(true)
|
tracing_subscriber::registry()
|
||||||
.with_max_level(Level::TRACE)
|
.with(stderr_layer)
|
||||||
.pretty()
|
.with(file_layer)
|
||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue