Crate ultimate_logger

source ·
Expand description

Ultimate Logger is a simple logger that can write to a file and/or the console.

Examples

Write to the console

use ultimate_logger::Logger;
use ultimate_logger::log_level::LogLevel;

let mut logger = Logger::new(String::from("example"), LogLevel::Trace);

logger.trace("This is a trace message");
logger.debug("This is a debug message");
logger.info("This is an info message");
logger.warning("This is a warning message");
logger.error("This is an error message");
logger.critical("This is a critical message");

This will output the following to the console with appropriate colors:

[2020-05-01 12:00:00.000] [example] [trace] This is a trace message
[2020-05-01 12:00:00.000] [example] [debug] This is a debug message
[2020-05-01 12:00:00.000] [example] [info] This is an info message
[2020-05-01 12:00:00.000] [example] [warning] This is a warning message
[2020-05-01 12:00:00.000] [example] [error] This is an error message
[2020-05-01 12:00:00.000] [example] [critical] This is a critical message

Write to a file

use ultimate_logger::Logger;
use ultimate_logger::log_level::LogLevel;

let mut logger = Logger::new_to_file(String::from("example"), LogLevel::Trace, String::from("log.txt"), true);

logger.trace("This is a trace message");
logger.debug("This is a debug message");
logger.info("This is an info message");
logger.warning("This is a warning message");
logger.error("This is an error message");
logger.critical("This is a critical message");

Below is the text which will output to the file log.txt, and to the console. The console output will be colored.

[2020-05-01 12:00:00.000] [example] [trace] This is a trace message
[2020-05-01 12:00:00.000] [example] [debug] This is a debug message
[2020-05-01 12:00:00.000] [example] [info] This is an info message
[2020-05-01 12:00:00.000] [example] [warning] This is a warning message
[2020-05-01 12:00:00.000] [example] [error] This is an error message
[2020-05-01 12:00:00.000] [example] [critical] This is a critical message

Features

  • Write to a file
  • Write to the console
  • Write to both
  • Set a minimum log level
  • Colored output
  • Timestamps
  • Multiple loggers with different names

Modules

Structs

  • A logger that can write to a file and/or the console.