# 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]

#### `fn new() -> LogOptions`

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)

#### `fn log_to_file(self, log_to_file: bool) -> LogOptions`

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.

#### `fn print_message(self, print_message: bool) -> LogOptions`

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.

#### `fn duplicate_error(self, duplicate_error: bool) -> LogOptions`

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.

#### `fn duplicate_info(self, duplicate_info: bool) -> LogOptions`

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.

#### `fn format(self, format: fn(_: &LogRecord) -> String) -> LogOptions`

Specifies a formatting function for the log entries.

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

#### `fn directory(self, directory: Option<String>) -> LogOptions`

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.

#### `fn suffix(self, suffix: Option<String>) -> LogOptions`

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.

#### `fn timestamp(self, timestamp: bool) -> LogOptions`

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.

#### `fn rotate_over_size(self, rotate_over_size: Option<usize>) -> LogOptions`

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.

#### `fn discriminant(self, discriminant: Option<String>) -> LogOptions`

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.

#### `fn symlink(self, create_symlink: Option<String>) -> LogOptions`

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.

#### `fn init(self, loglevelspec: Option<String>) -> Result<(), FlexiLoggerError>`

Consumes the LogOptions object and initializes the flexi_logger.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)