Logging
Configuring logging output and levels
trojan-rs uses the tracing framework for structured logging.
Configuration
[logging]
level = "info"
format = "pretty"
output = "stderr"Log Level
| Level | Description |
|---|---|
error | Errors that affect operation |
warn | Warnings and degraded conditions |
info | Normal operational events (connections, auth) |
debug | Detailed debugging information |
trace | Very verbose tracing (protocol bytes, state transitions) |
Default: info
Log Format
| Format | Description |
|---|---|
pretty | Human-readable, colorized output (default) |
compact | Single-line human-readable format |
json | Structured JSON, one object per line |
pretty — Best for development and interactive use:
2024-01-15T10:30:00Z INFO trojan_server: connection accepted client_ip=192.168.1.1json — Best for log aggregation systems (ELK, Loki, etc.):
{"timestamp":"2024-01-15T10:30:00Z","level":"INFO","target":"trojan_server","message":"connection accepted","client_ip":"192.168.1.1"}compact — Condensed single-line format:
2024-01-15T10:30:00Z INFO trojan_server: connection accepted client_ip=192.168.1.1Output Target
| Target | Description |
|---|---|
stderr | Standard error (default) |
stdout | Standard output |
Per-Module Filters
Override the log level for specific modules:
[logging.filters]
trojan_auth = "debug" # Verbose auth logging
trojan_server = "info" # Normal server logging
rustls = "warn" # Suppress rustls noise
h2 = "warn" # Suppress HTTP/2 noiseThis is useful for debugging specific subsystems without flooding output from other modules.
CLI Override
The --log-level CLI flag overrides the config file:
trojan server -c config.toml --log-level debugProduction Recommendations
For production deployments:
[logging]
level = "info"
format = "json"
output = "stderr"
[logging.filters]
rustls = "warn"- Use
jsonformat for structured log aggregation - Set
infolevel for normal operations - Suppress verbose third-party crate logging with filters
- Route stderr to your log collection system (journald, fluentd, etc.)
Log Rotation
trojan-rs writes to stderr/stdout and does not manage log files directly. Use your system's log management:
systemd/journald
When running as a systemd service, logs go to journald automatically:
journalctl -u trojan -f # Follow logs
journalctl -u trojan --since today # Today's logs
journalctl -u trojan -p err # Errors onlyFile-based rotation
Redirect output and use logrotate:
trojan server -c config.toml 2>> /var/log/trojan/server.log# /etc/logrotate.d/trojan
/var/log/trojan/*.log {
daily
rotate 14
compress
missingok
notifempty
copytruncate
}