pub struct LogController<F: LogFactory> { /* private fields */ }Expand description
A LogControl1 implementation for log.
This implementation creates a log::Log implementation whose level and
underlying logger can be dynamically reconfigured through the LogControl1
interface. It uses a ReloadLog together with a LevelFilter under
the hood.
Currently, this implementation only supports for following KnownLogTargets:
Any other target fails with LogControl1Error::UnsupportedLogTarget.
Implementations§
Source§impl<F: LogFactory> LogController<F>
impl<F: LogFactory> LogController<F>
Sourcepub fn new(
factory: F,
connected_to_journal: bool,
syslog_identifier: String,
target: KnownLogTarget,
level: Level,
) -> Result<(Self, ControlledLog), LogControl1Error>
pub fn new( factory: F, connected_to_journal: bool, syslog_identifier: String, target: KnownLogTarget, level: Level, ) -> Result<(Self, ControlledLog), LogControl1Error>
Create a new logger which can be controlled through the log control interface.
factory creates the inner log::Log instances for the selected target which
denotes the initial log target. The factory is invoked whenever the log target
is changed, to create a new logger for the corresponding target. See
LogController for supported log targets.
connected_to_journal indicates whether this process is connected to the systemd
journal. Set to true to make KnownLogTarget::Auto use KnownLogTarget::Journal,
otherwise it uses KnownLogTarget::Console.
level denotes the default tracing log level to start with.
syslog_identifier is passed to LogFactory::create_journal_log
for use as SYSLOG_IDENTIFIER journal field.
Returns an error if target is not supported, of if creating a layer fails,
§Errors
Return a LogControl1Error::UnsupportedLogTarget if target is
not supported, and LogControl1Error::InputOutputError if creating
the logger for target failed, e.g. when selecting KnownLogTarget::Journal
on a system where journald is not running, or inside a container which
has no direct access to the journald socket.
Sourcepub fn new_auto(
factory: F,
level: Level,
) -> Result<(Self, ControlledLog), LogControl1Error>
pub fn new_auto( factory: F, level: Level, ) -> Result<(Self, ControlledLog), LogControl1Error>
Create a new logger which can be controlled through the log control interface, using automatic defaults.
Use logcontrol::syslog_identifier() as the syslog identifier, and
determine the initial log target automatically according to
logcontrol::stderr_connected_to_journal().
level denotes the initial level; for factory and returned errors,
see Self::new.
§Errors
Return LogControl1Error::InputOutputError if journald is not
available, but should have been. This will only happen on a broken
system.
Sourcepub fn install_auto(factory: F, level: Level) -> Result<Self, LogControl1Error>
pub fn install_auto(factory: F, level: Level) -> Result<Self, LogControl1Error>
Create and install a controlled logger, with automatic defaults.
See Self::new_auto for arguments.
§Errors
See Self::new_auto for errors. Additionally, this function fails with
LogControl1Error::Failure if log::set_boxed_logger fails.