pub struct TextLayout { /* private fields */ }Expand description
A layout that formats log record as optionally colored text.
Output format:
2024-08-11T22:44:57.172105+08:00 ERROR file: examples/file.rs:51 Hello error!
2024-08-11T22:44:57.172219+08:00 WARN file: examples/file.rs:52 Hello warn!
2024-08-11T22:44:57.172276+08:00 INFO file: examples/file.rs:53 Hello info!
2024-08-11T22:44:57.172329+08:00 DEBUG file: examples/file.rs:54 Hello debug!
2024-08-11T22:44:57.172382+08:00 TRACE file: examples/file.rs:55 Hello trace!By default, log levels are colored. You can set the no_color field to true to disable
coloring.
You can also customize the color of each log level with error_color
and so on.
You can customize the timezone of the timestamp by setting the tz field with a TimeZone
instance. Otherwise, the system timezone is used.
§Examples
use logforth_layout_text::TextLayout;
let layout = TextLayout::default();Implementations§
Source§impl TextLayout
impl TextLayout
Sourcepub fn fatal_color(self, color: Color) -> Self
pub fn fatal_color(self, color: Color) -> Self
Customize the color of the error log level. Default to bright red.
No effect if no_color is set to true.
Sourcepub fn error_color(self, color: Color) -> Self
pub fn error_color(self, color: Color) -> Self
Customize the color of the error log level. Default to red.
No effect if no_color is set to true.
Sourcepub fn warn_color(self, color: Color) -> Self
pub fn warn_color(self, color: Color) -> Self
Customize the color of the warn log level. Default to yellow.
No effect if no_color is set to true.
Sourcepub fn info_color(self, color: Color) -> Self
pub fn info_color(self, color: Color) -> Self
Customize the color of the info log level/ Default to green.
No effect if no_color is set to true.
Sourcepub fn debug_color(self, color: Color) -> Self
pub fn debug_color(self, color: Color) -> Self
Customize the color of the debug log level. Default to blue.
No effect if no_color is set to true.
Sourcepub fn trace_color(self, color: Color) -> Self
pub fn trace_color(self, color: Color) -> Self
Customize the color of the trace log level. Default to magenta.
No effect if no_color is set to true.
Sourcepub fn timezone(self, tz: TimeZone) -> Self
pub fn timezone(self, tz: TimeZone) -> Self
Set the timezone for timestamps.
Defaults to the system timezone if not set.
§Examples
use jiff::tz::TimeZone;
use logforth_layout_text::TextLayout;
let layout = TextLayout::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_text::TextLayout;
// This is equivalent to the default timestamp format.
let layout = TextLayout::default()
.timestamp_format(|ts, tz| format!("{:.6}", ts.display_with_offset(tz.to_offset(ts))));Trait Implementations§
Source§impl Clone for TextLayout
impl Clone for TextLayout
Source§fn clone(&self) -> TextLayout
fn clone(&self) -> TextLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more