pub fn init(level: LogLevel, logfile: Option<&str>) -> Result<()>Expand description
Initialize the logging system.
This function sets up the tracing subscriber with the specified log level and output destination. It should be called once at application startup. Subsequent calls are no-ops.
§Arguments
level- The minimum log level to outputlogfile- Output destination:None- Log to stdout with ANSI colorsSome(":syslog:")- Log to system syslogSome(path)- Log to file at the specified path
§Returns
Ok(()) on success, or an error if initialization fails.
§Errors
Returns Error::Io if:
- The log file cannot be created or opened
- The syslog socket cannot be found (Linux:
/dev/log, macOS:/var/run/syslog)
Returns Error::Config if:
- The tracing subscriber cannot be set (usually means already initialized)
§Example
use vanguards_rs::{LogLevel, logger};
// Log to stdout (with colors)
logger::init(LogLevel::Notice, None).unwrap();
// Log to file (no colors)
logger::init(LogLevel::Debug, Some("/var/log/vanguards.log")).unwrap();
// Log to syslog
logger::init(LogLevel::Notice, Some(":syslog:")).unwrap();§Notes
- The
RUST_LOGenvironment variable can override the configured level - File logging appends to existing files
- Syslog messages are prefixed with “vanguards:”
§See Also
plog- Log messages after initializationcrate::config::LogLevel- Available log levels