[][src]Crate fmtlog

A simple configurable logger with format specification.

This crate provides an implementation of log crate, which provides integrated logging interface.

Examples

Basic

#[macro_use]
extern crate log;
extern crate fmtlog;

fn main() {
    fmtlog::default().set().unwrap();

    info!("Hello!"); // INFO: Hello!
}

See also the function default.

Configure in Code

#[macro_use]
extern crate log;
extern crate fmtlog;

use fmtlog::{Config, LevelFilter};

fn main() {
    fmtlog::new(Config::new().level(LevelFilter::Trace))
        .set()
        .unwrap();

    info!("Hello!"); // INFO: Hello!
}

See also the struct Config.

Format Specification

The format string is basically a string, but the following specifiers will converted into another string.

Spec.ExampleDescription
%%Literal %.
%}Literal }. (use in {}.)
%NhyperThe target of the log.
%fmain.rsThe file that the log defined.
%Smain.rs:15The file and line that the log defined.
%MAn error has occured.The log message.
%linfoThe log level. (lowercase)
%LINFOThe log level. (uppercase)
%T(<format>)%T(%D %T) -> 01/01/21 12:00:00The local time. (see chrono's format specification).
%U(<format>)%T(%D %T) -> 01/01/21 12:00:00The UTC time. (see chrono's format specification).
%F(<color>){...}Set the foreground color.
%F(<error>,<warn>,<info>,<debug>,<trace>){...}Set the foreground color. (Branch by the log level.)
%B(<color>){...}Set the background color.
%B(<error>,<warn>,<info>,<debug>,<trace>){...}Set the background color. (Branch by the log level.)
%b{...}Bold the text.
%d{...}Dim the text color.
%i{...}Print the text in italics.
%r{...}Reverse the foreground and background color.
%u{...}Underline the text.
%s{...}Strikethrough the text.

Supported Color

All supported color used by %C and %O is here.

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • bright black
  • bright red
  • bright green
  • bright yellow
  • bright blue
  • bright magenta
  • bright cyan
  • bright white
  • #ffffff (Hexadecimal RGB)

Modules

formats

Formats Collection

Structs

Config

The logger settings.

Logger

The body of fmtlog.

Enums

Colorize

Colorize the output

LevelFilter

An enum representing the available verbosity level filters of the logger.

Output

The Output type

Functions

default

Create a logger by default settings.

new

Create a logger by custom settings.