Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ version = "0.1.0"
authors = ["Christoph Schlosser <[email protected]>"]
edition = "2018"
license = "BSD-3-Clause"
description = "glog style standard logging backend"
description = "glog style logging backend"
homepage = "https://crates.io/crates/glog"
repository = "https://github.com/cschlosser/glog-rs"
readme = "README.md"
keywords = ["glog", "log", "logging", "backend"]
keywords = ["glog", "log", "logging backend"]
documentation = "https://docs.rs/glog/0.1.0/"

[dependencies]
Expand All @@ -21,6 +21,7 @@ gethostname = "0.2.1"
whoami = "1.1.2"
if_empty = "0.2.0"
bimap = "0.6.1"
once_cell = "1.8.0"

[target.'cfg(windows)'.dependencies]
windows = "0.11.0"
Expand Down
28 changes: 13 additions & 15 deletions examples/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::thread;

use glog::Flags;
use glog::{fatal, Extensions, Flags};
use log::*;

pub fn foo() {
Expand All @@ -21,27 +21,25 @@ pub fn foo() {
}

fn main() {
glog::new()
.with_year(true)
.reduced_log_levels(true)
.set_application_fingerprint("Example")
.init(Flags {
glog::init(
Flags {
colorlogtostderr: true,
minloglevel: Level::Trace,
log_backtrace_at: Some("main.rs:20".to_owned()),
alsologtostderr: true,
..Default::default()
})
.unwrap();
},
Some("example application".to_string()),
Some(Extensions {
with_year: true,
..Default::default()
}),
)
.unwrap();

error!("some erro in main while testing the logger");
error!("some error in main while testing the logger");

foo();

info!(
"{:?}",
Flags {
..Default::default()
}
);
fatal!("This will stop the application");
}
104 changes: 104 additions & 0 deletions src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,107 @@ impl Default for Flags {
}
}
}

pub struct Extensions {
/// 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
/// ```
/// # use log::*;
/// # use glog::Flags;
/// 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
/// ```
/// # use log::*;
/// # use glog::Flags;
/// glog::new().with_year(false).init(Flags::default()).unwrap();
/// // Will log:
/// // I0401 12:34:56.987654 123 doc.rs:4] A log message
/// ```
pub with_year: bool,
/// [`Trace`]: ../log/enum.Level.html#variant.Trace
/// [`Debug`]: ../log/enum.Level.html#variant.Debug
/// [`Info`]: ../log/enum.Level.html#variant.Info
/// 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
///
/// ```
/// # use log::*;
/// # use glog::Flags;
/// 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
///
/// ```
/// # use log::*;
/// # use glog::Flags;
/// 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
/// ```
pub with_rust_levels: bool,
}

impl Default for Extensions {
fn default() -> Self {
Extensions {
with_year: false,
with_rust_levels: false,
}
}
}
Loading