pub struct Glog { /* private fields */ }
Expand description
The logging structure doing all the heavy lifting
Implementations§
Source§impl Glog
impl Glog
Sourcepub fn init(&mut self, flags: Flags) -> Result<(), SetLoggerError>
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}
Sourcepub fn with_year(self, with_year: bool) -> Self
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}
Sourcepub fn reduced_log_levels(self, limit_abbreviations: bool) -> Self
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}
Sourcepub fn set_application_fingerprint(self, fingerprint: &str) -> Self
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§
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> 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