Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ All notable changes to this project will be documented in this file.
* `EnvFilter`'s constructors (`from_env`, etc.) are moved to `EnvFilterBuilder`.
* Upgrade to opentelemetry 0.31.0.

### Notable changes

* Timestamp format in `TextLayout`, `JsonLayout`, and `LogfmtLayout` is changed from RFC 9557 to RFC 3339 format.
* That is, from "2025-01-10T15:22:37.868815+08:00[Asia/Shanghai]" to "2025-01-10T15:22:37.868815+08:00".

## [0.27.0] 2025-08-18

### Notable changes
Expand Down
10 changes: 5 additions & 5 deletions src/diagnostic/fastrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use crate::diagnostic::Visitor;
/// Output format:
///
/// ```text
/// 2025-01-10T15:22:37.868815+08:00[Asia/Shanghai] ERROR fastrace: fastrace.rs:39 Hello syslog error! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868890+08:00[Asia/Shanghai] WARN fastrace: fastrace.rs:40 Hello syslog warn! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868921+08:00[Asia/Shanghai] INFO fastrace: fastrace.rs:41 Hello syslog info! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868949+08:00[Asia/Shanghai] DEBUG fastrace: fastrace.rs:42 Hello syslog debug! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868976+08:00[Asia/Shanghai] TRACE fastrace: fastrace.rs:43 Hello syslog trace! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868815+08:00 ERROR fastrace: fastrace.rs:39 Hello syslog error! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868890+08:00 WARN fastrace: fastrace.rs:40 Hello syslog warn! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868921+08:00 INFO fastrace: fastrace.rs:41 Hello syslog info! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868949+08:00 DEBUG fastrace: fastrace.rs:42 Hello syslog debug! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// 2025-01-10T15:22:37.868976+08:00 TRACE fastrace: fastrace.rs:43 Hello syslog trace! trace_id=37f9c45f918cbb477089afb0d7162e7e
/// ```
///
/// ## Example
Expand Down
4 changes: 3 additions & 1 deletion src/layout/google_cloud_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ where

impl Layout for GoogleCloudLoggingLayout {
fn format(&self, record: &Record, diags: &[Box<dyn Diagnostic>]) -> Result<Vec<u8>, Error> {
let timestamp = jiff::Timestamp::now();

let mut visitor = KvCollector {
layout: self,
payload_fields: BTreeMap::new(),
Expand All @@ -243,7 +245,7 @@ impl Layout for GoogleCloudLoggingLayout {

let record_line = RecordLine {
extra_fields: visitor.payload_fields,
timestamp: jiff::Timestamp::now(),
timestamp,
severity: record.level().as_str(),
message: record.args(),
labels: visitor.labels,
Expand Down
22 changes: 14 additions & 8 deletions src/layout/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use std::borrow::Cow;
use std::collections::BTreeMap;
use std::fmt::Arguments;

use jiff::Timestamp;
use jiff::Zoned;
use jiff::tz::TimeZone;
use jiff::{Timestamp, TimestampDisplayWithOffset};
use log::Record;
use serde::Serialize;
use serde_json::Map;
Expand Down Expand Up @@ -102,8 +102,8 @@ impl Visitor for DiagsCollector<'_> {

#[derive(Debug, Clone, Serialize)]
struct RecordLine<'a> {
#[serde(serialize_with = "serialize_time_zone")]
timestamp: Zoned,
#[serde(serialize_with = "serialize_timestamp")]
timestamp: TimestampDisplayWithOffset,
level: &'a str,
target: &'a str,
file: &'a str,
Expand All @@ -116,7 +116,10 @@ struct RecordLine<'a> {
diags: BTreeMap<String, String>,
}

fn serialize_time_zone<S>(timestamp: &Zoned, serializer: S) -> Result<S::Ok, S::Error>
fn serialize_timestamp<S>(
timestamp: &TimestampDisplayWithOffset,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
Expand All @@ -134,6 +137,12 @@ impl Layout for JsonLayout {
fn format(&self, record: &Record, diags: &[Box<dyn Diagnostic>]) -> Result<Vec<u8>, Error> {
let diagnostics = diags;

let time = match self.tz.clone() {
None => Zoned::now(),
Some(tz) => Timestamp::now().to_zoned(tz),
};
let timestamp = time.timestamp().display_with_offset(time.offset());

let mut kvs = Map::new();
let mut kvs_visitor = KvCollector { kvs: &mut kvs };
record
Expand All @@ -148,10 +157,7 @@ impl Layout for JsonLayout {
}

let record_line = RecordLine {
timestamp: match self.tz.clone() {
Some(tz) => Timestamp::now().to_zoned(tz),
None => Zoned::now(),
},
timestamp,
level: record.level().as_str(),
target: record.target(),
file: record.file().unwrap_or_default(),
Expand Down
4 changes: 3 additions & 1 deletion src/layout/logfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ impl Visitor for KvFormatter {
impl Layout for LogfmtLayout {
fn format(&self, record: &Record, diags: &[Box<dyn Diagnostic>]) -> Result<Vec<u8>, Error> {
let time = match self.tz.clone() {
Some(tz) => Timestamp::now().to_zoned(tz),
None => Zoned::now(),
Some(tz) => Timestamp::now().to_zoned(tz),
};
let time = time.timestamp().display_with_offset(time.offset());

let level = record.level().to_string();
let target = record.target();
let file = filename(record);
Expand Down
4 changes: 3 additions & 1 deletion src/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,11 @@ impl Visitor for KvWriter {
impl Layout for TextLayout {
fn format(&self, record: &Record, diags: &[Box<dyn Diagnostic>]) -> Result<Vec<u8>, Error> {
let time = match self.tz.clone() {
Some(tz) => Timestamp::now().to_zoned(tz),
None => Zoned::now(),
Some(tz) => Timestamp::now().to_zoned(tz),
};
let time = time.timestamp().display_with_offset(time.offset());

let level = self.format_record_level(record.level());
let target = record.target();
let file = filename(record);
Expand Down