From afcaa40922518ba951e2857b4266a13d053ec9ea Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 23 Dec 2021 15:43:47 +0800 Subject: [PATCH 1/4] chore: log examples with tracing-subscriber --- examples/actix4_example/Cargo.toml | 4 ++-- examples/actix4_example/src/main.rs | 2 +- examples/actix_example/Cargo.toml | 4 ++-- examples/actix_example/src/main.rs | 2 +- examples/axum_example/Cargo.toml | 4 ++-- examples/axum_example/src/main.rs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/actix4_example/Cargo.toml b/examples/actix4_example/Cargo.toml index b8721ce1f..c7fea10a0 100644 --- a/examples/actix4_example/Cargo.toml +++ b/examples/actix4_example/Cargo.toml @@ -18,12 +18,12 @@ tera = "1.8.0" dotenv = "0.15" listenfd = "0.3.3" serde = "1" -env_logger = "0.8" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dependencies.sea-orm] path = "../../" # remove this line in your own project version = "^0.4.0" -features = ["macros", "runtime-actix-native-tls"] +features = ["macros", "runtime-actix-native-tls", "debug-print"] default-features = false [features] diff --git a/examples/actix4_example/src/main.rs b/examples/actix4_example/src/main.rs index 6a52b81b1..43ec4336d 100644 --- a/examples/actix4_example/src/main.rs +++ b/examples/actix4_example/src/main.rs @@ -155,7 +155,7 @@ async fn delete(data: web::Data, id: web::Path) -> Result std::io::Result<()> { std::env::set_var("RUST_LOG", "debug"); - env_logger::init(); + tracing_subscriber::fmt::init(); // get env vars dotenv::dotenv().ok(); diff --git a/examples/actix_example/Cargo.toml b/examples/actix_example/Cargo.toml index 368d4d62b..36cbf8421 100644 --- a/examples/actix_example/Cargo.toml +++ b/examples/actix_example/Cargo.toml @@ -18,12 +18,12 @@ tera = "1.8.0" dotenv = "0.15" listenfd = "0.3.3" serde = "1" -env_logger = "0.8" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dependencies.sea-orm] path = "../../" # remove this line in your own project version = "^0.4.0" -features = ["macros", "runtime-async-std-native-tls"] +features = ["macros", "runtime-async-std-native-tls", "debug-print"] default-features = false [features] diff --git a/examples/actix_example/src/main.rs b/examples/actix_example/src/main.rs index e2d1e9566..d532174f8 100644 --- a/examples/actix_example/src/main.rs +++ b/examples/actix_example/src/main.rs @@ -181,7 +181,7 @@ async fn delete( #[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "debug"); - env_logger::init(); + tracing_subscriber::fmt::init(); // get env vars dotenv::dotenv().ok(); diff --git a/examples/axum_example/Cargo.toml b/examples/axum_example/Cargo.toml index 3b07ce6df..07994151c 100644 --- a/examples/axum_example/Cargo.toml +++ b/examples/axum_example/Cargo.toml @@ -16,15 +16,15 @@ tower-http = { version = "0.2", features = ["fs"] } tower-cookies = { version = "0.4" } anyhow = "1" dotenv = "0.15" -env_logger = "0.9" serde = "1" serde_json = "1" tera = "1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } [dependencies.sea-orm] path = "../../" # remove this line in your own project version = "^0.4.2" -features = ["macros", "runtime-tokio-native-tls"] +features = ["macros", "runtime-tokio-native-tls", "debug-print"] default-features = false [features] diff --git a/examples/axum_example/src/main.rs b/examples/axum_example/src/main.rs index 5c48d9dc3..c35e180a4 100644 --- a/examples/axum_example/src/main.rs +++ b/examples/axum_example/src/main.rs @@ -23,7 +23,7 @@ use tower_http::services::ServeDir; #[tokio::main] async fn main() -> anyhow::Result<()> { env::set_var("RUST_LOG", "debug"); - env_logger::init(); + tracing_subscriber::fmt::init(); dotenv::dotenv().ok(); let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file"); From 6b72b7fdc5134bd2cf82169b17c5e1b9e0e502de Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 23 Dec 2021 15:44:50 +0800 Subject: [PATCH 2/4] chore: log [issues] with tracing-subscriber --- issues/86/Cargo.toml | 4 ++-- issues/86/src/main.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/issues/86/Cargo.toml b/issues/86/Cargo.toml index 4284cb686..f5749a63f 100644 --- a/issues/86/Cargo.toml +++ b/issues/86/Cargo.toml @@ -10,5 +10,5 @@ publish = false [dependencies] sea-orm = { path = "../../", features = [ "sqlx-all", "runtime-tokio-native-tls", "debug-print" ] } tokio = { version = "1", features = ["full"] } -env_logger = { version = "^0.9" } -log = { version = "^0.4" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +tracing = { version = "0.1" } diff --git a/issues/86/src/main.rs b/issues/86/src/main.rs index 14a76086c..21681287c 100644 --- a/issues/86/src/main.rs +++ b/issues/86/src/main.rs @@ -3,9 +3,9 @@ use sea_orm::*; #[tokio::main] pub async fn main() { - env_logger::builder() - .filter_level(log::LevelFilter::Debug) - .is_test(true) + tracing_subscriber::fmt() + .with_max_level(tracing::Level::DEBUG) + .with_test_writer() .init(); let db = Database::connect("mysql://sea:sea@localhost/bakery") From c6e2abfac80223cd31412f31cbfa08a0d06931c7 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 23 Dec 2021 15:45:02 +0800 Subject: [PATCH 3/4] chore: log [cli] with tracing-subscriber --- sea-orm-cli/Cargo.toml | 4 ++-- sea-orm-cli/src/main.rs | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 0c8a06605..6dca13bb3 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -30,8 +30,8 @@ sea-schema = { version = "0.3.0", default-features = false, features = [ "writer", ] } sqlx = { version = "^0.5", default-features = false, features = [ "mysql", "postgres" ] } -env_logger = { version = "^0.9" } -log = { version = "^0.4" } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +tracing = { version = "0.1" } url = "^2.2" [dev-dependencies] diff --git a/sea-orm-cli/src/main.rs b/sea-orm-cli/src/main.rs index 2c7848ce9..aee80b0b6 100644 --- a/sea-orm-cli/src/main.rs +++ b/sea-orm-cli/src/main.rs @@ -1,6 +1,5 @@ use clap::ArgMatches; use dotenv::dotenv; -use log::LevelFilter; use sea_orm_codegen::{EntityTransformer, OutputFile, WithSerde}; use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command, str::FromStr}; use url::Url; @@ -33,9 +32,9 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box Date: Thu, 23 Dec 2021 16:57:54 +0800 Subject: [PATCH 4/4] feat: tracing will emit log if tracing-subscriber is not setup --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 443e2eb0c..0eccf60dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ async-trait = { version = "^0.1" } chrono = { version = "^0", optional = true } futures = { version = "^0.3" } futures-util = { version = "^0.3" } -tracing = "0.1" +tracing = { version = "0.1", features = ["log"] } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.4.2", path = "sea-orm-macros", optional = true } sea-query = { version = "^0.20.0", features = ["thread-safe"] }