Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tokio asynchronous multi-thread log unknown time #905

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

0x676e67
Copy link
Collaborator

@0x676e67 0x676e67 commented Sep 24, 2023

修复tokio异步多线程日志时间显示:unknown time

#[cfg(feature = "local-time")]
impl OffsetTime<well_known::Rfc3339> {
    /// Returns a formatter that formats the current time using the [local time offset] in the [RFC
    /// 3339] format (a subset of the [ISO 8601] timestamp format).
    ///
    /// Returns an error if the local time offset cannot be determined. This typically occurs in
    /// multithreaded programs. To avoid this problem, initialize `OffsetTime` before forking
    /// threads. When using Tokio, this means initializing `OffsetTime` before the Tokio runtime.
    ///
    /// # Examples
    ///
    /// ```
    /// use tracing_subscriber::fmt::{self, time};
    ///
    /// let collector = tracing_subscriber::fmt()
    ///     .with_timer(time::OffsetTime::local_rfc_3339().expect("could not get local offset!"));
    /// # drop(collector);
    /// ```
    ///
    /// Using `OffsetTime` with Tokio:
    ///
    /// ```
    /// use tracing_subscriber::fmt::time::OffsetTime;
    ///
    /// #[tokio::main]
    /// async fn run() {
    ///     tracing::info!("runtime initialized");
    ///
    ///     // At this point the Tokio runtime is initialized, and we can use both Tokio and Tracing
    ///     // normally.
    /// }
    ///
    /// fn main() {
    ///     // Because we need to get the local offset before Tokio spawns any threads, our `main`
    ///     // function cannot use `tokio::main`.
    ///     tracing_subscriber::fmt()
    ///         .with_timer(OffsetTime::local_rfc_3339().expect("could not get local time offset"))
    ///         .init();
    ///
    ///     // Even though `run` is written as an `async fn`, because we used `tokio::main` on it
    ///     // we can call it as a synchronous function.
    ///     run();
    /// }
    /// ```
    ///
    /// [local time offset]: time::UtcOffset::current_local_offset
    /// [RFC 3339]: https://datatracker.ietf.org/doc/html/rfc3339
    /// [ISO 8601]: https://en.wikipedia.org/wiki/ISO_8601
    pub fn local_rfc_3339() -> Result<Self, time::error::IndeterminateOffset> {
        Ok(Self::new(
            UtcOffset::current_local_offset()?,
            well_known::Rfc3339,
        ))
    }
}

@0x676e67
Copy link
Collaborator Author

0x676e67 commented Sep 24, 2023

OffsetTime在openwrt上还是有毛病,看看要不要回万能的SystemTime

  • OffsetTime
╭─root at OpenWrt in ~ 23-09-24 - 8:22:39
╰─○ aliyundrive-webdav  --drive-type resource
Error: The system's UTC offset could not be determined
  • SystemTime
╭─root at OpenWrt in ~ 23-09-24 - 8:22:39
╰─○ aliyundrive-webdav  --drive-type resource
2023-09-24T00:24:06.860934Z  INFO aliyundrive_webdav::drive: refresh token succeed
2023-09-24T00:24:07.221117Z  WARN aliyundrive_webdav::drive: resource drive not found, use default drive instead
2023-09-24T00:24:07.221133Z  INFO aliyundrive_webdav::drive: found resource drive drive_id=78405871
2023-09-24T00:24:07.221445Z  INFO aliyundrive_webdav::webdav: listening on http://0.0.0.0:8080

@0x676e67 0x676e67 temporarily deployed to Docker Hub September 24, 2023 00:25 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@0x676e67 0x676e67 temporarily deployed to OpenWrt September 24, 2023 00:29 — with GitHub Actions Inactive
@messense messense merged commit a3c837b into messense:main Sep 25, 2023
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants