pub struct LoggerBuilder { /* private fields */ }Expand description
Implementations§
Source§impl LoggerBuilder
impl LoggerBuilder
Sourcepub fn build(self) -> Result<Logger>
pub fn build(self) -> Result<Logger>
use the configured settings to build and initialize a new global Logger
This will build a functional Logger. You don’t need to use the Logger struct, it’s better to use the macros:
error!warn!info!debug!trace!
instead of the methods of the Logger struct. You can however use the Logger struct in cases where usage of a macro is bad or you are somehow working with multiple loggers.
§Examples
Logger::builder()
.uptime(true)
.build();
info!("hello world");
§Errors
This function will return an error if a global Logger was aready initialized. This module uses the tracing crate for logging, so if a tracing logger is initialized elsewhere, this method will error.
Sourcepub const fn log_to_file(self, log_to_file: bool) -> Self
pub const fn log_to_file(self, log_to_file: bool) -> Self
enable or disable logging to and creating of logfiles
If you want to log to a file, don’t forget to set Self::log_dir!
Default: false
Sourcepub fn log_dir(self, log_dir: PathBuf) -> Self
pub fn log_dir(self, log_dir: PathBuf) -> Self
set a directory where logfiles would be created in
Enable or disable creation and logging to logfiles with log_to_file.
Default: DEFAULT_LOG_DIR (/dev/null)
Sourcepub const fn ansi(self, ansi: bool) -> Self
pub const fn ansi(self, ansi: bool) -> Self
enable or disable ANSI control sequences
Disabling ANSI control sequences might improve compatibility and readability when the logs are displayed by a program that does not interpret them.
Keeping ANSI control sequences enabled has the disadvantage of added colors for the logs.
Default: true
Sourcepub const fn display_filename(self, display_filename: bool) -> Self
pub const fn display_filename(self, display_filename: bool) -> Self
when making a log, display the source file in which a log was crated in
Default: false
Sourcepub const fn display_time(self, show_time: bool) -> Self
pub const fn display_time(self, show_time: bool) -> Self
when making a log, display the time of the message
Default: true
Sourcepub const fn display_level(self, display_level: bool) -> Self
pub const fn display_level(self, display_level: bool) -> Self
when making a log, display the log level of the message
Default: true
Sourcepub const fn display_target(self, display_target: bool) -> Self
pub const fn display_target(self, display_target: bool) -> Self
show target context
Default: false
Sourcepub const fn display_thread_ids(self, display_thread_ids: bool) -> Self
pub const fn display_thread_ids(self, display_thread_ids: bool) -> Self
show the id of the thread that created this message
Default: false
Sourcepub const fn display_thread_names(self, display_thread_names: bool) -> Self
pub const fn display_thread_names(self, display_thread_names: bool) -> Self
show the name of the thread that created this message
Default: false
Sourcepub const fn display_line_number(self, display_line_number: bool) -> Self
pub const fn display_line_number(self, display_line_number: bool) -> Self
show which line in the source file produces a log
Default: false
Sourcepub const fn pretty(self, pretty: bool) -> Self
pub const fn pretty(self, pretty: bool) -> Self
splits a log over multiple lines, looks like a python traceback
Default: false
Sourcepub const fn uptime(self, uptime: bool) -> Self
pub const fn uptime(self, uptime: bool) -> Self
show timestamps as uptime (duration since the logger was initialized)
Default: false
Sourcepub const fn set_level(self, max_level: Level) -> Self
pub const fn set_level(self, max_level: Level) -> Self
set the lowest loglevel to be displayed
Default: Level::INFO
Sourcepub const fn span_events(self, span_events: FmtSpan) -> Self
pub const fn span_events(self, span_events: FmtSpan) -> Self
set how span events are handled
Default: FmtSpan::NONE