Releases: rust-cli/env_logger
0.5.6
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.
0.5.5
Key Changes
- Allow toggling parts of the default format without having to write one from scratch
Contributions
More Details
Builder::default_format_*
The default format can be easily tweaked by conditionally enabling/disabling parts of it in the main Builder
. The API looks like:
impl Builder {
fn default_format(&mut self) -> &mut Self;
fn default_format_timestamp(&mut self, write: bool) -> &mut Self;
fn default_format_module_path(&mut self, write: bool) -> &mut Self;
fn default_format_level(&mut self, write: bool) -> &mut Self;
}
Calling default_format_*
will store whether or not we want to include those parts of the log, without affecting a custom format. That means:
Builder::new()
.format(|buf, record| { ... })
.default_format_timestamp(false)
.init();
Is the same as:
Builder::new()
.format(|buf, record| { ... })
.init();
Setting a custom format won't clobber any values passed to default_format_*
methods. That means:
Builder::new()
.default_format_timestamp(false)
.format(|buf, record| { ... })
.default_format()
.init();
Is the same as:
Builder::new()
.default_format_timestamp(false)
.init();
Builder::from_default_env
A new from_default_env
method that's a convenient way of calling from_env(env_logger::Env::default())
.
0.5.4
Key Changes
- Better panic message when attempting to initialise the global logger multiple times
- Use
humantime
instead ofchrono
for formatting timestamps
Changes to minimum Rust
The minimum version of Rust required has been set at 1.18.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.
New Dependencies
humantime
for formatting timestamps. This replaces the dependency onchrono
Contributions
0.5.3
Key Changes
- Support more intense variants of color using intensity. Call
set_intense(true)
to produce a lighter color, andset_intense(false)
to produce the default color.
Contributions
0.5.2
Key Changes
- Detect whether
stdout
/stderr
is a tty and write styles accordingly. This fixes an issue with color control characters showing up logs piped to files
New Dependencies
atty
for interrogatingstdout
/stderr
Contributions
0.5.1
Key Changes
- Fixed a panic in some rare logging cases and updated some incorrect sample code in the readme
Contributions
0.5.0
NOTE: These release notes are collected from the 0.5.0-rc.1
and 0.5.0-rc.2
release notes.
Key Changes
- Support for using custom environment variables to parse the log level filter and color output
- Added colors with configuration through an environment variable and an RFC3339-formatted timestamp to the default format
- Buffer log output so logs over multiple lines won't end up interleaved in multi-threaded applications
- Move the filter parsing into its own module so it's easier to consume in custom loggers
- Documentation!
Breaking Changes
LogTarget
has been renamed toTarget
LogBuilder
has been renamed toBuilder
- The
Builder::format
method now accepts aF: Fn(&mut Formatter, &Record) -> Result<()> + Sync + Send
. This is the new formatting API that writes into aFormatter
instead of producing an ownedString
Builder::init
will panic if the logger can't be initialised. A newBuilder::try_init
method has been added with the same semantics as the oldBuilder::init
method
New Dependencies
Contributions
- @matthiasbeyer Dependencies: log: 0.4.0-rc.1 -> 0.4.0
- @KodrAus Public color API
- @rukai Fix spelling error
- @KodrAus Make the timestamp format more compact
- @mjkillough Allow custom timestamp formats.
- @KodrAus Add rfc3339 timestamps to default format
- @KodrAus Support colors and buffer writes
- @KodrAus Make filtering public
- @FuGangqiang fix doc and reformat code style
- @KodrAus Add examples for custom format and logger impls
- @sfackler Fix std feature name
- @jimmycuadra Adds a new constructor and init functions for custom env vars.
- @jimmycuadra Update to the latest commit of
log
/ deny debug impls, missing docs, and warnings. - @jethrogb Enable use of Logger as a filter
Thanks to everybody who helped make this release of env_logger
happen!
More Details
Disabling colors
Adds a new builder property for whether or not to include colors. By default this is controlled by the RUST_LOG_STYLE
environment variable, but it can be overridden.
Setting this environment variable to never
will disable colors and other styles:
$ export RUST_LOG_STYLE=never
$ ./my-app
Valid values are:
auto
(or missing/invalid) will decide whether or not the terminal supports colorsalways
will always use colorsnever
will never use colors
In order to support multiple environment variables, I've refactored our from_env
functions to accept a generic T: Into<Env>
, where Env
is a container for the environment variables we care about. These methods can now be called in a few ways:
// reads filters from `MY_LOG` and styles from `RUST_LOG_STYLE`
env_logger::init_from_env("MY_LOG");
// reads filters from `MY_LOG` and styles from `MY_LOG_STYLE`
env_logger::init_from_env(Env::default().filter("MY_LOG").write_style("MY_LOG_STYLE"));
This lets us add new environment variables in the future without potentially breaking people. But it does mean if you're overriding all environment variables that new ones could slip in without you noticing.
Using alternative environment variables
Since we use two environment variables to configure the logger we need an ergonomic way to pass different combinations of those variables to from_env
methods. This PR adds an Env
type with builder methods for naming environment variables:
env_logger::init_from_env(Env::new().filter("MY_LOG"));
With a few From
conversions, the above is also equivalent to:
env_logger::init_from_env("MY_LOG");
Whether or not we want to keep these conversions is up for discussion.
Writing colors
The color API has been refactored and made public so you can use them in your own formats:
let mut style = buf.style();
style.set_color(Color::Red).set_bold(true).set_bg(Color::White);
writeln!(buf, "{}", style.value(42))
This saves you from having to split the writes into multiple calls and juggle Result
types.
Writing timestamps
Call the timestamp
method on a Formatter
to get an opaque timestamp that can be logged. It'll be written in an RFC3339 format:
let ts = buf.timestamp();
writeline!(buf, "log at: {}", ts)
0.5.0-rc.2
Key Changes
- Make the color API public
- Tweak the log format to be more aligned
Contributions
- @matthiasbeyer Dependencies: log: 0.4.0-rc.1 -> 0.4.0
- @KodrAus Public color API
- @rukai Fix spelling error
More Details
Disabling colors
Adds a new builder property for whether or not to include colors. By default this is RUST_LOG_STYLE
, but it can be overridden.
Setting this environment variable to never
will disable colors and other styles:
$ export RUST_LOG_STYLE=never
$ ./my-app
Valid values are:
auto
(or missing/invalid) will decide whether or not the terminal supports colorsalways
will always use colorsnever
will never use colors
In order to support multiple environment variables, I've refactored our from_env
functions to accept a generic T: Into<Env>
, where Env
is a container for the environment variables we care about. These methods can now be called in a few ways:
// reads filters from `MY_LOG` and styles from `RUST_LOG_STYLE`
env_logger::init_from_env("MY_LOG");
// reads filters from `MY_LOG` and styles from `MY_LOG_STYLE`
env_logger::init_from_env(Env::default().filter("MY_LOG").write_style("MY_LOG_STYLE"));
This lets us add new environment variables in the future without potentially breaking people. But it does mean if you're overriding all environment variables that new ones could slip in without you noticing.
Using alternative environment variables
Since we use two environment variables to configure the logger we need an ergonomic way to pass different combinations of those variables to from_env
methods. This PR adds an Env
type with builder methods for naming environment variables:
env_logger::init_from_env(Env::new().filter("MY_LOG"));
With a few From
conversions, the above is also equivalent to:
env_logger::init_from_env("MY_LOG");
Whether or not we want to keep these conversions is up for discussion.
Writing colors
The color API has been refactored and made public so you can use them in your own formats:
let mut style = buf.style();
style.set_color(Color::Red).set_bold(true).set_bg(Color::White);
writeln!(buf, "{}", style.value(42))
This saves you from having to split the writes into multiple calls and juggle Result
types.
Writing timestamps
Oh the Formatter.timestamp
method is now also public so you can grab timestamps.
0.5.0-rc.1
Key changes
- Support for using custom environment variables to parse the log level filter
- Added colors and an RFC3339-formatted timestamp to the default format
- Buffer log output so logs over multiple lines won't end up interleaved in multi-threaded applications
- Move the filter parsing into its own module so it's easier to consume in custom loggers
- Documentation!
Breaking changes
LogTarget
has been renamed toTarget
LogBuilder
has been renamed toBuilder
- The
Builder::format
method now accepts aF: Fn(&mut Formatter, &Record) -> Result<()> + Sync + Send
. This is the new formatting API that writes into aFormatter
instead of producing an ownedString
Builder::init
will panic if the logger can't be initialised. A newBuilder::try_init
method has been added with the same semantics as the oldBuilder::init
method
Contributions
- @KodrAus Make the timestamp format more compact
- @mjkillough Allow custom timestamp formats.
- @KodrAus Add rfc3339 timestamps to default format
- @KodrAus Support colors and buffer writes
- @KodrAus Make filtering public
- @FuGangqiang fix doc and reformat code style
- @KodrAus Add examples for custom format and logger impls
- @sfackler Fix std feature name
- @jimmycuadra Adds a new constructor and init functions for custom env vars.
- @jimmycuadra Update to the latest commit of
log
/ deny debug impls, missing docs, and warnings. - @jethrogb Enable use of Logger as a filter
Thanks to everybody who helped make this release of env_logger
happen!