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
project: String
Defines the name of the application.
dependencies: BTreeMap<String, Option<Priority>>
Defines the list of modules the application depends on and the lowest level log message
target: Target
Defines where the log messages should be written to, disk or stderr? By default this is set to stderr.
stderr_format: LogFormat
Defines the log format when writing to stderr. By default this will use the flexi_logger default format.
disk_format: LogFormat
Defines the log format when writing to disk. By default this will use the flexi_logger detailed format.
disk_dir: Option<String>
If logging to disk is enabled, this sets the directory to write to. By default (None) it will write to the current directory.
disk_dup_err: bool
When logging to disk, flexi_logger can duplicate any error messages to stdout. The default is to duplicate the error messages.
disk_dup_info: bool
When logging to disk, flexi_logger can duplicate any info messages to stdout. The default is to not duplicate the messages.
disk_filename_ext: String
The extension for the log file. By default this is "log".
disk_filename_time: bool
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.
disk_file_size: Option<u32>
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.
disk_filename_suffix: Option<String>
Adds a suffix to the log file names This will be included after the program name but
app_priority: Priority
Sets the lowest priority to report for you application. The default priority is Warn.
issues: Option<Issues>
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]
fn from_cargo_file<P: AsRef<Path>>(file: P) -> Result<FlexiConfig, Issues>
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();
fn from_cargo(file: &str) -> Result<FlexiConfig, Issues>
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]
fn from_toml_file<P: AsRef<Path>>(file: P) -> Result<FlexiConfig, Issues>
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()
fn from_toml_string(input: &str) -> Result<FlexiConfig, Issues>
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]
fn to_toml_string(self) -> String
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());
fn to_toml_file<P: AsRef<Path>>(self, file: P) -> Result<(), 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]
fn project(self, project: &str) -> FlexiConfig
Convenience method to set the project.
fn dependencies(self, name: &str, priority: Option<Priority>) -> FlexiConfig
Convenience method to set the list of dependencies.
fn all_dependencies(self, priority: Option<Priority>)
Set the priority for all dependencies to the same value.
fn target(self, target: Target) -> FlexiConfig
Convenience method to set the target.
fn stderr_format(self, format: LogFormat) -> FlexiConfig
Convenience method to set the stderr log format.
fn disk_format(self, format: LogFormat) -> FlexiConfig
Convenience method to set the disk log format.
fn disk_dir(self, dir: &str) -> FlexiConfig
Convenience method to set the log directory.
fn disk_dup_err(self, duplicate: bool) -> FlexiConfig
Convenience method to set the duplicate error flag.
fn disk_dup_info(self, duplicate: bool) -> FlexiConfig
Convenience method to set the duplicate info flag.
fn disk_filename_ext(self, ext: &str) -> FlexiConfig
Convenience method to set the extension for the log files.
fn disk_filename_time(self, enable: bool) -> FlexiConfig
Convenience method to enable/disable a timestamp in the log file names.
fn disk_file_size(self, size: u32) -> FlexiConfig
Convenience method to set a file size limit. Setting a size of 0 will disable the file size limit.
fn disk_filename_suffix(self, suffix: &str) -> FlexiConfig
Convenience method to set the log file name suffix.
fn app_priority(self, level: Priority) -> FlexiConfig
Convenience method to set the level for logging messages from the application.
impl FlexiConfig
[src]
fn new(
project: &str,
dependencies: BTreeMap<String, Option<Priority>>
) -> FlexiConfig
project: &str,
dependencies: BTreeMap<String, Option<Priority>>
) -> FlexiConfig
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();
fn apply(self) -> Result<(), String>
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]
impl Clone for FlexiConfig
[src]
fn clone(&self) -> FlexiConfig
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more