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>

source

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, 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.

source

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.

source

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 and errors. Additionally, this function fails with LogControl1Error::Failure if log::set_boxed_logger fails.

Trait Implementations§

source§

impl<F: LogFactory> LogControl1 for LogController<F>

source§

fn level(&self) -> LogLevel

Get the currently configured log level.
source§

fn set_level(&mut self, level: LogLevel) -> Result<(), LogControl1Error>

Set the level of the underlying log framework.
source§

fn target(&self) -> &str

Get the currently configured log target.
source§

fn set_target<S: AsRef<str>>( &mut self, target: S ) -> Result<(), LogControl1Error>

Set the target of the underlying log framework. Read more
source§

fn syslog_identifier(&self) -> &str

Get the syslog identifier.

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for LogController<F>where F: RefUnwindSafe,

§

impl<F> Send for LogController<F>where F: Send,

§

impl<F> Sync for LogController<F>where F: Sync,

§

impl<F> Unpin for LogController<F>where F: Unpin,

§

impl<F> UnwindSafe for LogController<F>where F: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.