Skip to content

Commit

Permalink
Rework the default format (#82)
Browse files Browse the repository at this point in the history
* adjust the default format

* remove FromStr impl for Color

* note the stability of default format

* make shim termcolor cargo test friendly

* catch attempts to re-use builders
  • Loading branch information
KodrAus committed Nov 4, 2018
1 parent 15ed5c7 commit d4a1434
Show file tree
Hide file tree
Showing 12 changed files with 564 additions and 507 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Expand Up @@ -13,9 +13,6 @@ variable.
categories = ["development-tools::debugging"]
keywords = ["logging", "log", "logger"]

[maintenance]
status = "actively-developed"

[workspace]
members = [
"ci"
Expand All @@ -37,4 +34,4 @@ name = "log-in-log"
harness = false

[features]
default = ["termcolor", "atty", "humantime", "regex"]
default = ["termcolor", "atty", "humantime", "regex"]
22 changes: 14 additions & 8 deletions README.md
Expand Up @@ -40,7 +40,7 @@ environment variable that corresponds with the log messages you want to show.

```bash
$ RUST_LOG=info ./main
INFO: 2017-11-09T02:12:24Z: main: starting up
[2018-11-03T06:09:06Z INFO default] starting up
```

### In tests
Expand All @@ -52,7 +52,7 @@ Tests can use the `env_logger` crate to see log messages generated during that t
log = "0.4.0"

[dev-dependencies]
env_logger = "0.5.13"
env_logger = { version = "0.5.13", default-features = false }
```

```rust
Expand Down Expand Up @@ -93,11 +93,11 @@ $ RUST_LOG=my_lib=info cargo test
Running target/debug/my_lib-...

running 2 tests
INFO: 2017-11-09T02:12:24Z: my_lib::tests: logging from another test
INFO: 2017-11-09T02:12:24Z: my_lib: add_one called with -8
[2017-11-09T02:12:24Z INFO my_lib::tests] logging from another test
[2017-11-09T02:12:24Z INFO my_lib] add_one called with -8
test tests::it_handles_negative_numbers ... ok
INFO: 2017-11-09T02:12:24Z: my_lib::tests: can log from the test too
INFO: 2017-11-09T02:12:24Z: my_lib: add_one called with 2
[2017-11-09T02:12:24Z INFO my_lib::tests] can log from the test too
[2017-11-09T02:12:24Z INFO my_lib] add_one called with 2
test tests::it_adds_one ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured
Expand All @@ -115,8 +115,8 @@ $ RUST_LOG=my_lib=info cargo test it_adds_one
Running target/debug/my_lib-...

running 1 test
INFO: 2017-11-09T02:12:24Z: my_lib::tests: can log from the test too
INFO: 2017-11-09T02:12:24Z: my_lib: add_one called with 2
[2017-11-09T02:12:24Z INFO my_lib::tests] can log from the test too
[2017-11-09T02:12:24Z INFO my_lib] add_one called with 2
test tests::it_adds_one ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
Expand All @@ -138,3 +138,9 @@ if env::var("RUST_LOG").is_ok() {
}
builder.init();
```

## Stability of the default format

The default format won't optimise for long-term stability, and explicitly makes no guarantees about the stability of its output across major, minor or patch version bumps during `0.x`.

If you want to capture or interpret the output of `env_logger` programmatically then you should use a custom format.
2 changes: 1 addition & 1 deletion src/fmt/humantime/extern_impl.rs
Expand Up @@ -5,7 +5,7 @@ use humantime::{format_rfc3339_nanos, format_rfc3339_seconds};

use ::fmt::Formatter;

pub(in ::fmt) mod pub_use_in_super {
pub(in ::fmt) mod glob {
pub use super::*;
}

Expand Down
2 changes: 1 addition & 1 deletion src/fmt/humantime/shim_impl.rs
Expand Up @@ -2,6 +2,6 @@
Timestamps aren't available when we don't have a `humantime` dependency.
*/

pub(in ::fmt) mod pub_use_in_super {
pub(in ::fmt) mod glob {

}

0 comments on commit d4a1434

Please sign in to comment.