pub struct JsonFormatter(/* private fields */);
Available on crate feature
serde_json
only.Expand description
JSON logs formatter.
Each log will be serialized into a single line of JSON object with the following schema.
§Schema
Field | Type | Description |
---|---|---|
level | String | The level of the log. Same as the return of Level::as_str . |
timestamp | Integer(u64) | The timestamp when the log was generated, in milliseconds since January 1, 1970 00:00:00 UTC. |
payload | String | The contents of the log. |
logger | String/Null | The name of the logger. Null if the logger has no name. |
tid | Integer(u64) | The thread ID when the log was generated. |
source | Object/Null | The source location of the log. See SourceLocation for its schema. Null if crate feature source-location is not enabled. |
-
If the type of a field is Null, the field will not be present or be
null
. -
The order of the fields is not guaranteed.
§Examples
-
Default:
{"level":"info","timestamp":1722817424798,"payload":"hello, world!","tid":3472525} {"level":"error","timestamp":1722817424798,"payload":"something went wrong","tid":3472525}
-
If the logger has a name:
{"level":"info","timestamp":1722817541459,"payload":"hello, world!","logger":"app-component","tid":3478045} {"level":"error","timestamp":1722817541459,"payload":"something went wrong","logger":"app-component","tid":3478045}
-
If crate feature
source-location
is enabled:{"level":"info","timestamp":1722817572709,"payload":"hello, world!","tid":3479856,"source":{"module_path":"my_app::say_hi","file":"src/say_hi.rs","line":4,"column":5}} {"level":"error","timestamp":1722817572709,"payload":"something went wrong","tid":3479856,"source":{"module_path":"my_app::say_hi","file":"src/say_hi.rs","line":5,"column":5}}
Implementations§
Source§impl JsonFormatter
impl JsonFormatter
Sourcepub fn new() -> JsonFormatter
pub fn new() -> JsonFormatter
Constructs a JsonFormatter
.
Trait Implementations§
Source§impl Clone for JsonFormatter
impl Clone for JsonFormatter
Source§fn clone(&self) -> JsonFormatter
fn clone(&self) -> JsonFormatter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Default for JsonFormatter
impl Default for JsonFormatter
Auto Trait Implementations§
impl Freeze for JsonFormatter
impl RefUnwindSafe for JsonFormatter
impl Send for JsonFormatter
impl Sync for JsonFormatter
impl Unpin for JsonFormatter
impl UnwindSafe for JsonFormatter
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