Skip to content

Commit 062f8b1

Browse files
Fix tracing time (#124)
1 parent c65dc66 commit 062f8b1

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ tokio = { version = "1.29.1", features = ["full"] }
6666
tokio-stream = "0.1.14"
6767
tonic = { version = "0.8.3", features = ["tls", "tls-roots"] }
6868
tracing = { version = "0.1.37", features = ["attributes"] }
69-
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
69+
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "time", "local-time"] }
7070
url = "2.4.0"
71+
time = { version = "0.3", features = ["formatting"] }
7172

7273
[dev-dependencies]
7374
axum = "0.6.19"

dist-material/LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ The text of each license is also included in licenses/LICENSE-[project].txt.
362362
https://crates.io/crates/native-tls/0.2.11 0.2.11 Apache-2.0 OR MIT
363363
https://crates.io/crates/num-traits/0.2.16 0.2.16 Apache-2.0 OR MIT
364364
https://crates.io/crates/num_cpus/1.16.0 1.16.0 Apache-2.0 OR MIT
365+
https://crates.io/crates/num_threads/0.1.7 0.1.7 Apache-2.0 OR MIT
365366
https://crates.io/crates/object/0.31.1 0.31.1 Apache-2.0 OR MIT
366367
https://crates.io/crates/once_cell/1.18.0 1.18.0 Apache-2.0 OR MIT
367368
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.
426427
https://crates.io/crates/thread_local/1.1.4 1.1.4 Apache-2.0 OR MIT
427428
https://crates.io/crates/time/0.3.23 0.3.23 Apache-2.0 OR MIT
428429
https://crates.io/crates/time-core/0.1.1 0.1.1 Apache-2.0 OR MIT
430+
https://crates.io/crates/time-macros/0.2.10 0.2.10 Apache-2.0 OR MIT
429431
https://crates.io/crates/tokio-io-timeout/1.2.0 1.2.0 Apache-2.0 OR MIT
430432
https://crates.io/crates/tokio-rustls/0.23.4 0.23.4 Apache-2.0 OR MIT
431433
https://crates.io/crates/toml_datetime/0.6.3 0.6.3 Apache-2.0 OR MIT

src/module.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ use std::{
3535
str::FromStr,
3636
time::SystemTime,
3737
};
38+
use time::format_description::well_known::Rfc3339;
3839
use tracing::{debug, error, info, metadata::LevelFilter};
39-
use tracing_subscriber::{EnvFilter, FmtSubscriber};
40+
use tracing_subscriber::{fmt::time::OffsetTime, EnvFilter, FmtSubscriber};
4041

4142
static IS_ENABLE: Lazy<bool> = Lazy::new(|| {
4243
if !ini_get::<bool>(SKYWALKING_AGENT_ENABLE) {
@@ -255,7 +256,7 @@ fn try_init_logger() -> anyhow::Result<()> {
255256
.unwrap_or_default();
256257
let log_file = log_file.trim();
257258
if log_file.is_empty() {
258-
bail!("log file cant't be empty when log enabled");
259+
bail!("log file can't be empty when log enabled");
259260
}
260261

261262
let path = Path::new(log_file);
@@ -277,6 +278,10 @@ fn try_init_logger() -> anyhow::Result<()> {
277278
.with_env_filter(filter)
278279
.with_ansi(false)
279280
.with_writer(file)
281+
.with_timer(
282+
OffsetTime::local_rfc_3339()
283+
.unwrap_or_else(|_| OffsetTime::new(time::UtcOffset::UTC, Rfc3339)),
284+
)
280285
.finish();
281286

282287
tracing::subscriber::set_global_default(subscriber)?;

0 commit comments

Comments
 (0)