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}. - Saving log to files: Save your logs to files automaticaly by specifying filename format
- File rotation: Rotate your files by specifying time period or size
- Compress used files: Save your space by compressing used log files
Installation
Add LogGit to your Cargo.toml:
[]
= "0.1.6"
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;
Setting up logging to the file
Enable save all your logs to a file
use set_file;
You can choose a format for the file name:
use set_file;
Choose how oftenly you change your file
use ;
Save your space by compressing log files
use ;
Choose the directory to save archived log files to
use ;
Configurate logger using env variables
colorized=false file_name="save_here.txt"
Importing config from files
use ;
Or simply crate a config file with one of those names:
loggit.envloggit.iniloggit.json
And it will be loaded automatically
Documentation
A complete user documentation can be found here
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.
- Custom file names: A format of a name that a file will take
- File rotation: How oftenly will the file be changed
- Compression method: To save space, you can specify the compression method.
- Archives directory: A directory to store the archives in
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.
Testing
There are two types of tests:
- unit tests that are stored in the
src/tests/folder. - integration tests that are stored in the
tests/folder.
Using cargo test is not recommended as it runs tests using multiple threads that doesn't respect the library logic, thus the next scripts are recommended:
test.shfor unit testsint_test.shfor integration tests
Release notes
In order to read release notes for each version, click here
License
LogGit is licensed under the MIT License.