layla-log

Crates.iolayla-log
lib.rslayla-log
version0.2.8
sourcesrc
created_at2024-03-31 13:07:47.457268
updated_at2024-04-26 05:45:56.437331
descriptionA simple logger library.
homepage
repository
max_upload_size
id1191664
size16,459
Layla (ILikeLayla)

documentation

README

Layla-log

A simple logger library. This library provides a simple log writer and simple log level control. It can be used to write logs in a program. The logs can be written to the aimed dictionary. The log level can be set to different levels (Error, Warn, Debug, and Info).

Usage

This can be initialized by using default setting, only the path of the aim dictionary is needed.

use layla_log::*;

fn main() {
    default_init("path/to/log/directory/");
    clean_log(); // This will clean the log file.
    error!("error message.");
    warn!("warn message.");
    info!("info message.");
    debug!("debug message.");
    trace!("trace message.");
}

And this will be the output in the log file.

{time} ERROR error message.
{time} WARN warn message.
{time} DEBUG debug message.
{time} INFO info message.
{time} TRACE trace message.

(Because the default log level is TRACE, so all the log will be recorded.)

And the time format is "yyyy-MM-dd HH:mm:ss.SSS". (The millisecond is included.)

It also provides a function for personal initializing, the following can be decided.

  • The path of the aim dictionary.
  • Maximum number of log in a single file. (0 as inf.)
  • The restriction of the log level.
  • Time zone.
  • Show detailed time or not.
use layla_log::*;

fn main() {
    init("path/to/log/directory/", Some(200), Some(LogLevel::Debug) , 0, false);
    clean_log();
    error!("error message.");
    warn!("warn message.");
    info!("info message.");
    debug!("debug message.");
    trace!("trace message.");
}

And this will be the output.

{time} ERROR error message.
{time} WARN warn message.
{time} INFO info message.
{time} DEBUG debug message.
Commit count: 0

cargo fmt