#logging #level #formatting #different #messages #format #log-file

tangra

🪵 A lightweight and easy to use Rust logging library

7 stable releases

1.3.0 Oct 24, 2023
1.2.1 Oct 23, 2023

#216 in Debugging

Download history 11/week @ 2023-12-21 1/week @ 2023-12-28 21/week @ 2024-01-04 4/week @ 2024-02-15 18/week @ 2024-02-22 5/week @ 2024-02-29 5/week @ 2024-03-07 5/week @ 2024-03-14 9/week @ 2024-03-21 11/week @ 2024-03-28 118/week @ 2024-04-04

144 downloads per month
Used in 2 crates (via project-absence-kernel)

MIT license

785KB
433 lines

tangra.rs

Crates.io Badge CI Badge Dependency Status Badge

Discord Server Badge Last Commit Badge Conventional Commits Badge


A lightweight and easy to use Rust logging library that includes logging functionalities with different levels and custom formatting. It can also be used as a library to simply format the various messages you print in the terminal.

Showcase

macOS

macOS Showcase

Linux

Linux Showcase

Windows

Windows Showcase

Installation

If you want to use this library for one of your projects, you can install it like any other Go library

cargo add tangra

Customizing

Prefix

The prefix, what comes before the message, can be changed with the set_prefix method on a Logger structure.

The default prefix is $[datetime] $[level:color]$[level:name]$[reset]:

Placeholders

There are formatting placeholders that will be replaced in both the message and the prefix that can be seen here.

For example, logging the following message

$[fg:red]$[effect:blink]$[effect:bold]$[sys:username] says hello!

Will print a red blinking message in bold that says <username> says hello!, where <username> is the username on your system.

Styling

You can choose whether you want to style your messages or not with the SetStyling method on a Logger structure. Styling includes foreground colors, background colors and special effects such as bold, and others - see the terminal.rs file.

Note: The styling will not apply to the message if it is not supported by the terminal.

Log File

Logs can also be written inside a log file with styling removed. For example:

fn main() {
    let mut logger = tangra::Logger::new();
    logger.set_log_file_path("example.log");
    logger.debug("$[fg:red]$[effect:blink]$[effect:bold]$[sys:username] says hello!");
}

License

This library was made with 💜 by Krypton and is under the MIT license.

Dependencies