diff --git a/Cargo.lock b/Cargo.lock index 67ce2ff..2c0c319 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1248,6 +1248,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "object" version = "0.31.1" @@ -2177,6 +2186,7 @@ dependencies = [ "skywalking-php-worker", "systemstat", "thiserror", + "time", "tokio", "tokio-stream", "tonic", @@ -2375,8 +2385,12 @@ version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" dependencies = [ + "itoa", + "libc", + "num_threads", "serde", "time-core", + "time-macros", ] [[package]] @@ -2385,6 +2399,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +[[package]] +name = "time-macros" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" +dependencies = [ + "time-core", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2652,6 +2675,7 @@ dependencies = [ "sharded-slab", "smallvec", "thread_local", + "time", "tracing", "tracing-core", "tracing-log", diff --git a/Cargo.toml b/Cargo.toml index 2437f62..60818e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,8 +66,9 @@ tokio = { version = "1.29.1", features = ["full"] } tokio-stream = "0.1.14" tonic = { version = "0.8.3", features = ["tls", "tls-roots"] } tracing = { version = "0.1.37", features = ["attributes"] } -tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } +tracing-subscriber = { version = "0.3.17", features = ["env-filter", "time", "local-time"] } url = "2.4.0" +time = { version = "0.3", features = ["formatting"] } [dev-dependencies] axum = "0.6.19" diff --git a/dist-material/LICENSE b/dist-material/LICENSE index 6ff7c00..7e54a95 100644 --- a/dist-material/LICENSE +++ b/dist-material/LICENSE @@ -362,6 +362,7 @@ The text of each license is also included in licenses/LICENSE-[project].txt. https://crates.io/crates/native-tls/0.2.11 0.2.11 Apache-2.0 OR MIT https://crates.io/crates/num-traits/0.2.16 0.2.16 Apache-2.0 OR MIT https://crates.io/crates/num_cpus/1.16.0 1.16.0 Apache-2.0 OR MIT + https://crates.io/crates/num_threads/0.1.7 0.1.7 Apache-2.0 OR MIT https://crates.io/crates/object/0.31.1 0.31.1 Apache-2.0 OR MIT https://crates.io/crates/once_cell/1.18.0 1.18.0 Apache-2.0 OR MIT https://crates.io/crates/openssl-macros/0.1.1 0.1.1 Apache-2.0 OR MIT @@ -426,6 +427,7 @@ The text of each license is also included in licenses/LICENSE-[project].txt. https://crates.io/crates/thread_local/1.1.4 1.1.4 Apache-2.0 OR MIT https://crates.io/crates/time/0.3.23 0.3.23 Apache-2.0 OR MIT https://crates.io/crates/time-core/0.1.1 0.1.1 Apache-2.0 OR MIT + https://crates.io/crates/time-macros/0.2.10 0.2.10 Apache-2.0 OR MIT https://crates.io/crates/tokio-io-timeout/1.2.0 1.2.0 Apache-2.0 OR MIT https://crates.io/crates/tokio-rustls/0.23.4 0.23.4 Apache-2.0 OR MIT https://crates.io/crates/toml_datetime/0.6.3 0.6.3 Apache-2.0 OR MIT diff --git a/src/module.rs b/src/module.rs index 36a7d74..3acb497 100644 --- a/src/module.rs +++ b/src/module.rs @@ -35,8 +35,9 @@ use std::{ str::FromStr, time::SystemTime, }; +use time::format_description::well_known::Rfc3339; use tracing::{debug, error, info, metadata::LevelFilter}; -use tracing_subscriber::{EnvFilter, FmtSubscriber}; +use tracing_subscriber::{fmt::time::OffsetTime, EnvFilter, FmtSubscriber}; static IS_ENABLE: Lazy = Lazy::new(|| { if !ini_get::(SKYWALKING_AGENT_ENABLE) { @@ -255,7 +256,7 @@ fn try_init_logger() -> anyhow::Result<()> { .unwrap_or_default(); let log_file = log_file.trim(); if log_file.is_empty() { - bail!("log file cant't be empty when log enabled"); + bail!("log file can't be empty when log enabled"); } let path = Path::new(log_file); @@ -277,6 +278,10 @@ fn try_init_logger() -> anyhow::Result<()> { .with_env_filter(filter) .with_ansi(false) .with_writer(file) + .with_timer( + OffsetTime::local_rfc_3339() + .unwrap_or_else(|_| OffsetTime::new(time::UtcOffset::UTC, Rfc3339)), + ) .finish(); tracing::subscriber::set_global_default(subscriber)?;