From 7b6544bfa17f7ef24a885bb7c3f77d827ef6a901 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Mon, 20 Jan 2020 20:16:34 -0800 Subject: [PATCH] Stub to create filenames based on time and log level. --- Cargo.toml | 4 +- README.md | 14 ++++++- examples/demo.rs | 5 ++- src/lib.rs | 97 ++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 104 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 817e0b2..b9d3273 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,8 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -log = "0.4.8" +log = { version = "0.4.8", features = ["std"] } chrono = "0.4.10" gettid = "0.1.0" +hostname = "0.3.0" +username = "0.2.0" diff --git a/README.md b/README.md index dc752f5..a2a6c7f 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,27 @@ http://github.com/golang/glog and https://github.com/google/glog # TODO - [ ] `-alsologtostderr` -- [ ] `-colorlogtostderr` +- [ ] `-colorlogtostderr` this implies color support. - [ ] `-log_backtrace_at` - [ ] `-log_dir` - [ ] `-logbuflevel` - [ ] `-logbufsecs` - [ ] `-logfile_mode` - [ ] `-logtostderr` -- [ ] `-max_log_size` +- [ ] `-max_log_size` this implies log rotation. - [ ] `-minloglevel` - [ ] `-stderrthreshold` - [ ] `-stop_logging_if_full_disk` - [ ] `-timestamp_in_logfile_name` - [ ] `-v` - [ ] `-vmodule` +- [ ] flush / sync behavior matching Go or C++ implementations. +- [ ] various wrappers for conditional logging (i.e. log_if, sample based). +TODO(wathiede): breakout into subcheckboxes. + +# Not implemented +These are things that seem unnecessary or low priority for the rust version. + +- [ ] raw log mode that doesn't allocate or use locking primitives +- [ ] numeric logging levels, rust offers debug and trace beyond info, and +also target based logging. diff --git a/examples/demo.rs b/examples/demo.rs index 8acad68..7f675a2 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -3,8 +3,8 @@ use std::thread; use glog; -fn main() { - glog::init(); +fn main() -> Result<(), Box> { + glog::init()?; trace!("trace!"); debug!("debug!"); @@ -14,4 +14,5 @@ fn main() { let handle = thread::spawn(|| error!("from a second thread")); handle.join(); + Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index ecbcbb8..af554d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,17 +20,59 @@ //! //! I1103 11:57:31.739339 24395 google.rs:2341] Command line: ./some_prog //! I1103 11:57:31.739403 24395 google.rs:2342] Process id 24395 +//! +//! Unless otherwise specified, glog writes to the filename "/tmp/...log...