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]

Create new instance.

Example

extern crate rlog;
use rlog::Logger;

let log = Logger::new("test.log", "%a %H:%M");

Format setter method.

Format getter method.

Path setter method.

Path getter method.

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"));

Auto Trait Implementations

impl Send for Logger

impl Sync for Logger