pub struct JsonLayout { /* private fields */ }Expand description
A JSON layout for formatting log records.
Output format:
{"timestamp":"2024-08-11T22:44:57.172051+08:00","level":"ERROR","module_path":"file","file":"examples/file.rs","line":51,"message":"Hello error!"}
{"timestamp":"2024-08-11T22:44:57.172187+08:00","level":"WARN","module_path":"file","file":"examples/file.rs","line":52,"message":"Hello warn!"}
{"timestamp":"2024-08-11T22:44:57.172246+08:00","level":"INFO","module_path":"file","file":"examples/file.rs","line":53,"message":"Hello info!"}
{"timestamp":"2024-08-11T22:44:57.172300+08:00","level":"DEBUG","module_path":"file","file":"examples/file.rs","line":54,"message":"Hello debug!"}
{"timestamp":"2024-08-11T22:44:57.172353+08:00","level":"TRACE","module_path":"file","file":"examples/file.rs","line":55,"message":"Hello trace!"}§Examples
use logforth_layout_json::JsonLayout;
let json_layout = JsonLayout::default();Implementations§
Source§impl JsonLayout
impl JsonLayout
Sourcepub fn timezone(self, tz: TimeZone) -> Self
pub fn timezone(self, tz: TimeZone) -> Self
Set the timezone for timestamps.
Defaults to the system timezone.
§Examples
use jiff::tz::TimeZone;
use logforth_layout_json::JsonLayout;
let layout = JsonLayout::default().timezone(TimeZone::UTC);Sourcepub fn timestamp_format(
self,
format: fn(Timestamp, &TimeZone) -> String,
) -> Self
pub fn timestamp_format( self, format: fn(Timestamp, &TimeZone) -> String, ) -> Self
Set a user-defined timestamp format function.
Default to formatting the timestamp with offset as ISO 8601. See the example below.
For other formatting options, refer to the jiff::fmt::strtime documentation.
§Examples
use jiff::Timestamp;
use jiff::tz::TimeZone;
use logforth_layout_json::JsonLayout;
// This is equivalent to the default timestamp format.
let layout = JsonLayout::default()
.timestamp_format(|ts, tz| format!("{:.6}", ts.display_with_offset(tz.to_offset(ts))));Trait Implementations§
Source§impl Clone for JsonLayout
impl Clone for JsonLayout
Source§fn clone(&self) -> JsonLayout
fn clone(&self) -> JsonLayout
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JsonLayout
impl Debug for JsonLayout
Source§impl Default for JsonLayout
impl Default for JsonLayout
Auto Trait Implementations§
impl Freeze for JsonLayout
impl RefUnwindSafe for JsonLayout
impl Send for JsonLayout
impl Sync for JsonLayout
impl Unpin for JsonLayout
impl UnsafeUnpin for JsonLayout
impl UnwindSafe for JsonLayout
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more