Module syslog

Source
Expand description

Facilities for sending log message to syslog.

Every function exported by this module is thread-safe. Each function will silently fail until syslog::init() is called and returns Ok.

This implements and sets logger up for logging facade exposed by the log crate.

§Examples

use log::{error, warn};
use base::syslog;

if let Err(e) = syslog::init() {
    println!("failed to initiailize syslog: {}", e);
    return;
}
warn!("this is your {} warning", "final");
error!("something went horribly wrong: {}", "out of RAMs");
use log::{error, warn};
use base::syslog::{init_with, LogConfig, fmt};
use std::io::Write;

let mut cfg = LogConfig::default();
cfg.log_args.stderr = true;
cfg.log_args.filter = String::from("info,base=debug,base::syslog=error,serial_console=false");

init_with(cfg).unwrap();
error!("something went horribly wrong: {}", "out of RAMs");

Re-exports§

pub use env_logger;

Modules§

fmt
Formatting for log records.

Macros§

debug
Logs a message at the debug level.
error
Logs a message at the error level.
info
Logs a message at the info level.
log
The standard logging macro.
log_enabled
Determines if a message logged at the specified level in that module will be logged.
trace
Logs a message at the trace level.
warn
Logs a message at the warn level.

Structs§

LogArgs
LogConfig
LoggingFacade 🔒
The logger that is provided to the log crate. Wraps our State struct so that we can reconfigure logging sinks on the fly.
Metadata
Metadata about a log message.
MetadataBuilder
Builder for Metadata.
ParseLevelError
The type returned by from_str when the string doesn’t match any of the log levels.
Record
The “payload” of a log message.
RecordBuilder
Builder for Record.
SetLoggerError
The type returned by set_logger if set_logger has already been called.
State
Syslogger

Enums§

Error
Errors returned by syslog::init().
Facility
The facility of a syslog message.
Level
An enum representing the available verbosity levels of the logger.
LevelFilter
An enum representing the available verbosity level filters of the logger.
Priority
The priority (i.e. severity) of a syslog message.

Constants§

STATIC_MAX_LEVEL
The statically resolved maximum log level.

Statics§

EARLY_INIT_CALLED 🔒
LOGGING_FACADE 🔒
STATE 🔒

Traits§

Log
A trait encapsulating the operations required of a logger.
Syslog 🔒

Functions§

apply_logging_state 🔒
early_init
Performs early (as in, moment of process start) logging initialization. Any logging prior to this call will be SILENTLY discarded. Calling more than once per process will panic.
init
Initialize the syslog connection and internal variables.
init_with
Initialize the syslog connection and internal variables.
logger
Returns a reference to the logger.
max_level
Returns the current maximum log level.
push_descriptors
Retrieves the file descriptors owned by the global syslogger.
set_boxed_logger
Sets the global logger to a Box<Log>.
set_logger
Sets the global logger to a &'static Log.
set_logger_racy
A thread-unsafe version of set_logger.
set_max_level
Sets the global maximum log level.
set_max_level_racy
A thread-unsafe version of set_max_level.
test_only_ensure_inited
Test only function that ensures logging has been configured. Since tests share module state, we need a way to make sure it has been initialized with some configuration.