pub struct FlexiConfig {Show 14 fields
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>,
}Expand description
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: StringDefines 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: TargetDefines where the log messages should be written to, disk or stderr? By default this is set to stderr.
stderr_format: LogFormatDefines the log format when writing to stderr. By default this will use the flexi_logger default format.
disk_format: LogFormatDefines 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: boolWhen logging to disk, flexi_logger can duplicate any error messages to stdout. The default is to duplicate the error messages.
disk_dup_info: boolWhen logging to disk, flexi_logger can duplicate any info messages to stdout. The default is to not duplicate the messages.
disk_filename_ext: StringThe extension for the log file. By default this is “log”.
disk_filename_time: boolFlag 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: PrioritySets 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.
Implementations§
Source§impl FlexiConfig
impl FlexiConfig
Sourcepub fn from_cargo_file<P: AsRef<Path>>(file: P) -> Result<FlexiConfig, Issues>
pub 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();Sourcepub fn from_cargo(file: &str) -> Result<FlexiConfig, Issues>
pub 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();Source§impl FlexiConfig
impl FlexiConfig
Sourcepub fn from_toml_file<P: AsRef<Path>>(file: P) -> Result<FlexiConfig, Issues>
pub 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()Sourcepub fn from_toml_string(input: &str) -> Result<FlexiConfig, Issues>
pub 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();Source§impl FlexiConfig
impl FlexiConfig
Sourcepub fn to_toml_string(self) -> String
pub 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());Source§impl FlexiConfig
impl FlexiConfig
Sourcepub fn project(self, project: &str) -> FlexiConfig
pub fn project(self, project: &str) -> FlexiConfig
Convenience method to set the project.
Sourcepub fn dependencies(self, name: &str, priority: Option<Priority>) -> FlexiConfig
pub fn dependencies(self, name: &str, priority: Option<Priority>) -> FlexiConfig
Convenience method to set the list of dependencies.
Sourcepub fn all_dependencies(self, priority: Option<Priority>)
pub fn all_dependencies(self, priority: Option<Priority>)
Set the priority for all dependencies to the same value.
Sourcepub fn target(self, target: Target) -> FlexiConfig
pub fn target(self, target: Target) -> FlexiConfig
Convenience method to set the target.
Sourcepub fn stderr_format(self, format: LogFormat) -> FlexiConfig
pub fn stderr_format(self, format: LogFormat) -> FlexiConfig
Convenience method to set the stderr log format.
Sourcepub fn disk_format(self, format: LogFormat) -> FlexiConfig
pub fn disk_format(self, format: LogFormat) -> FlexiConfig
Convenience method to set the disk log format.
Sourcepub fn disk_dir(self, dir: &str) -> FlexiConfig
pub fn disk_dir(self, dir: &str) -> FlexiConfig
Convenience method to set the log directory.
Sourcepub fn disk_dup_err(self, duplicate: bool) -> FlexiConfig
pub fn disk_dup_err(self, duplicate: bool) -> FlexiConfig
Convenience method to set the duplicate error flag.
Sourcepub fn disk_dup_info(self, duplicate: bool) -> FlexiConfig
pub fn disk_dup_info(self, duplicate: bool) -> FlexiConfig
Convenience method to set the duplicate info flag.
Sourcepub fn disk_filename_ext(self, ext: &str) -> FlexiConfig
pub fn disk_filename_ext(self, ext: &str) -> FlexiConfig
Convenience method to set the extension for the log files.
Sourcepub fn disk_filename_time(self, enable: bool) -> FlexiConfig
pub fn disk_filename_time(self, enable: bool) -> FlexiConfig
Convenience method to enable/disable a timestamp in the log file names.
Sourcepub fn disk_file_size(self, size: u32) -> FlexiConfig
pub 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.
Sourcepub fn disk_filename_suffix(self, suffix: &str) -> FlexiConfig
pub fn disk_filename_suffix(self, suffix: &str) -> FlexiConfig
Convenience method to set the log file name suffix.
Sourcepub fn app_priority(self, level: Priority) -> FlexiConfig
pub fn app_priority(self, level: Priority) -> FlexiConfig
Convenience method to set the level for logging messages from the application.
Source§impl FlexiConfig
impl FlexiConfig
Sourcepub fn new(
project: &str,
dependencies: BTreeMap<String, Option<Priority>>,
) -> FlexiConfig
pub fn new( 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();Sourcepub fn apply(self) -> Result<(), String>
pub 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§
Source§impl Clone for FlexiConfig
impl Clone for FlexiConfig
Source§fn clone(&self) -> FlexiConfig
fn clone(&self) -> FlexiConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more