Logger

Struct Logger 

Source
pub struct Logger;
Expand description

§Logger for libpt

A logger is generally a functionality that let’s you write information from your library or application in a more structured manner than if you just wrote all information to stdout or stderr with the likes of println! or eprintln!.

It offers writing to multiple targets, such as both the terminal and a log file, and allows users to choose the verbosity of the information that gets printed by selecting a Loglevel.

§Levels

  • ERROR – Something broke
  • WARN – Something is bad
  • INFO – Useful information for users
  • DEBUG – Useful information for developers
  • TRACE – Very verbose information for developers (often for libraries)

§Usage

You don’t need to use the Logger struct, it’s better to use the macros instead:

You can however use the Logger struct in cases where usage of a macro is impossible or you are somehow working with multiple loggers. The macros offer additional functionalities, suck as full format! support and context, see tracing, which we use as backend.

§Examples

Logger::builder()
    .uptime(true)
    .build();
info!("hello world");

Implementations§

Source§

impl Logger

§Main implementation
Source

pub fn builder() -> LoggerBuilder

Get a new LoggerBuilder

Source

pub fn error<T>(&self, printable: T)
where T: Display,

§logging at Level::ERROR
Source

pub fn warn<T>(&self, printable: T)
where T: Display,

§logging at Level::WARN
Source

pub fn info<T>(&self, printable: T)
where T: Display,

§logging at Level::INFO
Source

pub fn debug<T>(&self, printable: T)
where T: Display,

§logging at Level::DEBUG
Source

pub fn trace<T>(&self, printable: T)
where T: Display,

§logging at Level::TRACE

Trait Implementations§

Source§

impl Debug for Logger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

§DEBUG representation for Logger
Source§

impl Default for Logger

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Logger

§

impl RefUnwindSafe for Logger

§

impl Send for Logger

§

impl Sync for Logger

§

impl Unpin for Logger

§

impl UnwindSafe for Logger

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more