Loggit
Loggit is a lightweight, easy-to-use logging library for Rust. It provides ready-to-use logger macros that let you start logging with zero boilerplate. You simply import and use it; no additional setup is required for basic usage. However, if you need more control, you can customize the logging format, colors, and minimum logging level.
Features
- Zero Setup: Just import the library and start logging.
- Customizable: Change log formats, colors, and logging levels.
- Macros Provided: Includes
trace!,debug!,info!,warn!, anderror!. - Flexible Formatting: Use custom templates with placeholders like
{level},{file},{line}, and{message}.
Installation
Add LogGit to your Cargo.toml:
[]
= "0.1.0"
or just write in the terminal:
cargo add loggit
Usage
Basic Logging
Simply import the logger macros and use it in your project:
use ;
Customizing the Log Level
Set the minimum log level so that only messages at that level and above are printed:
use set_log_level;
use Level;
Customizing the Log Format
You can adjust the log format globally or per log level. Templates can include placeholders like {level}, {file}, {line}, and {message}. Colors can be configured by wrapping text with color tags.
Global Format Customization
use set_global_formatting;
Level-Specific Format Customization
use set_level_formatting;
use Level;
Enabling Colorized Output
Enable or disable colored output based on your preference:
use set_colorized;
Customizing Terminal Output
Control whether messages are printed directly to the terminal:
use set_print_to_terminal;
Configuration
Internally, LogGit uses a simple configuration structure which holds:
- Log Level: One of TRACE, DEBUG, INFO, WARN, or ERROR.
- Terminal Output: A flag that determines if logs are printed to the terminal.
- Colorization: A flag to enable or disable colored output.
- Custom Formats: Individual formatters for each log level.
The default configuration already provides sensible defaults, so you can get started right away. Customization is available for those who need advanced logging setups.
Contributing
Contributions and suggestions are welcome! Feel free to open issues or submit pull requests to help improve LogGit.
License
LogGit is licensed under the MIT License.