Struct Glog

Source
pub struct Glog { /* private fields */ }
Expand description

The logging structure doing all the heavy lifting

Implementations§

Source§

impl Glog

Source

pub fn new() -> Glog

Create a new Glog object for logging

Source

pub fn init(&mut self, flags: Flags) -> Result<(), SetLoggerError>

Initialize the logging object and register it with the standard logging frontend

§Example
use log::*;
use glog::Flags;

glog::new().init(Flags::default()).unwrap();

info!("A log message");
Examples found in repository?
examples/main.rs (lines 28-34)
23fn main() {
24    glog::new()
25        .with_year(true)
26        .reduced_log_levels(true)
27        .set_application_fingerprint("Example")
28        .init(Flags {
29            colorlogtostderr: true,
30            minloglevel: Level::Trace,
31            log_backtrace_at: Some("main.rs:20".to_owned()),
32            alsologtostderr: true,
33            ..Default::default()
34        })
35        .unwrap();
36
37    error!("some erro in main while testing the logger");
38
39    foo();
40
41    info!(
42        "{:?}",
43        Flags {
44            ..Default::default()
45        }
46    );
47}
Source

pub fn with_year(self, with_year: bool) -> Self

Enable the year in the log timestamp

By default the year is not part of the timestamp.

§Examples
use log::*;
use glog::Flags;

// init of glog happens here in examples

info!("A log message");
§With year
glog::new().with_year(true).init(Flags::default()).unwrap();
// Will log:
// I20210401 12:34:56.987654   123 doc.rs:4] A log message
§Without year
glog::new().with_year(false).init(Flags::default()).unwrap();
// Will log:
// I0401 12:34:56.987654   123 doc.rs:4] A log message
Examples found in repository?
examples/main.rs (line 25)
23fn main() {
24    glog::new()
25        .with_year(true)
26        .reduced_log_levels(true)
27        .set_application_fingerprint("Example")
28        .init(Flags {
29            colorlogtostderr: true,
30            minloglevel: Level::Trace,
31            log_backtrace_at: Some("main.rs:20".to_owned()),
32            alsologtostderr: true,
33            ..Default::default()
34        })
35        .unwrap();
36
37    error!("some erro in main while testing the logger");
38
39    foo();
40
41    info!(
42        "{:?}",
43        Flags {
44            ..Default::default()
45        }
46    );
47}
Source

pub fn reduced_log_levels(self, limit_abbreviations: bool) -> Self

Change the behavior regarding Trace and Debug levels

If limit_abbreviations is set to false Trace and Debug get their own levels. Otherwise they will be logged in the Info level.

By default reduced_log_levels is true.

§Examples
use log::*;
use glog::Flags;

// glog init happens here

trace!("A trace message");
debug!("Helpful for debugging");
info!("An informational message");
§With all abbreviations
glog::new()
    .reduced_log_levels(false) // Treat DEBUG and TRACE as separate levels
    .init(Flags {
        minloglevel: Level::Trace, // By default glog will only log INFO and more severe
        logtostderr: true, // don't write to log files
        ..Default::default()
    }).unwrap();

// T0401 12:34:56.000000  1234 doc.rs:12] A trace message
// D0401 12:34:56.000050  1234 doc.rs:13] Helpful for debugging
// I0401 12:34:56.000100  1234 doc.rs:14] An informational message
§With limited abbreviations
glog::new()
    .reduced_log_levels(true) // Treat DEBUG and TRACE are now logged as INFO
    .init(Flags {
        minloglevel: Level::Trace, // By default glog will only log INFO and more severe
        logtostderr: true, // don't write to log files
        ..Default::default()
    }).unwrap();

// I0401 12:34:56.000000  1234 doc.rs:12] A trace message
// I0401 12:34:56.000050  1234 doc.rs:13] Helpful for debugging
// I0401 12:34:56.000100  1234 doc.rs:14] An informational message
Examples found in repository?
examples/main.rs (line 26)
23fn main() {
24    glog::new()
25        .with_year(true)
26        .reduced_log_levels(true)
27        .set_application_fingerprint("Example")
28        .init(Flags {
29            colorlogtostderr: true,
30            minloglevel: Level::Trace,
31            log_backtrace_at: Some("main.rs:20".to_owned()),
32            alsologtostderr: true,
33            ..Default::default()
34        })
35        .unwrap();
36
37    error!("some erro in main while testing the logger");
38
39    foo();
40
41    info!(
42        "{:?}",
43        Flags {
44            ..Default::default()
45        }
46    );
47}
Source

pub fn set_application_fingerprint(self, fingerprint: &str) -> Self

Set fingerprint as the application fingerprint in the log file header

Examples found in repository?
examples/main.rs (line 27)
23fn main() {
24    glog::new()
25        .with_year(true)
26        .reduced_log_levels(true)
27        .set_application_fingerprint("Example")
28        .init(Flags {
29            colorlogtostderr: true,
30            minloglevel: Level::Trace,
31            log_backtrace_at: Some("main.rs:20".to_owned()),
32            alsologtostderr: true,
33            ..Default::default()
34        })
35        .unwrap();
36
37    error!("some erro in main while testing the logger");
38
39    foo();
40
41    info!(
42        "{:?}",
43        Flags {
44            ..Default::default()
45        }
46    );
47}

Trait Implementations§

Source§

impl Clone for Glog

Source§

fn clone(&self) -> Glog

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 Default for Glog

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Log for Glog

Source§

fn enabled(&self, metadata: &Metadata<'_>) -> bool

Determines if a log message with the specified metadata would be logged. Read more
Source§

fn log(&self, record: &Record<'_>)

Logs the Record. Read more
Source§

fn flush(&self)

Flushes any buffered records.

Auto Trait Implementations§

§

impl !Freeze for Glog

§

impl !RefUnwindSafe for Glog

§

impl Send for Glog

§

impl Sync for Glog

§

impl Unpin for Glog

§

impl UnwindSafe for Glog

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.