Struct Config

Source
pub struct Config { /* private fields */ }
Expand description

To configure the logger you will use some different functions.
This is how the default configuration would look if written out:

log4rust::new()
    .time(Time::Local)
    .set_type(Log::Info)?
        .color(Color::TrueColor{r:0,g:255,b:255})?
        .console(Console::Stdout)?
        .backtrace(Backtrace::_None)?
    .set_type(Log::Warn)?
        .color(Color::TrueColor{r:255,g:215,b:185})?
        .console(Console::Stderr)?
        .backtrace(Backtrace::_None)?
    .set_type(Log::Error)?
        .color(Color::TrueColor{r:255,g:100,b:0})?
        .console(Console::Stderr)?
        .backtrace(Backtrace::Simple)?
    .set_type(Log::Fatal)?
        .color(Color::TrueColor{r:255,g:0,b:0})?
        .console(Console::Stderr)?
        .backtrace(Backtrace::Complex)?
    .save()
    .unwrap();

If you wanted to change something from the norm you could do

log4rust::new()
   .time(Time::UTC)
   .set_type(Log::Info)?.console(Console::_None)?
   .save()
   .unwrap();

You can see that we only change one of the items and all the rest are the same. We also change it so that time will be saved in UTC and not in local time.

If you want to see some other examples look in https://github.com/AMTitan/log4rust/tree/master/examples

Implementations§

Source§

impl Config

Source

pub fn time(self, time: Time) -> Self

This will change the type of time that will be saved (This will save it globally and not on a type by type basis)

Source

pub fn color(self, color: Color) -> Result<Self, Error>

This will change the color of a type when it is printed to the console

Source

pub fn backtrace(self, backtrace: Backtrace) -> Result<Self, Error>

This will change the backtrace of a type when it is printed to the console

Source

pub fn console(self, console: Console) -> Result<Self, Error>

This will set if this type will be printed to the console or not

Source

pub fn web(self, format: &str, request: Request) -> Result<Self, Error>

Available on crate feature web only.

This will make it so that you can make a request every time this type goes off. You can also have multiple of these so it will make multiple requests for every time this type fires. This would be most useful for a webhook.

Source

pub fn file(self, file: &str) -> Result<Self, Error>

This will make it so that every time this type fires it will add it to the end of a file. You can have multiple files that it will be added to.

Source

pub fn set_type(self, log: Log) -> Result<Self, Error>

This will set the currently selected item, this will be used so you can use the other attributes that require a type to be set.

Source

pub fn save(self) -> Result<(), PoisonError<MutexGuard<'static, Config>>>

This is going to save the configuration.

Auto Trait Implementations§

§

impl Freeze for Config

§

impl !RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl !UnwindSafe for Config

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T