Configuration and logging
Configuration precedence
Section titled “Configuration precedence”Examples read optional config.toml and .env files from the working directory:
Process environment > .env > TOML > defaults
The bot token remains required. An empty high-priority value does not silently fall back to a lower-priority source. The library itself does not read .env or modify the process environment.
| Setting | TOML | Environment or .env | Default |
|---|---|---|---|
| Log level | logging.level |
LOG_LEVEL |
INFO |
| Detailed log filter | None | RUST_LOG |
None |
| Total request timeout | telegram.request_timeout_seconds |
TELEGRAM_REQUEST_TIMEOUT_SECONDS |
30 seconds |
| Explicit HTTP proxy | telegram.proxy_url |
HTTPS_PROXY, ALL_PROXY, HTTP_PROXY, and lowercase variants |
Auto-detect |
| Proxy bypass | telegram.no_proxy |
NO_PROXY or no_proxy |
Backend-specific |
| Bot token | None | TELEGRAM_BOT_TOKEN |
Required |
Within one source, RUST_LOG takes priority over LOG_LEVEL. A process-level LOG_LEVEL still takes priority over RUST_LOG from .env.
Levels support TRACE, DEBUG, INFO, WARN, ERROR, and OFF in any case. Empty and invalid values return errors. Unknown TOML fields are not ignored silently; errors include the field or line and a suggested action.
Proxy sources
Section titled “Proxy sources”Examples search each source in HTTPS_PROXY, ALL_PROXY, HTTP_PROXY order, with uppercase variants before lowercase, before falling back to lower-priority sources.
The selected address is applied as a unified proxy, while NO_PROXY still applies. Do not commit proxies, bot tokens, or webhook secrets to shared configuration or logs.
tracing
Section titled “tracing”The project uses tracing. The library does not install a global subscriber; applications own logger initialization.
tracing_subscriber::fmt() .with_env_filter(std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into())) .try_init() .map_err(|error| anyhow::anyhow!("Failed to initialize tracing: {error}"))?;Logs include method names, phases, HTTP status, byte counts, timeouts, and elapsed time:
inforecords success.debugandtracerecord execution details.warnrecords rate limits and expired callbacks.errorrecords request or handler failures.
elapsed_ms is the total time from request validation through response parsing, including local upload reads. It is not Telegram server processing time. Logs do not print raw request or response bodies and do not replace returned errors.