Struct jlogger::JloggerBuilder
source · pub struct JloggerBuilder { /* private fields */ }
Implementations§
source§impl JloggerBuilder
impl JloggerBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new JloggerBuilder which is used to build a Jlogger.
Examples
use log::LevelFilter;
use jlogger::{JloggerBuilder, LogTimeFormat};
JloggerBuilder::new()
.max_level(LevelFilter::Debug)
.log_console(true)
.log_time(LogTimeFormat::TimeStamp)
.log_file(Some("/tmp/my_log.log"), false)
.build();
sourcepub fn max_level(self, max_level: LevelFilter) -> Self
pub fn max_level(self, max_level: LevelFilter) -> Self
Set the max level to be outputted. Log messages with a level below it will not be outputted. At runtime, the log level can be filtered though “JLOGGER_LEVEL” environment variable.
sourcepub fn log_console(self, log_console: bool) -> Self
pub fn log_console(self, log_console: bool) -> Self
If enabled, log message will be printed to the console. Default is true.
sourcepub fn log_file(self, log_file: Option<&str>, append: bool) -> Self
pub fn log_file(self, log_file: Option<&str>, append: bool) -> Self
Log file name. If specified, log message will be outputted to it. If append is true and the log file exists, new messages well be appended to the end of the file. Otherwise, a new log file will be created.
sourcepub fn log_runtime(self, log_runtime: bool) -> Self
pub fn log_runtime(self, log_runtime: bool) -> Self
Add runtime information to log message. If the current thread name is set, it will be used as runtime information, otherwise process name is used
DEBUG thread1 : logging from thread thread1.
DEBUG jlogger-cac0970c6f073082 : logging from a thread whose name is not set.
sourcepub fn log_time(self, time_format: LogTimeFormat) -> Self
pub fn log_time(self, time_format: LogTimeFormat) -> Self
Time stamp string format, only take effect when time stamp is enable in the log.
- TimeStamp
Timestamp (from system boot) will be outputted in the log message.
9080.163365118 DEBUG test_debug_macro : src/lib.rs-364 : this is debug
9083.164066687 INFO test_debug_macro : this is info
- TimeLocal
Date and time are printed in the log message.
2022-05-17 13:00:03 DEBUG : src/lib.rs-363 : this is debug
2022-05-17 13:00:06 INFO : this is info
- TimeNone No timestamp included in the log message.