fix local time not work in musl (#20)

This commit is contained in:
Sijie.Sun 2024-02-27 21:47:08 +08:00 committed by GitHub
parent e5b3fb09e6
commit 31af413b03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 2 deletions

View File

@ -366,6 +366,7 @@ fn init_logger() {
file_layer.set_ansi(false);
let file_layer = file_layer
.with_writer(file_appender)
.with_timer(easytier_core::common::get_logger_timer_rfc3339())
.with_filter(file_filter);
tracing_subscriber::Registry::default()

View File

@ -23,6 +23,7 @@ log = "0.4"
thiserror = "1.0"
auto_impl = "1.1.0"
crossbeam = "0.8.4"
time = "0.3"
gethostname = "0.4.3"

View File

@ -7,3 +7,19 @@ pub mod netns;
pub mod network;
pub mod rkyv_util;
pub mod stun;
pub fn get_logger_timer<F: time::formatting::Formattable>(
format: F,
) -> tracing_subscriber::fmt::time::OffsetTime<F> {
unsafe {
time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound)
};
let local_offset = time::UtcOffset::current_local_offset()
.unwrap_or(time::UtcOffset::from_whole_seconds(0).unwrap());
tracing_subscriber::fmt::time::OffsetTime::new(local_offset, format)
}
pub fn get_logger_timer_rfc3339(
) -> tracing_subscriber::fmt::time::OffsetTime<time::format_description::well_known::Rfc3339> {
get_logger_timer(time::format_description::well_known::Rfc3339)
}

View File

@ -15,6 +15,7 @@ mod peers;
mod rpc;
mod tunnels;
use common::get_logger_timer_rfc3339;
use instance::instance::{Instance, InstanceConfigWriter};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};
@ -53,7 +54,7 @@ fn init_logger() {
file_layer.set_ansi(false);
let file_layer = file_layer
.with_writer(file_appender)
.with_timer(tracing_subscriber::fmt::time::OffsetTime::local_rfc_3339().unwrap())
.with_timer(get_logger_timer_rfc3339())
.with_filter(file_filter);
// logger to console
@ -63,7 +64,7 @@ fn init_logger() {
.unwrap();
let console_layer = tracing_subscriber::fmt::layer()
.pretty()
.with_timer(tracing_subscriber::fmt::time::OffsetTime::local_rfc_3339().unwrap())
.with_timer(get_logger_timer_rfc3339())
.with_writer(std::io::stderr)
.with_filter(console_filter);