Struct flexi_logger::LogOptions [] [src]

pub struct LogOptions(_);

Allows initializing flexi_logger to your needs.

In order to initialize flexi_logger, create an instance of LogOptions, use one or several of its methods to adapt the configuration to your needs, and finally call init() with your desired loglevel-specification.

Examples

Use defaults only

If you initialize flexi_logger with default settings, then it behaves like env_logger:

use flexi_logger::LogOptions;

LogOptions::new().init(None).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:

use flexi_logger::{LogOptions,opt_format};

LogOptions::new()
            .log_to_file(true)
            .directory(Some("log_files".to_string()))
            .format(opt_format)
            .init(Some("myprog=debug,mylib=warn".to_string()) )
            .unwrap_or_else(|e|{panic!("Logger initialization failed with {}",e)});

Methods

impl LogOptions
[src]

The defaults for the logger initialization are

  • log_to_file(false)
  • print_message(true)
  • duplicate_error(true)
  • duplicate_info(false)
  • format(flexi_logger::default_format)
  • directory(None)
  • suffix(Some("log".to_string()))
  • timestamp(false)
  • rotate_over_size(None)
  • discriminant(None)
  • symlink(None)

Sets the option for logging to a file.

If this option is set to true, all logs will be written to a file, otherwise to stderr.

Sets the option for printing out an info message when a new output file is used.

If this option is set to true, an info message is printed to stdout when a new file is used for log-output.

Sets the option for duplicating logged error messages to stdout.

If this option is true and duplicate_error is set to true, then all logged error messages are additionally written to stdout.

Sets the option for duplicating logged error, warning and info messages to stdout.

If log_to_file is true and duplicate_info is set to true, then all logged error, warning, and info messages are additionally written to stdout.

Specifies a formatting function for the log entries.

The function being used by default is formats::default_format.

Specifies a folder for the log files.

This parameter only has an effect if log_to_file is set to true. If set to None, the log files are created in the folder where the program was started, otherwise in the specified folder. If the folder does not exist, the initialization will fail.

Specifies a suffix for the log files.

This parameter only has an effect if log_to_file is set to true.

If not set to None, then the log files are created with the specified suffix.

Sets the option for including a timestamp into the name of the log files.

This parameter only has an effect if log_to_file is set to true.

If set to true, then the names of the log files will include a timestamp.

Sets the option for specifying a maximum size for log files in bytes.

This parameter only has an effect if log_to_file is set to true.

If set to None, the log file will grow indefinitely. If a value is set, then when the log file reaches or exceeds the specified file size, the file will be closed and a new file will be opened. The filename pattern changes - instead of the timestamp a serial number is included into the filename.

Sets the option for specifying an additional part of the log file name.

This parameter only has an effect if log_to_file is set to true.

If specified, the additional part of the log file name is inserted after the program name.

Sets the option for including a timestamp into the name of the log files.

This parameter only has an effect if log_to_file is set to true.

If a String is specified, it will be used on linux systems to create in the current folder a symbolic link to the current log file.

Consumes the LogOptions object and initializes the flexi_logger.