Struct session_log::Logger

source ·
pub struct Logger(/* private fields */);

Implementations§

source§

impl Logger

source

pub fn new(name: impl Into<String>) -> Logger

Create a new logging entry with the given name. Level and directory is defaulted to Info and “logs”
OR
Retrieve an existing logging entry if the entry already exists.

You can chain the configuration methods to set the level and directory.

§Parameters
  • name - The name of the logging entry.
§Examples
use session_log::Logger;

fn main() {
  let logger  = Logger::new("main");
  let logger2 = Logger::new("main"); // Retrieve the existing logger

  let logger3 = Logger::new("main")
    .set_log_level(session_log::Level::Debug);
    .set_directory("logs/main");
}
source

pub fn set_default_directory(directory: impl Into<String>)

Set the default logging directory for all new logging entries. The directory will be created if it doesn’t exist. Old loggers will not be affected by this change.

The default directory is ./logs.

source

pub fn get_default_directory() -> String

Get the default logging directory for all new logging entries.

source

pub fn set_default_write_level(level: Level)

Set the default writing level for all new writing entries. Old loggers will not be affected by this change.

The default writing level is Verbose.

source

pub fn get_default_write_level() -> Level

Get the default writing level for all new writing entries.

source

pub fn set_default_log_level(level: Level)

Set the default logging level for all new logging entries. Old loggers will not be affected by this change.

The default logging level is Info.

source

pub fn get_default_log_level() -> Level

Get the default logging level for all new logging entries.

source

pub fn set_default_processor(proc: fn(_: &Context<'_>) -> (String, String))

Set the default processor for all new logging entries. Old loggers will not be affected by this change.

The default processor is $crate::context::processor.

source

pub fn get_default_processor() -> fn(_: &Context<'_>) -> (String, String)

Get the default processor for all new logging entries.

source

pub fn set_auto_directory(auto: bool)

Set the if the logger should automatically set the directory based on the current application name. Once set, the directory option will no longer take effect.

source

pub fn get_auto_directory() -> bool

Get the if the logger should automatically set the directory based on the current application name.

source

pub fn get_write_level(&self) -> Level

Get writing level for this entry.

§Examples
use session_log::{Logger, Level};

fn main() {
  let logger = Logger::new("main");

  assert_eq!(logger.get_write_level(), Level::Info);
}
source

pub fn set_write_level(self, level: Level) -> Self

Set writing level for this entry

§Examples
use session_log::{Logger, Level};

fn main() {
  let mut logger = Logger::new("main");

  logger = logger.set_write_level(Level::Debug);
  assert_eq!(logger.get_write_level(), Level::Debug);

  logger = logger.set_write_level(Level::Info);
  assert_eq!(logger.get_write_level(), Level::Info);
}
source

pub fn get_log_level(&self) -> Level

Get logging level for this entry.

§Examples
use session_log::{Logger, Level};

fn main() {
  let logger = Logger::new("main");

  assert_eq!(logger.get_log_level(), Level::Info);
}
source

pub fn set_log_level(self, level: Level) -> Self

Set logging level for this entry

§Examples
use session_log::{Logger, Level};

fn main() {
  let mut logger = Logger::new("main");

  logger = logger.set_log_level(Level::Debug);
  assert_eq!(logger.get_log_level(), Level::Debug);

  logger = logger.set_log_level(Level::Info);
  assert_eq!(logger.get_log_level(), Level::Info);
}
source

pub fn get_directory(&self) -> String

Get logging directory for this entry.

§Examples
use session_log::Logger;

fn main() {
  let logger = Logger::new("main");

  assert_eq!(logger.get_directory(), "logs");
}
source

pub fn set_directory(self, directory: impl Into<String>) -> Self

Set logging directory for this entry and create the directory if it doesn’t exist. the result of creating the directory is returned.

§Examples
use session_log::Logger;

fn main() {
  let mut logger = Logger::new("main");

  logger = logger.set_directory("logs/main");
  assert_eq!(logger.get_directory(), "logs/main");

  logger = logger.set_directory("logs/other");
  assert_eq!(logger.get_directory(), "logs/other");
}
source

pub fn set_processor( self, proc: fn(_: &Context<'_>) -> (String, String), ) -> Self

Set the processor for this entry.

§Examples
use session_log::Logger;

fn main() {
  let logger = Logger::new("main")
    .set_proc(|ctx| (
      // The console will always print "Hello"
      "Hello".to_string(),
      // The file will always write "World"
      "World".to_string()
    ));
}

Trait Implementations§

source§

impl Clone for Logger

source§

fn clone(&self) -> Logger

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Logger

source§

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

Formats the value using the given formatter. Read more
source§

impl Loggable for Logger

source§

fn log(&self, ctx: Context<'_>)

Log a message with the dynamic level.
source§

fn session(&self, name: impl Into<String>) -> Session

Create a new session with the given name.
source§

fn get_name(&self) -> &str

Get the name of the current loggable.
source§

fn get_logger_name(&self) -> &str

Get the current logging entry name.
source§

fn get_logger(&self) -> Logger

Get the logger of the current loggable.
source§

fn get_session(&self) -> Option<&str>

Get the current session name.
source§

fn get_log_level(&self) -> Level

Get the log level of current loggable.
source§

fn get_write_level(&self) -> Level

Get the write level of current loggable.
source§

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>)

Log a message at the verbose level with caller position.
source§

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>)

Log a message at the warning level with caller position.
source§

fn critical(&self, message: impl Into<String>)

Log a message at the critical level with caller position.
source§

fn error(&self, message: impl Into<String>)

Log a message at the error level with caller position.
source§

fn fatal(&self, message: impl Into<String>) -> !

Log a message at the fatal level with caller position then panic. 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, 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.