Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
fix: use tracing to fix serenity logging
Browse files Browse the repository at this point in the history
file logging is todo
  • Loading branch information
Sculas committed Jul 9, 2022
1 parent 6d8eb9a commit 704d05f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 63 deletions.
96 changes: 59 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ serde = { version = "1.0", features = ["derive"] }
dotenv = "0.15"
serde_json = "1.0"
tokio = { version = "1.0", features = ["rt-multi-thread"] }
log = { version = "0.4", features = ["max_level_debug", "release_max_level_info"] }
regex = "1.0"
serde_regex = "1.1"
chrono = "0.4"
serenity = { git = "https://github.com/serenity-rs/serenity.git", default_features = false, features = ["client", "gateway", "rustls_backend", "model"] }
simplelog = "0.12.0"
anyhow = "1.0.58"
serenity = { git = "https://github.com/serenity-rs/serenity.git", default_features = false, features = ["client", "gateway", "rustls_backend", "model"] }
dirs = "4.0.0"
tracing = { version = "0.1", features = ["max_level_debug", "release_max_level_info"] }
tracing-subscriber = "0.3"
24 changes: 4 additions & 20 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
use std::fs::File;
use tracing_subscriber;

use log::LevelFilter;
use simplelog::{ColorChoice, CombinedLogger, Config, TermLogger, TerminalMode, WriteLogger};

pub fn init() -> anyhow::Result<()> {
CombinedLogger::init(vec![
TermLogger::new(
LevelFilter::Debug,
Config::default(),
TerminalMode::Mixed,
ColorChoice::Auto,
),
WriteLogger::new(
LevelFilter::Info,
Config::default(),
File::create("logs.log")?
),
])?;

Ok(())
pub fn init() {
// TODO: log to file
tracing_subscriber::fmt::init();
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;
use std::{env, process};

use chrono::{DateTime, Duration, NaiveDateTime, Utc};
use log::{error, info, debug};
use tracing::{error, info, debug};
use model::application::Configuration;
use regex::Regex;
use serenity::client::{Context, EventHandler};
Expand Down Expand Up @@ -223,7 +223,7 @@ impl EventHandler for Handler {
#[tokio::main]
async fn main() {
// Initialize the logging framework.
logger::init().expect("failed to init logger");
logger::init();

// Set up the configuration.
let configuration = load_configuration();
Expand Down

0 comments on commit 704d05f

Please sign in to comment.