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
impl Config
Sourcepub fn time(self, time: Time) -> Self
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)
Sourcepub fn color(self, color: Color) -> Result<Self, Error>
pub fn color(self, color: Color) -> Result<Self, Error>
This will change the color of a type when it is printed to the console
Sourcepub fn backtrace(self, backtrace: Backtrace) -> Result<Self, Error>
pub fn backtrace(self, backtrace: Backtrace) -> Result<Self, Error>
This will change the backtrace of a type when it is printed to the console
Sourcepub fn console(self, console: Console) -> Result<Self, Error>
pub fn console(self, console: Console) -> Result<Self, Error>
This will set if this type will be printed to the console or not
Sourcepub fn web(self, format: &str, request: Request) -> Result<Self, Error>
Available on crate feature web
only.
pub fn web(self, format: &str, request: Request) -> Result<Self, Error>
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.
Sourcepub fn file(self, file: &str) -> Result<Self, Error>
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.
Sourcepub fn set_type(self, log: Log) -> Result<Self, Error>
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.
Sourcepub fn save(self) -> Result<(), PoisonError<MutexGuard<'static, Config>>>
pub fn save(self) -> Result<(), PoisonError<MutexGuard<'static, Config>>>
This is going to save the configuration.