Struct easylog::LogFile [−][src]
pub struct LogFile { /* fields omitted */ }
Struct that represents the LogFile
Methods
impl LogFile
[src]
impl LogFile
pub fn new(config: LogFileConfig) -> LogFile
[src]
pub fn new(config: LogFileConfig) -> LogFile
Creates a new Logfile.
Example 1
extern crate easylog; use easylog::{LogFile, LogFileConfig, LogLevel}; fn main() { let default_config = LogFileConfig::new(); let logfile = LogFile::new(default_config); }
You can also modify the config-struct
Example 2
extern crate easylog; use easylog::{LogFile, LogFileConfig, LogLevel}; fn main() { let mut custom_config = LogFileConfig::new(); custom_config.max_size_in_mb = 2; custom_config.extension = String::from(".txt"); let logfile = LogFile::new(custom_config); }
Details
At first this function checks, if already a logfile (specified by the config argument) exist. If a logfile exist the size is checked. If the size is okay (actual size < max size) the file will be opened. When the size is not okay (actual size > max size) a new file will be created.
pub fn write(&mut self, level: LogLevel, msg: &str)
[src]
pub fn write(&mut self, level: LogLevel, msg: &str)
Write the given message to the logfile.
Example
extern crate easylog; use easylog::{LogFile, LogFileConfig, LogLevel}; fn main() { let default_config = LogFileConfig::new(); let mut logfile = LogFile::new(default_config); logfile.write(LogLevel::DEBUG, "Insert your logmessage here..."); }
Example Output
2018-06-08 20:23:44.278165 [DEBUG ] Insert your logmessage here...
Details
The function will append a newline at the end of the message and insert a timestamp and the given loglevel at the beginning of the message.
This function also check if the actual logfilesize is less then the allowed maximum size.
If the actual logfilesize is bigger as the allowed maximum, the actual file will be closed, the filecounter will be incresaesed by 1 and a new file will be opened.
After writing the message to the file flush will be called to ensure that all is written to file.
Todo
Implementing exception handling when calling file.write() and file.flush()!