Crate glog[][src]

Expand description

Port of the famous C++ glog logging style framework.

It’s implemented on top of the standard logging crate in Rust.

Default options will be compatible with glog but there are several customizations possible to take advantage of more Rust standard features (currently more levels) and additional configurability options.


Basic usage

use log::*;
use glog::Flags;


info!("A log message");

Pretty logs on stderr

By default glog will write to files once initialized. For colored priniting to stderr you can use these flags:

use log::*;
use glog::Flags;

glog::new().init(Flags {
        colorlogtostderr: true,
        alsologtostderr: true, // use logtostderr to only write to stderr and not to files

info!("This will be visibile on stderr and in a file");
// I0401 12:34:56.987654   123] This will be visibile on stderr and in a file

Nonstandard Glog configuration

glog doesn’t have levels for Trace and Debug. Just like Verbose logs in glog these will be logged as Info by default. As an additional configuration this logging crate offers these levels as different ones as well.

use log::*;
use glog::Flags;

    .reduced_log_levels(false) // Treat DEBUG and TRACE as separate levels
    .with_year(true) // Add the year to the timestamp in the logfile
    .init(Flags {
        minloglevel: Level::Trace, // By default glog will only log INFO and more severe
        logtostderr: true, // don't write to log files

trace!("A trace message");
debug!("Helpful for debugging");
info!("An informational message");

// T20210401 12:34:56.000000  1234] A trace message
// D20210401 12:34:56.000050  1234] Helpful for debugging
// I20210401 12:34:56.000100  1234] An informational message



The flag structure used to initialize glog.


The logging structure doing all the heavy lifting



Create a new Glog instance