From e4d838d1fed87be3134f404c4e9705773a785a52 Mon Sep 17 00:00:00 2001 From: Oupson Date: Thu, 27 Aug 2020 17:05:28 +0200 Subject: [PATCH] Beggin to log --- .gitignore | 3 ++- Cargo.toml | 4 +++- log4rs.yaml | 12 ++++++++++++ src/macros.rs | 2 +- src/main.rs | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 log4rs.yaml diff --git a/.gitignore b/.gitignore index fcb20e1..7cf5fc8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /logging/ Cargo.lock Conf.toml -/data \ No newline at end of file +/data +/log \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index ab0ad6e..8a5b1f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,6 @@ async-trait = "0.1.36" tokio = { version = "0.2", features = ["full"] } futures = "0.3" chrono = "0.4.15" -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" +log = "0.4" +log4rs = "0.13.0" \ No newline at end of file diff --git a/log4rs.yaml b/log4rs.yaml new file mode 100644 index 0000000..d522c12 --- /dev/null +++ b/log4rs.yaml @@ -0,0 +1,12 @@ +appenders: + stdout: + kind: console + file-debug: + kind: file + path: "log/debug.log" + encoder: + pattern: "{d} - {m}{n}" +root: + level: debug + appenders: + - stdout \ No newline at end of file diff --git a/src/macros.rs b/src/macros.rs index d7eebbe..2b77001 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -2,7 +2,7 @@ macro_rules! debugln { ($($arg:tt)*) => { if cfg!(debug_assertions) { - eprintln!($($arg)*); + log::debug!($($arg)*); } }; } diff --git a/src/main.rs b/src/main.rs index 6fa8a9a..71c1ec9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,7 @@ impl TypeMapKey for ShardManagerContainer { // TODO USE LOG #[tokio::main] async fn main() -> IoResult<()> { + log4rs::init_file("log4rs.yaml", Default::default()).unwrap(); let conf: config::Conf = toml::from_str(&std::fs::read_to_string("Conf.toml")?)?; debugln!("conf : {:?}", conf);