az_logger
az_logger is a minimal and thread-safe logger for Rust applications. It provides easy-to-use logging macros, optional file output, colored terminal output, and configurable verbosity and filtering. I'm not expecting anyone to download this, as I'll be using it mostly for my Malware Development projects.
Features
- Simple logging macros:
info!,warn!,debug!,error!,success!,critical! - Optional log file output
- Template-based log file output
- Colorful terminal output using the
coloredcrate - Runtime-configurable verbosity, log level filtering, and color selection
- Thread-safe
- Stores recent log entries in memory with a configurable maximum
- Serde serializable
- Optional async runtime support via tokio and the
asyncfeature flag
[!IMPORTANT]
Using the async logger requires the tokio runtime to be enabled, so make sure it's running via the#[tokio::main]macro in your main function!
Logging Macros
All macros capture the source file and line number automatically:
info!;
debug!;
warn!;
error!;
success!;
critical!;
LoggerOptions
You can customize the logger behaviour using the LoggerOptions struct:
| Field | Description |
|---|---|
no_console |
Enables or disables all output |
log_to_stdout |
Enables printing to stdout |
log_to_stderr |
Enables printing error and critical logs to stderr |
color_output |
Enables colored output |
show_debug |
Enables debug-level logs |
show_info |
Enables info-level logs |
max_logs |
Specifies a limit on the amount of logs in the buffer |
truncate_previous_logs |
If true, the existing log file will be truncated instead of appended |
log_name_format |
Optional pattern to dynamically format the log file name |
log_dir |
Directory path where the log file will be created (if specified) |
custom_log_styles |
An optional [LogFormatStyles] struct to configure log styling per level |
no_line_num |
Disables line number logging for every logger except debug/critical |
no_file_name |
Disables file name logging for every logger except debug/critical |
no_level_string |
Disables level string logging in the log entry |
no_date |
Disables date logging for entries |
[!NOTE]
Ifcolor_outputis set tofalse,custom_log_styleswill be ignored
File Output
To log messages to a file, provide the path to Logger::init:
You can also customize the log file's location and filename dynamically using the log_dir and log_name_format options:
Supported filename tokens
The log_name_format string can contain the following placeholders:
| Token | Description |
|---|---|
<exe> |
Executable name (without extension) |
<dd> |
Day of the month (e.g. 07) |
<mm> |
Month (e.g. 04) |
<yyyy> |
Four-digit year (e.g. 2025) |
<yy> |
Two-digit year (e.g. 25) |
<HH> |
Hour (24-hour format) |
<MM> |
Minute |
<SS> |
Second |
<timestamp> |
UNIX timestamp (e.g. 1713706800) |
Examples
Here are a few example log_name_format values and their possible outputs:
| Format string | Example output | Description |
|---|---|---|
<exe>.log |
my_app.log |
Simple log file with the executable name |
<exe>_<dd>_<mm>.log |
my_app_22_04.log |
Log file with day and month |
<exe>_<yyyy>-<mm>-<dd>_<HH><MM><SS>.log |
my_app_2025-04-22_143015.log |
Full timestamped log file |
session_<timestamp>.log |
session_1713802456.log |
Log file using UNIX timestamp |
<exe>_<yy><mm><dd>.log |
my_app_250422.log |
Compact date format with two-digit year |
Notes
- If log_name_format is provided, the
Some("log.txt")argument toLogger::initis ignored — the final filename is generated from the format string. - If
log_diris provided, it will be automatically created if it doesn't exist. - If neither
log_name_formatnorlog_dirare specified, the logger will use the provided path as-is.
Getting the Logs
If for some reason you want to get the logs currently stored in the buffer, you can call the Logger::get_logs() function after initializing the logger:
use ;
Thread Safety
All internal state, including the log buffer and file handle, is wrapped in Arc, Mutex, and RwLock, ensuring safe concurrent access from multiple threads. I am thinking of adding async support, but I don't know yet if it will be useful
Example
use ;
Installation
Add the following to your Cargo.toml:
[]
= "0.1.5"
Or, alternatively:
cargo add az_logger
License
MIT