Struct fast_logger::LoggerV2Async
source · pub struct LoggerV2Async<C: Display + Send> { /* private fields */ }
Expand description
The fastest logger in the west
A very simple logger that uses a custom structure and a logging level. No further assumptions are made about the structure or nature of the logging message, thus making it extremely cheap to send messages to the logger thread.
Implementations§
source§impl<C: 'static + Display + Send> LoggerV2Async<C>
impl<C: 'static + Display + Send> LoggerV2Async<C>
sourcepub fn spawn(ctx: &'static str) -> Logger<C>
pub fn spawn(ctx: &'static str) -> Logger<C>
Create a logger object and spawn a logging thread
The logger object is the interface to write stuff to the logger thread. The logger thread is in the background, waiting for messages to print out. Once all logger objects are dropped, the thread will die.
Typically, you only call spawn
once in an application
since you just want a single logging thread to print stuff.
sourcepub fn spawn_with_writer<T: 'static + Write + Send>(
ctx: &'static str,
writer: T
) -> Logger<C>
pub fn spawn_with_writer<T: 'static + Write + Send>( ctx: &'static str, writer: T ) -> Logger<C>
Create a logger object with a specific writer
See spawn
for more information regarding spawning. This function providing the logger a
writer, which makes the logger use any arbitrary writing interface.
sourcepub fn spawn_void() -> Logger<C>
pub fn spawn_void() -> Logger<C>
Spawn a logger that doesn’t output anything
This logger automatically sets the log level to 0, if you set the log level to something other than that the message will be sent, but it will be completely ignored.
sourcepub fn spawn_test() -> Logger<C>
pub fn spawn_test() -> Logger<C>
Create a logger object for tests
Similar to spawn
but sets the log level to 255 and enables colored output,
logs to stderr
.
sourcepub fn clone_with_context(&self, ctx: &'static str) -> Self
pub fn clone_with_context(&self, ctx: &'static str) -> Self
Clone the logger but change the context of the clone
sourcepub fn clone_add_context(&self, ctx: &'static str) -> Self
pub fn clone_add_context(&self, ctx: &'static str) -> Self
Clone the logger but append the context of the clone
sourcepub fn set_log_level(&self, level: u8)
pub fn set_log_level(&self, level: u8)
The log-level is an 8-bit variable that is shared among all clones of this logger. When we try logging we first check if our message has a priority higher or equal to this level. If it doesn’t we just exit the logger function.
Internally, we use an atomic variable to store the logging level so all threads can check it quickly. This makes log statements that won’t trigger because of the log-level absolutely fucking NUTS (so cheap it’s basically non-existent).
sourcepub fn get_log_level(&self) -> u8
pub fn get_log_level(&self) -> u8
Retrieve the current global log level value
sourcepub fn set_context_specific_log_level(&self, ctx: &str, level: u8) -> bool
pub fn set_context_specific_log_level(&self, ctx: &str, level: u8) -> bool
Sets the log level for a specific context
Whenever the logger receives a message, it will use the context-to-level mapping to see if the message should be logged or not. Note that this happens after checking the global log level.
sourcepub fn set_this_log_level(&self, level: u8)
pub fn set_this_log_level(&self, level: u8)
Set the log level of this logger’s associated context
sourcepub fn set_colorize(&self, on: bool)
pub fn set_colorize(&self, on: bool)
Enable colorizing log output
sourcepub fn get_colorize(&self) -> bool
pub fn get_colorize(&self) -> bool
Check the current colorization status
source§impl<C: 'static + Display + Send> LoggerV2Async<C>
impl<C: 'static + Display + Send> LoggerV2Async<C>
Trait Implementations§
source§impl<C: Clone + Display + Send> Clone for LoggerV2Async<C>
impl<C: Clone + Display + Send> Clone for LoggerV2Async<C>
source§fn clone(&self) -> LoggerV2Async<C>
fn clone(&self) -> LoggerV2Async<C>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more