From 9d5ce08ff891497cd9ef591ca692b47ac2c57f68 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 2 Sep 2021 18:35:10 +0800 Subject: [PATCH] Logging --- Cargo.toml | 6 ++++-- sea-orm-macros/src/lib.rs | 4 ++++ src/util.rs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3db574bb..387d27d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ chrono = { version = "^0", optional = true } futures = { version = "^0.3" } futures-util = { version = "^0.3" } rust_decimal = { version = "^1", optional = true } -sea-orm-macros = { version = "^0.1.1", optional = true } +sea-orm-macros = { version = "^0.1.1", path = "sea-orm-macros", optional = true } sea-query = { version = "^0.16", features = ["thread-safe"] } sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } @@ -40,6 +40,7 @@ sqlx-core = { version = "^0.5", optional = true } sqlx-macros = { version = "^0.5", optional = true } serde_json = { version = "^1", optional = true } uuid = { version = "0.8", features = ["serde", "v4"], optional = true } +log = { version = "^0.4", optional = true } [dev-dependencies] smol = { version = "^1.2" } @@ -49,11 +50,12 @@ tokio = { version = "^1.6", features = ["full"] } actix-rt = { version = "2.2.0" } maplit = { version = "^1" } rust_decimal_macros = { version = "^1" } +env_logger = { version = "^0.9" } sea-orm = { path = ".", features = ["debug-print"] } pretty_assertions = { version = "^0.7" } [features] -debug-print = [] +debug-print = ["log"] default = [ "macros", "mock", diff --git a/sea-orm-macros/src/lib.rs b/sea-orm-macros/src/lib.rs index a2217aa8..a9abf8b2 100644 --- a/sea-orm-macros/src/lib.rs +++ b/sea-orm-macros/src/lib.rs @@ -99,6 +99,10 @@ pub fn test(_: TokenStream, input: TokenStream) -> TokenStream { #[test] #(#attrs)* fn #name() #ret { + let _ = ::env_logger::builder() + .filter_level(::log::LevelFilter::Debug) + .is_test(true) + .try_init(); crate::block_on!(async { #body }) } ) diff --git a/src/util.rs b/src/util.rs index f6ddfd54..20cc8eb3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,7 +1,7 @@ #[macro_export] #[cfg(feature = "debug-print")] macro_rules! debug_print { - ($( $args:expr ),*) => { println!( $( $args ),* ); } + ($( $args:expr ),*) => { log::debug!( $( $args ),* ); } } #[macro_export]