Skip to content

Releases: rust-cli/env_logger

0.6.1

07 Mar 03:55
2ae080e
Compare
Choose a tag to compare

Key Changes

  • Support better capturing for cargo test
  • Don't print internal logs to stdout

Contributions

More Details

Builder::is_test

The is_test method can be used in tests to make sure logs are captured by cargo test the same way println! is:

fn init() {
    let _ = env_logger::builder().is_test(true).try_init();
}

#[test]
fn it_adds_one() {
    init();

    info!("can log from the test too");
    assert_eq!(3, add_one(2));
}

There are performance implications of using is_test though, so it should be avoided outside of unit tests.

0.6.0

11 Nov 23:57
ebf4829
Compare
Choose a tag to compare

Key Changes

  • Set a policy for changes to the default format
  • Make all dependencies besides log optional (but enabled by default)

Breaking Changes

  • The default format is not considered stable across patch versions. The best way to get a stable format for later ripgrepping is to define a custom one.
  • All dependencies have been made optional except for log. That means compiling env_logger with default-features=false will result in a different experience than in 0.5.x.

Contributions

More Details

Disabling dependencies

Using default-features=false will disable all dependencies of env_logger besides log. This will reduce compile times and alter the default format by disabling colours and timestamps.

Disabling default dependencies is the recommended way to use env_logger for libraries that only need it for logging in tests.

0.5.13

26 Aug 22:17
6b1b619
Compare
Choose a tag to compare

Key Changes

  • Add a public function for getting the default level style

Contributions

More Details

Formatter::default_level_style

The style used in the default format for printing level names can be fetched using the new default_level_style method on a Formatter. The below example will format just the record message using the style of its level:

builder.format(|buf, record| {
    let level_style = buf.default_level_style(level);
    write!(buf, "{} ", level_style.value(record.args()))
});

0.5.12

04 Aug 00:08
5407365
Compare
Choose a tag to compare

Key Changes

  • Add support for high-precision timestamps

Contributions

More Details

Builder::default_format_timestamp_nanos

The Builder::default_format_timestamp_nanos method can be used to toggle the precision of timestamps in the default format. When set to true, timestamps will include a 6-digit nanosecond component like 2018-02-14T00:28:07.000000000Z.

Formatter::precise_timestamp

Custom formats can get a precise timestamp instead of the default by calling the precise_timestamp method instead of the existing timestamp one.

0.5.11

23 Jul 22:11
211d566
Compare
Choose a tag to compare

Key Changes

  • Update termcolor to 1.0
  • Bump minimum rustc to 1.20.0

Changes to minimum Rust

The minimum version of Rust required has been set at 1.20.0. We may change this in patch versions, but will always flag it in the release notes here.

You can always check the .travis.yml file to see the current minimum supported version.

Contributions

0.5.10

05 May 01:13
4e39b74
Compare
Choose a tag to compare

Key Changes

  • Update regex to 1.0.

Contributions

0.5.9

21 Apr 10:09
6b672d8
Compare
Choose a tag to compare

Key Changes

  • Add some convenient methods for adding filter directives

Contributions

More Details

filter_module and filter_level

Adds two new methods to Builder and filter::Builder that are specific cases of the existing filter method:

  • filter_module adds a directive for the given module. It's the same as filter(Some(module), level)
  • filter_level adds a directive for all modules. It's the same as filter(None, level)

0.5.8

18 Apr 03:15
afd147a
Compare
Choose a tag to compare

Key Changes

  • Support setting default values for environment variables before initialising a logger

Contributions

More Details

Env::filter_or and Env::write_style_or

Default values for environment variables can be specified on the Env type using the filter_or and write_style_or methods. The default value is a string in the same format as the environment variable:

impl Env {
    fn filter_or<E, V>(self, filter_env: E, default: V) -> Self
    where
        E: Into<Cow<'a, str>>,
        V: Into<Cow<'a, str>>;

    fn write_style_or<E, V>(self, write_style_env: E, default: V) -> Self
        where
            E: Into<Cow<'a, str>>,
            V: Into<Cow<'a, str>>;
}

In usage:

let env = Env::default()
    .filter_or("MY_LOG_LEVEL", "trace")
    .write_style_or("MY_LOG_STYLE", "always");

env_logger::init_from_env(env);

DEFAULT_FILTER_ENV and DEFAULT_WRITE_STYLE_ENV

Two new constants are publicly exported that correspond to the default environment variable names used for the filters and style preferences.

0.5.7

11 Apr 23:25
b43890a
Compare
Choose a tag to compare

0.5.6

18 Mar 01:55
a3e25b3
Compare
Choose a tag to compare

Key Changes

  • Wrap the termcolor::Color API so it's no longer a public dependency

Contributions

More Details

This patch fixes an issue that slipped through 0.5.0 where the termcolor::Color type was re-exported instead of redefined.

This is a potentially breaking change

Instead of re-exporting termcolor::Color, we now redefine the same API in env_logger. The potential breakage is if anyone was relying on the fact that env_logger::Color and termcolor::Color were equivalent types. This was only obvious from the source, and a survey of public code using env_logger and call for comment hasn't revealed any code relying on this.