Struct flexi_config::FlexiConfig [] [src]

pub struct FlexiConfig {
    pub project: String,
    pub dependencies: BTreeMap<String, Option<Priority>>,
    pub target: Target,
    pub stderr_format: LogFormat,
    pub disk_format: LogFormat,
    pub disk_dir: Option<String>,
    pub disk_dup_err: bool,
    pub disk_dup_info: bool,
    pub disk_filename_ext: String,
    pub disk_filename_time: bool,
    pub disk_file_size: Option<u32>,
    pub disk_filename_suffix: Option<String>,
    pub app_priority: Priority,
    pub issues: Option<Issues>,
}

Main structure for the crate. This object is used to create the configuration file, load the configuration file, and apply the settings to flexi_logger.

This object will initialize flexi_logger to start logging messages. It can be created programatically, from a Cargo.toml file, or from a configuration TOML file. Once the settings are correct the configuration can be applied to flexi_logger and logging can start.

Fields

Defines the name of the application.

Defines the list of modules the application depends on and the lowest level log message

Defines where the log messages should be written to, disk or stderr? By default this is set to stderr.

Defines the log format when writing to stderr. By default this will use the flexi_logger default format.

Defines the log format when writing to disk. By default this will use the flexi_logger detailed format.

If logging to disk is enabled, this sets the directory to write to. By default (None) it will write to the current directory.

When logging to disk, flexi_logger can duplicate any error messages to stdout. The default is to duplicate the error messages.

When logging to disk, flexi_logger can duplicate any info messages to stdout. The default is to not duplicate the messages.

The extension for the log file. By default this is "log".

Flag to tell flexi_logger to include the timestamp when a log file is created. This is set to true by default. If the file_limit_size is set however this value will be ignored.

If set, limits the size of the log file in megabytes. When this size is reached a new file is created. If this value is set the log files will have a sequence number rather than a time stamp.

Adds a suffix to the log file names This will be included after the program name but

Sets the lowest priority to report for you application. The default priority is Warn.

If the object was loaded from a TOML configuration file, this object will contain any issues encountered while loading the file.

Methods

impl FlexiConfig
[src]

Construct a new instance from a Cargo.toml file located on disk. This can be used during development to create the initial configuration file to ship with the application.

Examples

use flexi_config::FlexiConfig;

let config = FlexiConfig::from_cargo_file("Cargo.toml").unwrap();

config.to_toml_file("log.toml").unwrap();

You can also change some of the default values to values that work better for your application.

use flexi_config::{FlexiConfig, Target};

let mut config = FlexiConfig::from_cargo_file("Cargo.toml").unwrap();

config.target   = Target::Disk;
config.disk_dir = Some(String::from("logs"));

config.to_toml_file("log.toml").unwrap();

Construct a new object from a Cargo.toml file that has already been loaded. Use this method if you want to load the Cargo.toml file yourself. Or you could provide a static string for the Cargo file instead.

Examples

use flexi_config::FlexiConfig;

let mut config = FlexiConfig::from_cargo(r#"
    [package]
    name="foo"
    [dependencies]
    rand = "*"
    time = "*"
    "#).unwrap();

config.to_toml_file("log.toml").unwrap();

impl FlexiConfig
[src]

Creates an instance of the object by loading a configuration file that has been previously created.

Examples

use flexi_config::FlexiConfig;

let mut config = FlexiConfig::from_toml_file("log.toml").unwrap();

config.apply().unwrap()

Creates an instance from a file already loaded into memory. Use this method if you want to load the configuration file yourself and pass it to FlexiConfig. Or you could use it to contruct from a static string.

Examples

use flexi_config::FlexiConfig;

let config = FlexiConfig::from_toml_string(r#"
    [common]
    application="foo"
    priority="warn"
    target="stderr"
    stderr_format="detailed"
    [depends]
    rand = "warn"
    time = "trace"
    "#).unwrap();

config.apply().unwrap();

impl FlexiConfig
[src]

Construct the configuration TOML file into a string. Use this method is you would like to save the configuration file yourself.

Examples

use flexi_config::FlexiConfig;

let config = FlexiConfig::from_cargo_file("Cargo.toml").unwrap();

println!("{}", config.to_toml_string());

Saves the log configuration to a TOML file on disk.

Examples

use flexi_config::FlexiConfig;

let config = FlexiConfig::from_cargo_file("Cargo.toml").unwrap();

config.to_toml_file("log.toml").unwrap();

impl FlexiConfig
[src]

Convenience method to set the project.

Convenience method to set the list of dependencies.

Set the priority for all dependencies to the same value.

Convenience method to set the target.

Convenience method to set the stderr log format.

Convenience method to set the disk log format.

Convenience method to set the log directory.

Convenience method to set the duplicate error flag.

Convenience method to set the duplicate info flag.

Convenience method to set the extension for the log files.

Convenience method to enable/disable a timestamp in the log file names.

Convenience method to set a file size limit. Setting a size of 0 will disable the file size limit.

Convenience method to set the log file name suffix.

Convenience method to set the level for logging messages from the application.

impl FlexiConfig
[src]

Creates an instance of the object from the values passed in.

This could be used to create a configuration programatically.

Examples

Create an initial configuration file that can be modified by a human.

use std::collections::BTreeMap;
use flexi_config::{FlexiConfig, Priority};

let mut depends =  BTreeMap::new();

depends.insert(String::from("time"), None);
depends.insert(String::from("rand"), Some(Priority::Debug));

let config = FlexiConfig::new("foo", depends);

config.to_toml_file("log.toml");

Create a configuration and apply it to flexi_config immediately.

use std::collections::BTreeMap;
use flexi_config::{FlexiConfig, Priority};

let mut depends =  BTreeMap::new();

depends.insert(String::from("time"), Some(Priority::Warn));
depends.insert(String::from("rand"), Some(Priority::Debug));

let config = FlexiConfig::new("foo", depends);

config.apply().unwrap();

Applies the configuration to flexi_logger.

Any log messages generated before this call will be lost. This method should only ever be called once, the logger configuration cannot change after it is set.

Examples

Apply a programatic configuration that doesn't allow the user to change anything.

use std::collections::BTreeMap;
use flexi_config::{FlexiConfig, Priority};

let mut depends =  BTreeMap::new();

depends.insert(String::from("time"), Some(Priority::Warn));
depends.insert(String::from("rand"), Some(Priority::Debug));

let config = FlexiConfig::new("foo", depends);

config.apply().unwrap();

Load a configuration file from disk and apply it.

use flexi_config::FlexiConfig;

let config = FlexiConfig::from_toml_file("log.toml").unwrap();

config.apply().unwrap();

Trait Implementations

impl Debug for FlexiConfig
[src]

Formats the value using the given formatter.

impl Clone for FlexiConfig
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more