LogController

Struct LogController 

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

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

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.

§Errors

Return LogControl1Error::InputOutputError if journald is not available, but should have been. This will only happen on a broken system.

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.

§Errors

See Self::new_auto for 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. Read more
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> Freeze for LogController<F>
where F: Freeze,

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.