Crate simple_file_logger

Source
Expand description

§crates.io Crates.io docs.rs

§Simple File Logger

A simple file logger for rust.

The crate log is required to use this package.

cargo add log

Very basic setup, just provide an app name and an optional log level.

use simple_file_logger::{init_logger, LogLevel};
use log::info;

fn main() {
    init_logger("my_app", Loglevel::Info).unwrap();
    info!("Hello, world!");
}

or if you want to use the default log level (and save typing around 15 characters):

use simple_file_logger::init_logger;

fn main() {
    init_logger!("my_app").unwrap();
    info!("Hello, world!");
}

The log levels are: trace, debug, info , warn, error.

The log file is located:

OSPathExample
Windows%FOLDERID_LocalAppData%\program_name\log\program_nametime_stamp.logC:\Users\username\AppData\Local\program_name\log\program_name_2020-05-01T12-34-56.log
Linux$XDG_DATA_HOME/program_name/log/program_name_time_stamp.log/home/username/.local/share/program_name/log/program_name_2020-05-01T12-34-56.log
macOS$HOME/Library/Application Support/program_name/log/program_nametime_stamp.logUsers/username/Library/Application Support/program_name/log/program_name_2020-05-01T12-34-56.log

§Optional features

  • clap: enable clap parsing for LogLevel, Uses the ValueEnum proc-macro.
  • serde: enable serde serialization and deserialization on LogLevel.

Macros§

init_logger
This macro initializes the logger with the given log level or the default log level (info) if no log level is given.

Enums§

Error
Errors that this crate can produce.
LogLevel
Used to set the minimum log level displayed in the log file.

Functions§

init_logger
This initializes the logger with the given log level or the default log level (info) if no log level is given. Log level can be one of the following: trace, debug, info, warn, error The log file is located: