Struct flexi_logger::Logger
[−]
[src]
pub struct Logger { /* fields omitted */ }
The standard entry-point for using flexi_logger.
Create a Logger with your desired loglevel-specification
- by specifying a String programmatically, using Logger::with_str(),
- or by expecting a String in the environment, using Logger::with_env(),
- or by providing an explicitly built LogSpecification, using Logger::with(),
use its configuration methods, and finally call start().
Examples
Use defaults only
If you initialize flexi_logger like this, it behaves like env_logger:
use flexi_logger::Logger; Logger::with_env().start().unwrap();
Write to files, use a detailed log-line format that contains the module and line number
Here we configure flexi_logger to write log entries with time and location info into a log file in folder "log_files", and we provide the loglevel-specification programmatically, as String:
use flexi_logger::{Logger,opt_format}; Logger::with_str("myprog=debug, mylib=warn") .log_to_file() .directory("log_files") .format(opt_format) .start() .unwrap_or_else(|e|{panic!("Logger initialization failed with {}",e)});
Methods
impl Logger
[src]
fn with(logspec: LogSpecification) -> Logger
Create a Logger that you provide with an explicit LogSpecification.
fn with_str<S: AsRef<str>>(s: S) -> Logger
Create a Logger that reads the LogSpecification from a String or &str.
fn with_env() -> Logger
Create a Logger that reads the LogSpecification from the environment variable RUST_LOG.
fn log_to_file(self) -> Logger
Makes the logger write all logs to a file, rather than to stderr.
fn print_message(self) -> Logger
Makes the logger print an info message to stdout when a new file is used for log-output.
fn duplicate_error(self) -> Logger
Makes the logger write all logged error messages additionally to stdout.
fn duplicate_info(self) -> Logger
Makes the logger write all logged error, warning, and info messages additionally to stdout.
fn format(self, format: fn(_: &LogRecord) -> String) -> Logger
Makes the logger use the provided format function for the log entries, rather than the default (formats::default_format).
fn directory<S: Into<String>>(self, directory: S) -> Logger
Specifies a folder for the log files.
This parameter only has an effect if log_to_file is set to true. If the specified folder does not exist, the initialization will fail. By default, the log files are created in the folder where the program was started.
fn suffix<S: Into<String>>(self, suffix: S) -> Logger
Specifies a suffix for the log files.
This parameter only has an effect if log_to_file is set to true.
fn timestamp(self) -> Logger
Makes the logger include a timestamp into the names of the log files (log_to_file must be chosen, too).
fn rotate_over_size(self, rotate_over_size: usize) -> Logger
This option only has an effect if log_to_file is used, too.
By default, the log file will grow indefinitely. With this option, when the log file reaches or exceeds the specified file size, the file will be closed and a new file will be opened. Also he filename pattern changes - instead of the timestamp a serial number is included into the filename.
fn discriminant<S: Into<String>>(self, discriminant: S) -> Logger
This option only has an effect if log_to_file is used, too.
The specified String is added to the log file name.
fn create_symlink<S: Into<String>>(self, symlink: S) -> Logger
This option only has an effect if log_to_file is used, too.
The specified String will be used on linux systems to create in the current folder a symbolic link to the current log file.
fn start(self) -> Result<(), FlexiLoggerError>
Consumes the Logger object and initializes the flexi_logger.