Struct rlog::Logger [−][src]
pub struct Logger { /* fields omitted */ }
Main structure.
pub struct Logger { path: String, format: String, }
path
: filepath to the log file you want to use, can be relative.format
: timestamp in ISO8061 format.
Please note that the log file isn't created after creating a new instance of Logger struct,
but rather after the first call to log()
method. That is also the time when filepath given is validated.
Examples
Default timestamp formatting
extern crate rlog; use rlog::Logger; let log = Logger::new("my.log", ""); // Note the empty string literal as second parameter. // Method log() returns a bool to signal succes or failure. assert!(log.log("Just testing")); assert!(log.log("Another test"));
Result is in file my.log
in the root directory of your crate:
ⓘThis example is not tested
10.08.2018 09:06.33 Just testing 10.08.2018 09:06.34 Another test
Custom formatting
rlog supports (thanks to chrono) ISO 8061 timestamp formatting.
extern crate rlog; use rlog::Logger; let log = Logger::new("my.log", "%d-%m %H:%M"); assert!(log.log("Custom format test"));
Output:
my.log
ⓘThis example is not tested
10-08 10:46 Custom format test
Methods
impl Logger
[src]
impl Logger
pub fn new(path: &str, format: &str) -> Logger
[src]
pub fn new(path: &str, format: &str) -> Logger
Create new instance.
Example
extern crate rlog; use rlog::Logger; let log = Logger::new("test.log", "%a %H:%M");
pub fn fmt(&mut self, fmt: &str)
[src]
pub fn fmt(&mut self, fmt: &str)
Format setter method.
pub fn get_fmt(&self) -> &str
[src]
pub fn get_fmt(&self) -> &str
Format getter method.
pub fn path(&mut self, path: &str)
[src]
pub fn path(&mut self, path: &str)
Path setter method.
pub fn get_path(&self) -> &str
[src]
pub fn get_path(&self) -> &str
Path getter method.
pub fn log(&self, msg: &str) -> bool
[src]
pub fn log(&self, msg: &str) -> bool
Log message msg
to file.
This method will create the log file if it does not exist.
Errors
If there are problems opening a file, the method returns false
and prints error to stderr.
Result<T, Err>
isn't used for the sake of simplicity.
Example
extern crate rlog; use rlog::Logger; let log = Logger::new("my.log", ""); assert!(log.log("Just testing"));