|
|
@@ -1,36 +1,14 @@
|
|
|
use std::collections::HashMap;
|
|
|
use std::fmt::Debug;
|
|
|
use std::io;
|
|
|
-use chrono::{Datelike, FixedOffset, Timelike, Utc};
|
|
|
use tracing::{Event, Subscriber, warn};
|
|
|
-use tracing_appender::non_blocking::WorkerGuard;
|
|
|
+use tracing_appender_timezone::non_blocking::WorkerGuard;
|
|
|
use tracing_subscriber::{fmt, Layer};
|
|
|
-use tracing_subscriber::fmt::format::Writer;
|
|
|
-use tracing_subscriber::fmt::time::FormatTime;
|
|
|
use tracing_subscriber::layer::{Context, SubscriberExt};
|
|
|
use reqwest::{Client};
|
|
|
-use rust_decimal::prelude::ToPrimitive;
|
|
|
use tracing::field::{Field, Visit};
|
|
|
-use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
|
|
-
|
|
|
-// 用來格式化日誌的輸出時間格式
|
|
|
-struct LocalTimer;
|
|
|
-
|
|
|
-impl FormatTime for LocalTimer {
|
|
|
- fn format_time(&self, w: &mut Writer<'_>) -> std::fmt::Result {
|
|
|
- let now = Utc::now().with_timezone(&FixedOffset::east_opt(8 * 3600).unwrap());
|
|
|
- write!(
|
|
|
- w,
|
|
|
- "{:02}-{:02} {:02}:{:02}:{:02}.{:03}",
|
|
|
- now.month(),
|
|
|
- now.day(),
|
|
|
- now.hour(),
|
|
|
- now.minute(),
|
|
|
- now.second(),
|
|
|
- now.nanosecond() / 1e6.to_u32().unwrap()
|
|
|
- )
|
|
|
- }
|
|
|
-}
|
|
|
+use tracing_appender_timezone::rolling::{RollingFileAppender, Rotation};
|
|
|
+
|
|
|
|
|
|
struct ErrorMessageVisitor {
|
|
|
message: String
|
|
|
@@ -107,22 +85,30 @@ pub fn final_init(level: &str, port: u32, account_name: String) -> WorkerGuard {
|
|
|
path.push_str(port.to_string().as_str());
|
|
|
|
|
|
let file_appender = RollingFileAppender::builder()
|
|
|
- .rotation(Rotation::HOURLY)
|
|
|
+ .time_zone(8)
|
|
|
+ .rotation(Rotation::DAILY)
|
|
|
.filename_suffix("log")
|
|
|
.build(path)
|
|
|
.expect("initializing rolling file appender failed");
|
|
|
- let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
|
|
+ let (non_blocking, guard) = tracing_appender_timezone::non_blocking(file_appender);
|
|
|
+
|
|
|
+ use time::{macros::format_description, UtcOffset};
|
|
|
+ use tracing_subscriber::{fmt::time::OffsetTime};
|
|
|
+ let local_time = OffsetTime::new(
|
|
|
+ UtcOffset::from_hms(8, 0, 0).unwrap(),
|
|
|
+ format_description!("[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]"),
|
|
|
+ );
|
|
|
|
|
|
let fmt_layer = fmt::layer()
|
|
|
- .with_timer(LocalTimer)
|
|
|
- .with_target(true)
|
|
|
+ .with_timer(local_time.clone())
|
|
|
+ .with_target(false)
|
|
|
.with_level(true)
|
|
|
.with_writer(io::stdout)
|
|
|
.with_span_events(fmt::format::FmtSpan::FULL);
|
|
|
|
|
|
let file_layer = fmt::layer()
|
|
|
- .with_timer(LocalTimer)
|
|
|
- .with_target(true)
|
|
|
+ .with_timer(local_time.clone())
|
|
|
+ .with_target(false)
|
|
|
.with_ansi(false)
|
|
|
.with_level(true)
|
|
|
.with_writer(non_blocking.clone())
|