diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml new file mode 100644 index 0000000..5a73deb --- /dev/null +++ b/.github/workflows/post-release.yml @@ -0,0 +1,42 @@ +name: post-release +on: + push: + tags: + - "v*" +permissions: + contents: read + +jobs: + create-release: + permissions: + contents: write # for actions/create-release to create a release + name: create-release + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.release.outputs.upload_url }} + release_version: ${{ env.RELEASE_VERSION }} + steps: + - name: Get the release version from the tag + shell: bash + if: env.RELEASE_VERSION == '' + run: | + # See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 + echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + echo "version is: ${{ env.RELEASE_VERSION }}" + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Generate Release Notes + run: | + ./.github/workflows/release-notes.py --tag ${{ env.RELEASE_VERSION }} --output notes-${{ env.RELEASE_VERSION }}.md + cat notes-${{ env.RELEASE_VERSION }}.md + - name: Create GitHub release + id: release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.RELEASE_VERSION }} + release_name: ${{ env.RELEASE_VERSION }} + body_path: notes-${{ env.RELEASE_VERSION }}.md diff --git a/.github/workflows/release-notes.py b/.github/workflows/release-notes.py new file mode 100755 index 0000000..7a0d26d --- /dev/null +++ b/.github/workflows/release-notes.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import argparse +import re +import pathlib +import sys + + +_STDIO = pathlib.Path("-") + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-i", "--input", type=pathlib.Path, default="CHANGELOG.md") + parser.add_argument("--tag", required=True) + parser.add_argument("-o", "--output", type=pathlib.Path, required=True) + args = parser.parse_args() + + if args.input == _STDIO: + lines = sys.stdin.readlines() + else: + with args.input.open() as fh: + lines = fh.readlines() + version = args.tag.lstrip("v") + + note_lines = [] + for line in lines: + if line.startswith("## ") and version in line: + note_lines.append(line) + elif note_lines and line.startswith("## "): + break + elif note_lines: + note_lines.append(line) + + notes = "".join(note_lines).strip() + if args.output == _STDIO: + print(notes) + else: + args.output.write_text(notes) + + +if __name__ == "__main__": + main() diff --git a/CHANGELOG.md b/CHANGELOG.md index c6b4ef7..8d1be3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +## [0.11.2] - 2024-02-13 + ## [0.11.1] - 2024-01-27 ### Fixes @@ -15,6 +17,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [0.11.0] - 2024-01-19 +### Migration Guide + +**env_logger::fmt::Style:** +The bespoke styling API, behind `color`, was removed, in favor of accepting any +ANSI styled string and adapting it to the target stream's capabilities. + +Possible styling libraries include: +- [anstyle](https://docs.rs/anstyle) is a minimal, runtime string styling API and is re-exported as `env_logger::fmt::style` +- [owo-colors](https://docs.rs/owo-colors) is a feature rich runtime string styling API +- [color-print](https://docs.rs/color-print) for feature-rich compile-time styling API + +[custom_format.rs](https://docs.rs/env_logger/latest/src/custom_format/custom_format.rs.html) +uses `anstyle` via +[`Formatter::default_level_style`](https://docs.rs/env_logger/latest/env_logger/fmt/struct.Formatter.html#method.default_level_style) + ### Breaking Change - Removed bespoke styling API @@ -92,7 +109,8 @@ To open room for changing dependencies: - Added a method to print the module instead of the target -[Unreleased]: https://github.com/rust-cli/env_logger/compare/v0.11.1...HEAD +[Unreleased]: https://github.com/rust-cli/env_logger/compare/v0.11.2...HEAD +[0.11.2]: https://github.com/rust-cli/env_logger/compare/v0.11.1...v0.11.2 [0.11.1]: https://github.com/rust-cli/env_logger/compare/v0.11.0...v0.11.1 [0.11.0]: https://github.com/rust-cli/env_logger/compare/v0.10.2...v0.11.0 [0.10.2]: https://github.com/rust-cli/env_logger/compare/v0.10.1...v0.10.2 diff --git a/Cargo.lock b/Cargo.lock index bb0de81..eb4cb6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,9 +27,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anstyle-parse" @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.1" +version = "0.11.2" dependencies = [ "anstream", "anstyle", diff --git a/Cargo.toml b/Cargo.toml index 97ffdd6..ad6619e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ include = [ [package] name = "env_logger" -version = "0.11.1" +version = "0.11.2" description = """ A logging implementation for `log` which is configured via an environment variable. @@ -58,7 +58,7 @@ log = { version = "0.4.8", features = ["std"] } env_filter = { version = "0.1.0", path = "crates/env_filter", default-features = false } humantime = { version = "2.0.0", optional = true } anstream = { version = "0.6.11", default-features = false, features = ["wincon"], optional = true } -anstyle = { version = "1.0.4", optional = true } +anstyle = { version = "1.0.6", optional = true } [[test]] name = "regexp_filter" diff --git a/README.md b/README.md index 1457ecd..d18a868 100644 --- a/README.md +++ b/README.md @@ -77,12 +77,9 @@ logging levels, the letter case is not significant. Tests can use the `env_logger` crate to see log messages generated during that test: -```toml -[dependencies] -log = "0.4.0" - -[dev-dependencies] -env_logger = "0.10.0" +```console +$ cargo add log +$ cargo add --dev env_logger ``` ```rust diff --git a/examples/custom_format.rs b/examples/custom_format.rs index 8f575fd..80b9aaa 100644 --- a/examples/custom_format.rs +++ b/examples/custom_format.rs @@ -33,13 +33,11 @@ fn main() { // We are reusing `anstyle` but there are `anstyle-*` crates to adapt it to your // preferred styling crate. let warn_style = buf.default_level_style(log::Level::Warn); - let reset = warn_style.render_reset(); - let warn_style = warn_style.render(); let timestamp = buf.timestamp(); writeln!( buf, - "My formatted log ({timestamp}): {warn_style}{}{reset}", + "My formatted log ({timestamp}): {warn_style}{}{warn_style:#}", record.args() ) }) diff --git a/src/fmt/humantime.rs b/src/fmt/humantime.rs index 582a631..9c93d3b 100644 --- a/src/fmt/humantime.rs +++ b/src/fmt/humantime.rs @@ -25,8 +25,6 @@ impl Formatter { /// writeln!(buf, "{}: {}: {}", ts, record.level(), record.args()) /// }); /// ``` - /// - /// [`Timestamp`]: struct.Timestamp.html pub fn timestamp(&self) -> Timestamp { Timestamp { time: SystemTime::now(), @@ -76,8 +74,7 @@ impl Formatter { /// The timestamp implements [`Display`] and can be written to a [`Formatter`]. /// /// [RFC3339]: https://www.ietf.org/rfc/rfc3339.txt -/// [`Display`]: https://doc.rust-lang.org/stable/std/fmt/trait.Display.html -/// [`Formatter`]: struct.Formatter.html +/// [`Display`]: std::fmt::Display pub struct Timestamp { time: SystemTime, precision: TimestampPrecision, diff --git a/src/fmt/mod.rs b/src/fmt/mod.rs index faee69b..883f943 100644 --- a/src/fmt/mod.rs +++ b/src/fmt/mod.rs @@ -9,8 +9,14 @@ //! //! The format used to print log records can be customised using the [`Builder::format`] //! method. -//! Custom formats can apply different color and weight to printed values using -//! [`Style`] builders. +//! +//! Terminal styling is done through ANSI escape codes and will be adapted to the capabilities of +//! the target stream. +//! For example, you could use one of: +//! - [anstyle](https://docs.rs/anstyle) is a minimal, runtime string styling API and is re-exported as [`style`] +//! - [owo-colors](https://docs.rs/owo-colors) is a feature rich runtime string styling API +//! - [color-print](https://docs.rs/color-print) for feature-rich compile-time styling API +//! See also [`Formatter::default_level_style`] //! //! ``` //! use std::io::Write; @@ -24,10 +30,8 @@ //! }); //! ``` //! -//! [`Formatter`]: struct.Formatter.html -//! [`Style`]: struct.Style.html -//! [`Builder::format`]: ../struct.Builder.html#method.format -//! [`Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html +//! [`Builder::format`]: crate::Builder::format +//! [`Write`]: std::io::Write use std::cell::RefCell; use std::fmt::Display; @@ -80,7 +84,7 @@ impl Default for TimestampPrecision { /// A formatter to write logs into. /// /// `Formatter` implements the standard [`Write`] trait for writing log records. -/// It also supports terminal colors, through the [`style`] method. +/// It also supports terminal styling using ANSI escape codes. /// /// # Examples /// @@ -95,9 +99,8 @@ impl Default for TimestampPrecision { /// builder.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args())); /// ``` /// -/// [`Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html -/// [`writeln`]: https://doc.rust-lang.org/stable/std/macro.writeln.html -/// [`style`]: #method.style +/// [`Write`]: std::io::Write +/// [`writeln`]: std::writeln pub struct Formatter { buf: Rc>, write_style: WriteStyle, @@ -129,6 +132,8 @@ impl Formatter { /// Get the default [`style::Style`] for the given level. /// /// The style can be used to print other values besides the level. + /// + /// See [`style`] for how to adapt it to the styling crate of your choice pub fn default_level_style(&self, level: Level) -> style::Style { if self.write_style == WriteStyle::Never { style::Style::new() @@ -238,10 +243,6 @@ type SubtleStyle = StyledValue<&'static str>; type SubtleStyle = &'static str; /// A value that can be printed using the given styles. -/// -/// It is the result of calling [`Style::value`]. -/// -/// [`Style::value`]: struct.Style.html#method.value #[cfg(feature = "color")] struct StyledValue { style: style::Style, @@ -251,14 +252,13 @@ struct StyledValue { #[cfg(feature = "color")] impl std::fmt::Display for StyledValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let style = self.style.render(); - let reset = self.style.render_reset(); + let style = self.style; // We need to make sure `f`s settings don't get passed onto the styling but do get passed // to the value write!(f, "{style}")?; self.value.fmt(f)?; - write!(f, "{reset}")?; + write!(f, "{style:#}")?; Ok(()) } } diff --git a/src/lib.rs b/src/lib.rs index 26f25b8..86db145 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -259,20 +259,12 @@ //! [gh-repo-examples]: https://github.com/rust-cli/env_logger/tree/main/examples //! [level-enum]: https://docs.rs/log/latest/log/enum.Level.html //! [log-crate-url]: https://docs.rs/log -//! [`Builder`]: struct.Builder.html -//! [`Builder::is_test`]: struct.Builder.html#method.is_test -//! [`Env`]: struct.Env.html -//! [`fmt`]: fmt/index.html #![doc( html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://www.rust-lang.org/static/images/favicon.ico" )] #![cfg_attr(docsrs, feature(doc_auto_cfg))] -// When compiled for the rustc compiler itself we want to make sure that this is -// an unstable crate -#![cfg_attr(rustbuild, feature(staged_api, rustc_private))] -#![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))] #![deny(missing_debug_implementations, missing_docs)] mod logger; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy