Logging
RustMailer uses the tracing
framework for structured logging. Logging can be configured via command-line arguments or environment variables. We recommend using environment variables for production environments.
Supported Configuration Options
Variable Name | Type | Default | Description |
---|---|---|---|
RUSTMAILER_LOG_LEVEL | string | info | Sets the log level. Options: trace , debug , info , warn , error . |
RUSTMAILER_ANSI_LOGS | boolean | false | Enables ANSI colored log output. |
RUSTMAILER_JSON_LOGS | boolean | false | Outputs logs in JSON format (one JSON object per line). |
RUSTMAILER_LOG_TO_FILE | boolean | false | Enables writing logs to a file. Recommended in production. |
RUSTMAILER_MAX_SERVER_LOG_FILES | integer | 5 | Number of daily rotated log files to retain. |
RUSTMAILER_ROOT_DIR | path | . | Root directory for log files; logs are stored in the logs/ subdirectory. |
Example: Setting via Environment Variables
You can set these variables in a .env
file or export them before running RustMailer:
export RUSTMAILER_LOG_LEVEL=warn
export RUSTMAILER_JSON_LOGS=true
export RUSTMAILER_LOG_TO_FILE=true
export RUSTMAILER_MAX_SERVER_LOG_FILES=14
export RUSTMAILER_ROOT_DIR=/var/lib/rustmailer
Log Output Examples
- Default (stdout):
2025-07-15T15:01:23Z INFO rustmailer::server: server started on 0.0.0.0:8000
- JSON log format:
{"timestamp":"2025-07-15T15:01:23Z","level":"INFO","target":"rustmailer::server","message":"server started on 0.0.0.0:8000"}
- Log file location:
If RUSTMAILER_LOG_TO_FILE=true
, logs are written to:
{RUSTMAILER_ROOT_DIR}/logs/server-2025-07-15.log
And old files are rotated daily, based on RUSTMAILER_MAX_SERVER_LOG_FILES
.
tip
- Enable
RUSTMAILER_LOG_TO_FILE
in production to persist logs. - Use
RUSTMAILER_JSON_LOGS
for machine-readable logs (e.g., ELK/ClickHouse ingestion). - Make sure
RUSTMAILER_ROOT_DIR
points to a persistent volume (especially in containers).