Skip to content

Commit

Permalink
Fix tracing time
Browse files Browse the repository at this point in the history
  • Loading branch information
CodePrometheus committed Dec 30, 2024
1 parent c65dc66 commit d5748f8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions dist-material/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> = Lazy::new(|| {
if !ini_get::<bool>(SKYWALKING_AGENT_ENABLE) {
Expand Down Expand Up @@ -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);
Expand All @@ -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)?;
Expand Down

0 comments on commit d5748f8

Please sign in to comment.