pub struct JsonFormat { /* private fields */ }Available on crate feature
json only.Expand description
JSON formatter.
The default configuration emits compact JSON with a trailing
newline. Set Self::pretty for an indented form intended for
developer eyeballs, not machine ingestion.
§Example
use log_io::format::{Format, JsonFormat};
use log_io::{Field, Level, Metadata, Record, Value};
let fmt = JsonFormat::new();
let fields = [Field::new("port", Value::U64(8080))];
let record = Record::new(Metadata::new(Level::Info, "app"), "started", &fields);
let mut out = String::new();
fmt.write_record(&record, &mut out).unwrap();
assert!(out.starts_with('{'));
assert!(out.ends_with("}\n"));
assert!(out.contains("\"port\":8080"));Implementations§
Source§impl JsonFormat
impl JsonFormat
Sourcepub const fn timestamp_rfc3339(self, enabled: bool) -> Self
pub const fn timestamp_rfc3339(self, enabled: bool) -> Self
Emit timestamps as RFC 3339 strings instead of unix nanoseconds.
When enabled and a record’s timestamp is present, the output
looks like "timestamp":"2026-05-18T13:24:01.123456789Z". When
disabled (default), it is "timestamp":1700000000000000000.
Trait Implementations§
Source§impl Clone for JsonFormat
impl Clone for JsonFormat
Source§fn clone(&self) -> JsonFormat
fn clone(&self) -> JsonFormat
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 JsonFormat
impl Debug for JsonFormat
Source§impl Default for JsonFormat
impl Default for JsonFormat
Source§fn default() -> JsonFormat
fn default() -> JsonFormat
Returns the “default value” for a type. Read more
Source§impl Format for JsonFormat
impl Format for JsonFormat
impl Copy for JsonFormat
Auto Trait Implementations§
impl Freeze for JsonFormat
impl RefUnwindSafe for JsonFormat
impl Send for JsonFormat
impl Sync for JsonFormat
impl Unpin for JsonFormat
impl UnsafeUnpin for JsonFormat
impl UnwindSafe for JsonFormat
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