Tlogger
A versatile and stylish logging library for Rust applications that provides both console output and file logging capabilities with customization options.
Features
-
๐ Multiple log levels with selective file logging
- Info, Warn, Error, Success, Debug levels
- Control which levels get saved to files
- Console output for all levels regardless of file settings
-
๐จ Rich text formatting
- Full RGB color support with true color ANSI codes
- Text styling (bold, italic, underline, strikethrough, dim)
- Nested and combined styles support
-
๐ฆ Flexible output formats
- Single-line logging with timestamps
- Box-style messages with titles
- Clean file output (automatically strips ANSI codes)
-
โฐ Time-based file management
- Configurable log rotation intervals
- Hourly, 3-hour, 6-hour, 9-hour, 12-hour, or daily files
- Automatic file creation and naming
-
๐ฏ Extensive customization options
- Custom colors for each log level
- Customizable symbols and borders
- Separate colors for titles and message text
-
๐ Development features
- Debug mode toggle for production/development
- Millisecond-precision timestamps
- Error handling for file operations
Installation
Add this to your Cargo.toml:
[]
= "0.1.4"
Or use the cargo add command:
Usage
use *;
Log Management
Log Intervals
Configure how frequently new log files are created:
init_logger.unwrap;
Available intervals:
LogInterval::OneHour- New file every hour (e.g.,2024-02-20-14h-15h.log)LogInterval::ThreeHour- Every 3 hours (e.g.,2024-02-20-12h-15h.log)LogInterval::SixHour- Every 6 hours (e.g.,2024-02-20-12h-18h.log)LogInterval::NineHour- Every 9 hours (e.g.,2024-02-20-09h-18h.log)LogInterval::TwelveHour- Every 12 hours (e.g.,2024-02-20-12h-00h.log)LogInterval::OneDay- One file per day (e.g.,2024-02-20-00h-24h.log)
Log Level Filtering
Control which types of logs are saved to files:
use *;
// Initialize logger
init_logger.unwrap;
// Clear default log levels (by default all levels are saved)
clear_log_levels;
// Add only the log levels you want to save
add_log_levels!;
// Now only Debug, Warn, and Error logs will be saved to files
// Info and Success logs will still show in console but won't be saved
Styling Options
Colors
Change the colors your logs use.
All log types (info, warn, error, success, debug) will change the color of boxes in box style outputs,
or will change the title of single line outputs. The log types with _text suffix (e.g., info_text) will change all message text.
use *;
customize_colors;
Text Styling
You can style your text using simple markdown-like syntax:
**text**for bold text*text*for italic text_text_for underlined text~text~for strikethrough text@text@for dimmed text
These styles can be nested and combined:
// Single styles
info!;
info!;
info!;
info!;
info!;
// Combined styles
info!;
info!;
info!;
// Works in box style too
info_box!;
Custom Styling
If you need to style text programmatically, you can use the style_text! macro:
let styled_text = style_text!;
Debug Mode
Debug messages can be disabled in production while still being logged to file:
set_debug; // Disables console output for debug messages
File Logging
When initialized, logs are automatically saved to files based on the specified interval. All ANSI color codes are automatically stripped from the file output for better readability.
License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Example Output
โน 12:34:56.789 โ Server Starting up...
โ 12:34:56.790 โ Login User Alice connected
โ 12:34:56.791 โ Memory Usage at 85%
โ 12:34:56.792 โ Database Connection failed
Box Style Output:
โญโโLoginโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณ 12:29:47โฎ
โ User Alice connected โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ