Struct session_log::Session
source · pub struct Session { /* private fields */ }Expand description
Sessions are a way to group log messages together. They are useful for tracking the flow of a program. They can be nested, and when a session is dropped, it will dump all of its messages to the file at once. Despite the file being written to at once, the messages are still written in the traditional order on the terminal. It can also be used as a simple profiling tool, as it will track the starting time of the session and the elapsed time when it is dropped.
§Example
use session_log::{Logger, Loggable};
fn main() {
let logger = Logger::new("main");
foo(logger.session("foo"), 10);
bar(logger.session("bar"), 10);
}
fn foo(logger: impl Loggable, n: usize) {
for i in 0..n {
logger.info(&format!("message-{}", i));
}
}
fn bar(logger: impl Loggable, n: usize) {
for i in 0..n {
logger.warning(&format!("message-{}", i));
}
}Implementations§
Trait Implementations§
source§impl Loggable for Session
impl Loggable for Session
source§fn session(&self, name: impl Into<String>) -> Session
fn session(&self, name: impl Into<String>) -> Session
Create a new session with the given name.
source§fn get_logger_name(&self) -> &str
fn get_logger_name(&self) -> &str
Get the current logging entry name.
source§fn get_logger(&self) -> Logger
fn get_logger(&self) -> Logger
Get the logger of the current loggable.
source§fn get_session(&self) -> Option<&str>
fn get_session(&self) -> Option<&str>
Get the current session name.
source§fn get_log_level(&self) -> Level
fn get_log_level(&self) -> Level
Get the log level of current loggable.
source§fn get_write_level(&self) -> Level
fn get_write_level(&self) -> Level
Get the write level of current loggable.
source§fn debug(&self, message: impl Into<String>)
fn debug(&self, message: impl Into<String>)
Log a message at the debug level with caller position.
source§fn verbose(&self, message: impl Into<String>)
fn verbose(&self, message: impl Into<String>)
Log a message at the verbose level with caller position.
source§fn info(&self, message: impl Into<String>)
fn info(&self, message: impl Into<String>)
Log a message at the info level with caller position.
source§fn warning(&self, message: impl Into<String>)
fn warning(&self, message: impl Into<String>)
Log a message at the warning level with caller position.
source§fn critical(&self, message: impl Into<String>)
fn critical(&self, message: impl Into<String>)
Log a message at the critical level with caller position.
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more