Skip to main content

Logger

Struct Logger 

Source
pub struct Logger {
    pub mode: PRINTMODE,
    /* private fields */
}
Expand description

this is the tklog encapsulated Logger whose File operations are based on the standard library std::fs::File,therefore, it is a bio sync operation object. Logger allows you to set parameters for log printing of tklog.

§Examples

Create a Logger Object and set the parameters:

use tklog::sync::Logger;
use tklog::Format;
use tklog::LEVEL;
use tklog::MODE;

let mut log = Logger::new();
log.set_console(true)
    .set_level(LEVEL::Debug)
    .set_format(Format::LevelFlag | Format::Time | Format::ShortFileName)
    .set_formatter("{level}{time} {file}:{message}\n")
    .set_cutmode_by_size("tklog.log", 1<<20, 0, true);

Fields§

§mode: PRINTMODE

Implementations§

Source§

impl Logger

Source

pub fn new() -> Self

Source

pub fn print(&mut self, level: LEVEL, module: &str, message: &str)

Source

pub fn safeprint(&mut self, level: LEVEL, module: &str, message: &str)

Source

pub fn log(&self, level: LEVEL, module: String, message: String)

Source

pub fn get_level(&mut self, module: &str) -> LEVEL

Source

pub fn is_file_line(&mut self, level: LEVEL, module: &str) -> bool

Source

pub fn fmt( &mut self, module: &str, level: LEVEL, filename: &str, line: u32, message: String, ) -> String

Source

pub fn set_printmode(&mut self, mode: PRINTMODE) -> &mut Self

Source

pub fn set_level(&mut self, level: LEVEL) -> &mut Self

Source

pub fn set_console(&mut self, console: bool) -> &mut Self

Source

pub fn set_format(&mut self, format: u8) -> &mut Self

Format::LevelFlag | Format::Date | Format::Time | Format::ShortFileName;

Source

pub fn set_formatter(&mut self, formatter: &str) -> &mut Self

default: “{level}{time} {file}:{message}\n”

Source

pub fn set_cutmode_by_size( &mut self, filename: &str, maxsize: u64, maxbackups: u32, compress: bool, ) -> &mut Self

Source

pub fn set_cutmode_by_time( &mut self, filename: &str, mode: MODE, maxbackups: u32, compress: bool, ) -> &mut Self

Source

pub fn set_cutmode_by_mixed( &mut self, filename: &str, maxsize: u64, mode: MODE, maxbackups: u32, compress: bool, ) -> &mut Self

Source

pub fn set_option(&mut self, option: LogOption) -> &mut Self

Source

pub fn set_mod_option(&mut self, module: &str, option: LogOption) -> &mut Self

Source

pub fn set_custom_handler( &mut self, handler: fn(&LogContext) -> bool, ) -> &mut Self

Source

pub fn set_level_option( &mut self, level: LEVEL, option: &dyn OptionTrait, ) -> &mut Self

Source

pub fn set_separator(&mut self, separator: &str) -> &mut Self

Source

pub fn get_separator(&self) -> String

Source

pub fn set_attr_format<F>(&mut self, f: F)
where F: FnMut(&mut AttrFormat) + Send + Sync + 'static,

Auto Trait Implementations§

§

impl !Freeze for Logger

§

impl !RefUnwindSafe for Logger

§

impl !UnwindSafe for Logger

§

impl Send for Logger

§

impl Sync for Logger

§

impl Unpin for Logger

§

impl UnsafeUnpin 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, 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.