diff -Nru rust-env-logger-0.7.1/Cargo.lock rust-env-logger-0.9.0/Cargo.lock --- rust-env-logger-0.7.1/Cargo.lock 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/Cargo.lock 2021-07-14 15:57:38.000000000 +0000 @@ -2,211 +2,130 @@ # It is not intended for manual editing. [[package]] name = "aho-corasick" -version = "0.6.9" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] name = "atty" -version = "0.2.8" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", + "winapi", ] [[package]] name = "cfg-if" -version = "0.1.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "env_logger" -version = "0.7.1" +version = "0.9.0" dependencies = [ - "atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "atty", + "humantime", + "log", + "regex", + "termcolor", ] [[package]] -name = "humantime" -version = "1.3.0" +name = "hermit-abi" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] -name = "lazy_static" -version = "1.0.0" +name = "humantime" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "libc" -version = "0.2.40" +version = "0.2.98" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" [[package]] name = "log" -version = "0.4.8" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", ] [[package]] name = "memchr" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quick-error" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "redox_syscall" -version = "0.1.37" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "redox_termios" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "regex" -version = "1.1.0" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ - "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.5" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "termcolor" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "termion" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.3.6" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" dependencies = [ - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util", ] [[package]] -name = "ucd-util" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "utf8-ranges" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "version_check" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] name = "winapi" -version = "0.3.4" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.2" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "wincolor" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[metadata] -"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e" -"checksum atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "af80143d6f7608d746df1520709e5d141c96f240b0e62b0aa41bdfb53374d9d4" -"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" -"checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" -"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" -"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" -"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" -"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" -"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" -"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" -"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" -"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" -"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff -Nru rust-env-logger-0.7.1/Cargo.toml rust-env-logger-0.9.0/Cargo.toml --- rust-env-logger-0.7.1/Cargo.toml 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/Cargo.toml 2021-07-14 15:57:38.000000000 +0000 @@ -13,15 +13,16 @@ [package] edition = "2018" name = "env_logger" -version = "0.7.1" +version = "0.9.0" authors = ["The Rust Project Developers"] +include = ["src/**/*", "tests", "LICENSE-*", "README.md", "CHANGELOG.md"] description = "A logging implementation for `log` which is configured via an environment\nvariable.\n" documentation = "https://docs.rs/env_logger" readme = "README.md" keywords = ["logging", "log", "logger"] categories = ["development-tools::debugging"] license = "MIT/Apache-2.0" -repository = "https://github.com/sebasmagri/env_logger/" +repository = "https://github.com/env-logger-rs/env_logger/" [[test]] name = "regexp_filter" @@ -43,7 +44,7 @@ optional = true [dependencies.humantime] -version = "1.3" +version = "2.0.0" optional = true [dependencies.log] @@ -52,7 +53,9 @@ [dependencies.regex] version = "1.0.3" +features = ["std", "perf"] optional = true +default-features = false [dependencies.termcolor] version = "1.0.2" diff -Nru rust-env-logger-0.7.1/Cargo.toml.orig rust-env-logger-0.9.0/Cargo.toml.orig --- rust-env-logger-0.7.1/Cargo.toml.orig 2019-10-17 05:07:35.000000000 +0000 +++ rust-env-logger-0.9.0/Cargo.toml.orig 2021-07-14 12:52:33.000000000 +0000 @@ -1,11 +1,11 @@ [package] name = "env_logger" edition = "2018" -version = "0.7.1" # remember to update html_root_url +version = "0.9.0" authors = ["The Rust Project Developers"] license = "MIT/Apache-2.0" readme = "README.md" -repository = "https://github.com/sebasmagri/env_logger/" +repository = "https://github.com/env-logger-rs/env_logger/" documentation = "https://docs.rs/env_logger" description = """ A logging implementation for `log` which is configured via an environment @@ -13,6 +13,7 @@ """ categories = ["development-tools::debugging"] keywords = ["logging", "log", "logger"] +include = ["src/**/*", "tests", "LICENSE-*", "README.md", "CHANGELOG.md"] [workspace] members = [ @@ -21,9 +22,9 @@ [dependencies] log = { version = "0.4.8", features = ["std"] } -regex = { version = "1.0.3", optional = true } +regex = { version = "1.0.3", optional = true, default-features=false, features=["std", "perf"] } termcolor = { version = "1.0.2", optional = true } -humantime = { version = "1.3", optional = true } +humantime = { version = "2.0.0", optional = true } atty = { version = "0.2.5", optional = true } [[test]] diff -Nru rust-env-logger-0.7.1/.cargo_vcs_info.json rust-env-logger-0.9.0/.cargo_vcs_info.json --- rust-env-logger-0.7.1/.cargo_vcs_info.json 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/.cargo_vcs_info.json 2021-07-14 15:57:38.000000000 +0000 @@ -1,5 +1,5 @@ { "git": { - "sha1": "68a170094649c48c6ce7471acf3a33fd2799541c" + "sha1": "04856ac38baf422baebb40729cf51127a75b82ed" } } diff -Nru rust-env-logger-0.7.1/CHANGELOG.md rust-env-logger-0.9.0/CHANGELOG.md --- rust-env-logger-0.7.1/CHANGELOG.md 2019-06-30 22:45:16.000000000 +0000 +++ rust-env-logger-0.9.0/CHANGELOG.md 2021-07-14 12:01:37.000000000 +0000 @@ -1,3 +1,3 @@ Changes to this crate are tracked via [GitHub Releases][releases]. -[releases]: https://github.com/sebasmagri/env_logger/releases +[releases]: https://github.com/env-logger-rs/env_logger/releases diff -Nru rust-env-logger-0.7.1/debian/cargo-checksum.json rust-env-logger-0.9.0/debian/cargo-checksum.json --- rust-env-logger-0.7.1/debian/cargo-checksum.json 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/cargo-checksum.json 2021-10-23 19:34:22.000000000 +0000 @@ -1 +1 @@ -{"package":"Could not get crate checksum","files":{}} +{"package":"0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3","files":{}} diff -Nru rust-env-logger-0.7.1/debian/changelog rust-env-logger-0.9.0/debian/changelog --- rust-env-logger-0.7.1/debian/changelog 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/changelog 2021-10-23 19:34:22.000000000 +0000 @@ -1,3 +1,10 @@ +rust-env-logger (0.9.0-1) unstable; urgency=medium + + * Team upload. + * Package env_logger 0.9.0 from crates.io using debcargo 2.4.4 + + -- Ximin Luo Sat, 23 Oct 2021 20:34:22 +0100 + rust-env-logger (0.7.1-2) unstable; urgency=medium * Package env_logger 0.7.1 from crates.io using debcargo 2.4.2 diff -Nru rust-env-logger-0.7.1/debian/compat rust-env-logger-0.9.0/debian/compat --- rust-env-logger-0.7.1/debian/compat 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/compat 2021-10-23 19:34:22.000000000 +0000 @@ -1 +1 @@ -11 +12 diff -Nru rust-env-logger-0.7.1/debian/control rust-env-logger-0.9.0/debian/control --- rust-env-logger-0.7.1/debian/control 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/control 2021-10-23 19:34:22.000000000 +0000 @@ -1,24 +1,26 @@ Source: rust-env-logger Section: rust Priority: optional -Build-Depends: debhelper (>= 11), - dh-cargo (>= 18), +Build-Depends: debhelper (>= 12), + dh-cargo (>= 24), cargo:native , rustc:native , libstd-rust-dev , librust-atty-0.2+default-dev (>= 0.2.5-~~) , - librust-humantime-2+default-dev | librust-humantime-1+default-dev (>= 1.3-~~) , + librust-humantime-2+default-dev , librust-log-0.4+default-dev (>= 0.4.8-~~) , librust-log-0.4+std-dev (>= 0.4.8-~~) , - librust-regex-1+default-dev (>= 1.0.3-~~) , + librust-regex-1+perf-dev (>= 1.0.3-~~) , + librust-regex-1+std-dev (>= 1.0.3-~~) , librust-termcolor-1+default-dev (>= 1.0.2-~~) Maintainer: Debian Rust Maintainers Uploaders: Wolfgang Silbermayr -Standards-Version: 4.4.1 +Standards-Version: 4.5.1 Vcs-Git: https://salsa.debian.org/rust-team/debcargo-conf.git [src/env-logger] Vcs-Browser: https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/env-logger X-Cargo-Crate: env_logger +Rules-Requires-Root: no Package: librust-env-logger-dev Architecture: any @@ -36,9 +38,9 @@ librust-env-logger+termcolor-dev (= ${binary:Version}) Provides: librust-env-logger-0-dev (= ${binary:Version}), - librust-env-logger-0.7-dev (= ${binary:Version}), - librust-env-logger-0.7.1-dev (= ${binary:Version}) -Description: Log implementation configured via environment variable - Rust source code + librust-env-logger-0.9-dev (= ${binary:Version}), + librust-env-logger-0.9.0-dev (= ${binary:Version}) +Description: Logging implementation for `log` which is configured via an environment variable - Rust source code This package contains the source for the Rust env_logger crate, packaged by debcargo for use with cargo and dh-cargo. @@ -51,9 +53,9 @@ librust-atty-0.2+default-dev (>= 0.2.5-~~) Provides: librust-env-logger-0+atty-dev (= ${binary:Version}), - librust-env-logger-0.7+atty-dev (= ${binary:Version}), - librust-env-logger-0.7.1+atty-dev (= ${binary:Version}) -Description: Log implementation configured via environment variable - feature "atty" + librust-env-logger-0.9+atty-dev (= ${binary:Version}), + librust-env-logger-0.9.0+atty-dev (= ${binary:Version}) +Description: Logging implementation for `log` which is configured via an environment variable - feature "atty" This metapackage enables feature "atty" for the Rust env_logger crate, by pulling in any additional dependencies needed by that feature. @@ -64,14 +66,15 @@ ${misc:Depends}, librust-env-logger-dev (= ${binary:Version}), librust-atty-0.2+default-dev (>= 0.2.5-~~), - librust-humantime-2+default-dev | librust-humantime-1+default-dev (>= 1.3-~~), - librust-regex-1+default-dev (>= 1.0.3-~~), + librust-humantime-2+default-dev, + librust-regex-1+perf-dev (>= 1.0.3-~~), + librust-regex-1+std-dev (>= 1.0.3-~~), librust-termcolor-1+default-dev (>= 1.0.2-~~) Provides: librust-env-logger-0+default-dev (= ${binary:Version}), - librust-env-logger-0.7+default-dev (= ${binary:Version}), - librust-env-logger-0.7.1+default-dev (= ${binary:Version}) -Description: Log implementation configured via environment variable - feature "default" + librust-env-logger-0.9+default-dev (= ${binary:Version}), + librust-env-logger-0.9.0+default-dev (= ${binary:Version}) +Description: Logging implementation for `log` which is configured via an environment variable - feature "default" This metapackage enables feature "default" for the Rust env_logger crate, by pulling in any additional dependencies needed by that feature. @@ -81,12 +84,12 @@ Depends: ${misc:Depends}, librust-env-logger-dev (= ${binary:Version}), - librust-humantime-2+default-dev | librust-humantime-1+default-dev (>= 1.3-~~) + librust-humantime-2+default-dev Provides: librust-env-logger-0+humantime-dev (= ${binary:Version}), - librust-env-logger-0.7+humantime-dev (= ${binary:Version}), - librust-env-logger-0.7.1+humantime-dev (= ${binary:Version}) -Description: Log implementation configured via environment variable - feature "humantime" + librust-env-logger-0.9+humantime-dev (= ${binary:Version}), + librust-env-logger-0.9.0+humantime-dev (= ${binary:Version}) +Description: Logging implementation for `log` which is configured via an environment variable - feature "humantime" This metapackage enables feature "humantime" for the Rust env_logger crate, by pulling in any additional dependencies needed by that feature. @@ -96,12 +99,13 @@ Depends: ${misc:Depends}, librust-env-logger-dev (= ${binary:Version}), - librust-regex-1+default-dev (>= 1.0.3-~~) + librust-regex-1+perf-dev (>= 1.0.3-~~), + librust-regex-1+std-dev (>= 1.0.3-~~) Provides: librust-env-logger-0+regex-dev (= ${binary:Version}), - librust-env-logger-0.7+regex-dev (= ${binary:Version}), - librust-env-logger-0.7.1+regex-dev (= ${binary:Version}) -Description: Log implementation configured via environment variable - feature "regex" + librust-env-logger-0.9+regex-dev (= ${binary:Version}), + librust-env-logger-0.9.0+regex-dev (= ${binary:Version}) +Description: Logging implementation for `log` which is configured via an environment variable - feature "regex" This metapackage enables feature "regex" for the Rust env_logger crate, by pulling in any additional dependencies needed by that feature. @@ -114,8 +118,8 @@ librust-termcolor-1+default-dev (>= 1.0.2-~~) Provides: librust-env-logger-0+termcolor-dev (= ${binary:Version}), - librust-env-logger-0.7+termcolor-dev (= ${binary:Version}), - librust-env-logger-0.7.1+termcolor-dev (= ${binary:Version}) -Description: Log implementation configured via environment variable - feature "termcolor" + librust-env-logger-0.9+termcolor-dev (= ${binary:Version}), + librust-env-logger-0.9.0+termcolor-dev (= ${binary:Version}) +Description: Logging implementation for `log` which is configured via an environment variable - feature "termcolor" This metapackage enables feature "termcolor" for the Rust env_logger crate, by pulling in any additional dependencies needed by that feature. diff -Nru rust-env-logger-0.7.1/debian/copyright rust-env-logger-0.9.0/debian/copyright --- rust-env-logger-0.7.1/debian/copyright 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/copyright 2021-10-23 19:34:22.000000000 +0000 @@ -1,7 +1,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: env_logger Upstream-Contact: The Rust Project Developers -Source: https://github.com/sebasmagri/env_logger/ +Source: https://github.com/env-logger-rs/env_logger/ Files: * Copyright: 2014-2019 The Rust Project Developers @@ -9,7 +9,7 @@ Files: debian/* Copyright: - 2018-2019 Debian Rust Maintainers + 2018-2021 Debian Rust Maintainers 2018-2019 Wolfgang Silbermayr License: MIT or Apache-2.0 diff -Nru rust-env-logger-0.7.1/debian/copyright.debcargo.hint rust-env-logger-0.9.0/debian/copyright.debcargo.hint --- rust-env-logger-0.7.1/debian/copyright.debcargo.hint 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/copyright.debcargo.hint 2021-10-23 19:34:22.000000000 +0000 @@ -1,7 +1,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: env_logger Upstream-Contact: The Rust Project Developers -Source: https://github.com/sebasmagri/env_logger/ +Source: https://github.com/env-logger-rs/env_logger/ Files: * Copyright: FIXME (overlay) UNKNOWN-YEARS The Rust Project Developers @@ -28,8 +28,8 @@ Files: debian/* Copyright: - 2018-2020 Debian Rust Maintainers - 2018-2020 Wolfgang Silbermayr + 2018-2021 Debian Rust Maintainers + 2018-2021 Wolfgang Silbermayr License: MIT or Apache-2.0 License: Apache-2.0 diff -Nru rust-env-logger-0.7.1/debian/librust-env-logger+atty-dev.lintian-overrides rust-env-logger-0.9.0/debian/librust-env-logger+atty-dev.lintian-overrides --- rust-env-logger-0.7.1/debian/librust-env-logger+atty-dev.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/debian/librust-env-logger+atty-dev.lintian-overrides 2021-10-23 19:34:22.000000000 +0000 @@ -0,0 +1 @@ +librust-env-logger+atty-dev binary: empty-rust-library-declares-provides * \ No newline at end of file diff -Nru rust-env-logger-0.7.1/debian/librust-env-logger+default-dev.lintian-overrides rust-env-logger-0.9.0/debian/librust-env-logger+default-dev.lintian-overrides --- rust-env-logger-0.7.1/debian/librust-env-logger+default-dev.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/debian/librust-env-logger+default-dev.lintian-overrides 2021-10-23 19:34:22.000000000 +0000 @@ -0,0 +1 @@ +librust-env-logger+default-dev binary: empty-rust-library-declares-provides * \ No newline at end of file diff -Nru rust-env-logger-0.7.1/debian/librust-env-logger+humantime-dev.lintian-overrides rust-env-logger-0.9.0/debian/librust-env-logger+humantime-dev.lintian-overrides --- rust-env-logger-0.7.1/debian/librust-env-logger+humantime-dev.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/debian/librust-env-logger+humantime-dev.lintian-overrides 2021-10-23 19:34:22.000000000 +0000 @@ -0,0 +1 @@ +librust-env-logger+humantime-dev binary: empty-rust-library-declares-provides * \ No newline at end of file diff -Nru rust-env-logger-0.7.1/debian/librust-env-logger+regex-dev.lintian-overrides rust-env-logger-0.9.0/debian/librust-env-logger+regex-dev.lintian-overrides --- rust-env-logger-0.7.1/debian/librust-env-logger+regex-dev.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/debian/librust-env-logger+regex-dev.lintian-overrides 2021-10-23 19:34:22.000000000 +0000 @@ -0,0 +1 @@ +librust-env-logger+regex-dev binary: empty-rust-library-declares-provides * \ No newline at end of file diff -Nru rust-env-logger-0.7.1/debian/librust-env-logger+termcolor-dev.lintian-overrides rust-env-logger-0.9.0/debian/librust-env-logger+termcolor-dev.lintian-overrides --- rust-env-logger-0.7.1/debian/librust-env-logger+termcolor-dev.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ rust-env-logger-0.9.0/debian/librust-env-logger+termcolor-dev.lintian-overrides 2021-10-23 19:34:22.000000000 +0000 @@ -0,0 +1 @@ +librust-env-logger+termcolor-dev binary: empty-rust-library-declares-provides * \ No newline at end of file diff -Nru rust-env-logger-0.7.1/debian/patches/relax-deps.diff rust-env-logger-0.9.0/debian/patches/relax-deps.diff --- rust-env-logger-0.7.1/debian/patches/relax-deps.diff 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/patches/relax-deps.diff 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ ---- a/Cargo.toml -+++ b/Cargo.toml -@@ -43,7 +43,7 @@ - optional = true - - [dependencies.humantime] --version = "1.3" -+version = ">= 1.3, < 3" - optional = true - - [dependencies.log] diff -Nru rust-env-logger-0.7.1/debian/patches/series rust-env-logger-0.9.0/debian/patches/series --- rust-env-logger-0.7.1/debian/patches/series 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -relax-deps.diff diff -Nru rust-env-logger-0.7.1/debian/tests/control rust-env-logger-0.9.0/debian/tests/control --- rust-env-logger-0.7.1/debian/tests/control 2020-04-05 12:57:09.000000000 +0000 +++ rust-env-logger-0.9.0/debian/tests/control 2021-10-23 19:34:22.000000000 +0000 @@ -1,34 +1,34 @@ -Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.7.1 --all-targets --all-features -Features: test-name=@ +Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.9.0 --all-targets --all-features +Features: test-name=rust-env-logger:@ Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.7.1 --all-targets --no-default-features -Features: test-name=librust-env-logger-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.9.0 --all-targets --no-default-features +Features: test-name=librust-env-logger-dev: Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.7.1 --all-targets --features atty -Features: test-name=librust-env-logger+atty-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.9.0 --all-targets --no-default-features --features atty +Features: test-name=librust-env-logger+atty-dev:atty Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.7.1 --all-targets --features default -Features: test-name=librust-env-logger+default-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.9.0 --all-targets +Features: test-name=librust-env-logger+default-dev:default Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.7.1 --all-targets --features humantime -Features: test-name=librust-env-logger+humantime-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.9.0 --all-targets --no-default-features --features humantime +Features: test-name=librust-env-logger+humantime-dev:humantime Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.7.1 --all-targets --features regex -Features: test-name=librust-env-logger+regex-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.9.0 --all-targets --no-default-features --features regex +Features: test-name=librust-env-logger+regex-dev:regex Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.7.1 --all-targets --features termcolor -Features: test-name=librust-env-logger+termcolor-dev +Test-Command: /usr/share/cargo/bin/cargo-auto-test env_logger 0.9.0 --all-targets --no-default-features --features termcolor +Features: test-name=librust-env-logger+termcolor-dev:termcolor Depends: dh-cargo (>= 18), @ Restrictions: allow-stderr, skip-not-installable diff -Nru rust-env-logger-0.7.1/examples/custom_default_format.rs rust-env-logger-0.9.0/examples/custom_default_format.rs --- rust-env-logger-0.7.1/examples/custom_default_format.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/examples/custom_default_format.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,41 +0,0 @@ -/*! -Disabling parts of the default format. - -Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`: - -```no_run,shell -$ export MY_LOG_LEVEL='info' -``` - -Also try setting the `MY_LOG_STYLE` environment variable to `never` to disable colors -or `auto` to enable them: - -```no_run,shell -$ export MY_LOG_STYLE=never -``` - -If you want to control the logging output completely, see the `custom_logger` example. -*/ - -#[macro_use] -extern crate log; - -use env_logger::{Builder, Env}; - -fn init_logger() { - let env = Env::default() - .filter("MY_LOG_LEVEL") - .write_style("MY_LOG_STYLE"); - - let mut builder = Builder::from_env(env); - - builder.format_level(false).format_timestamp_nanos(); - - builder.init(); -} - -fn main() { - init_logger(); - - info!("a log from `MyLogger`"); -} diff -Nru rust-env-logger-0.7.1/examples/custom_format.rs rust-env-logger-0.9.0/examples/custom_format.rs --- rust-env-logger-0.7.1/examples/custom_format.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/examples/custom_format.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,53 +0,0 @@ -/*! -Changing the default logging format. - -Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`: - -```no_run,shell -$ export MY_LOG_LEVEL='info' -``` - -Also try setting the `MY_LOG_STYLE` environment variable to `never` to disable colors -or `auto` to enable them: - -```no_run,shell -$ export MY_LOG_STYLE=never -``` - -If you want to control the logging output completely, see the `custom_logger` example. -*/ - -#[cfg(all(feature = "termcolor", feature = "humantime"))] -fn main() { - use env_logger::{fmt, Builder, Env}; - use std::io::Write; - - fn init_logger() { - let env = Env::default() - .filter("MY_LOG_LEVEL") - .write_style("MY_LOG_STYLE"); - - Builder::from_env(env) - .format(|buf, record| { - let mut style = buf.style(); - style.set_bg(fmt::Color::Yellow).set_bold(true); - - let timestamp = buf.timestamp(); - - writeln!( - buf, - "My formatted log ({}): {}", - timestamp, - style.value(record.args()) - ) - }) - .init(); - } - - init_logger(); - - log::info!("a log from `MyLogger`"); -} - -#[cfg(not(all(feature = "termcolor", feature = "humantime")))] -fn main() {} diff -Nru rust-env-logger-0.7.1/examples/custom_logger.rs rust-env-logger-0.9.0/examples/custom_logger.rs --- rust-env-logger-0.7.1/examples/custom_logger.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/examples/custom_logger.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -/*! -Using `env_logger` to drive a custom logger. - -Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`: - -```no_run,shell -$ export MY_LOG_LEVEL='info' -``` - -If you only want to change the way logs are formatted, look at the `custom_format` example. -*/ - -#[macro_use] -extern crate log; - -use env_logger::filter::Filter; -use log::{Log, Metadata, Record, SetLoggerError}; - -struct MyLogger { - inner: Filter, -} - -impl MyLogger { - fn new() -> MyLogger { - use env_logger::filter::Builder; - let mut builder = Builder::from_env("MY_LOG_LEVEL"); - - MyLogger { - inner: builder.build(), - } - } - - fn init() -> Result<(), SetLoggerError> { - let logger = Self::new(); - - log::set_max_level(logger.inner.filter()); - log::set_boxed_logger(Box::new(logger)) - } -} - -impl Log for MyLogger { - fn enabled(&self, metadata: &Metadata) -> bool { - self.inner.enabled(metadata) - } - - fn log(&self, record: &Record) { - // Check if the record is matched by the logger before logging - if self.inner.matches(record) { - println!("{} - {}", record.level(), record.args()); - } - } - - fn flush(&self) {} -} - -fn main() { - MyLogger::init().unwrap(); - - info!("a log from `MyLogger`"); -} diff -Nru rust-env-logger-0.7.1/examples/default.rs rust-env-logger-0.9.0/examples/default.rs --- rust-env-logger-0.7.1/examples/default.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/examples/default.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,38 +0,0 @@ -/*! -Using `env_logger`. - -Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`: - -```no_run,shell -$ export MY_LOG_LEVEL='info' -``` - -Also try setting the `MY_LOG_STYLE` environment variable to `never` to disable colors -or `auto` to enable them: - -```no_run,shell -$ export MY_LOG_STYLE=never -``` -*/ - -#[macro_use] -extern crate log; - -use env_logger::Env; - -fn main() { - // The `Env` lets us tweak what the environment - // variables to read are and what the default - // value is if they're missing - let env = Env::default() - .filter_or("MY_LOG_LEVEL", "trace") - .write_style_or("MY_LOG_STYLE", "always"); - - env_logger::init_from_env(env); - - trace!("some trace log"); - debug!("some debug log"); - info!("some information log"); - warn!("some warning log"); - error!("some error log"); -} diff -Nru rust-env-logger-0.7.1/examples/direct_logger.rs rust-env-logger-0.9.0/examples/direct_logger.rs --- rust-env-logger-0.7.1/examples/direct_logger.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/examples/direct_logger.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -/*! -Using `env_logger::Logger` and the `log::Log` trait directly. - -This example doesn't rely on environment variables, or having a static logger installed. -*/ - -fn record() -> log::Record<'static> { - let error_metadata = log::MetadataBuilder::new() - .target("myApp") - .level(log::Level::Error) - .build(); - - log::Record::builder() - .metadata(error_metadata) - .args(format_args!("Error!")) - .line(Some(433)) - .file(Some("app.rs")) - .module_path(Some("server")) - .build() -} - -fn main() { - use log::Log; - - let stylish_logger = env_logger::Builder::new() - .filter(None, log::LevelFilter::Error) - .write_style(env_logger::WriteStyle::Always) - .build(); - - let unstylish_logger = env_logger::Builder::new() - .filter(None, log::LevelFilter::Error) - .write_style(env_logger::WriteStyle::Never) - .build(); - - stylish_logger.log(&record()); - unstylish_logger.log(&record()); -} diff -Nru rust-env-logger-0.7.1/examples/filters_from_code.rs rust-env-logger-0.9.0/examples/filters_from_code.rs --- rust-env-logger-0.7.1/examples/filters_from_code.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/examples/filters_from_code.rs 1970-01-01 00:00:00.000000000 +0000 @@ -1,18 +0,0 @@ -/*! -Specify logging filters in code instead of using an environment variable. -*/ - -#[macro_use] -extern crate log; - -fn main() { - env_logger::builder() - .filter_level(log::LevelFilter::Trace) - .init(); - - trace!("some trace log"); - debug!("some debug log"); - info!("some information log"); - warn!("some warning log"); - error!("some error log"); -} diff -Nru rust-env-logger-0.7.1/.gitignore rust-env-logger-0.9.0/.gitignore --- rust-env-logger-0.7.1/.gitignore 2018-04-18 22:13:07.000000000 +0000 +++ rust-env-logger-0.9.0/.gitignore 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -target/ -Cargo.lock -.emacs* -*~ diff -Nru rust-env-logger-0.7.1/README.md rust-env-logger-0.9.0/README.md --- rust-env-logger-0.7.1/README.md 2019-10-17 05:07:35.000000000 +0000 +++ rust-env-logger-0.9.0/README.md 2021-07-14 12:01:37.000000000 +0000 @@ -1,4 +1,9 @@ -env_logger [![Build Status](https://travis-ci.org/sebasmagri/env_logger.svg?branch=master)](https://travis-ci.org/sebasmagri/env_logger) [![Maintenance](https://img.shields.io/badge/maintenance-actively%20maintained-brightgreen.svg)](https://github.com/sebasmagri/env_logger) [![crates.io](https://img.shields.io/crates/v/env_logger.svg)](https://crates.io/crates/env_logger) [![Documentation](https://img.shields.io/badge/docs-current-blue.svg)](https://docs.rs/env_logger) +# env_logger + +[![Maintenance](https://img.shields.io/badge/maintenance-actively%20maintained-brightgreen.svg)](https://github.com/env-logger-rs/env_logger) +[![crates.io](https://img.shields.io/crates/v/env_logger.svg)](https://crates.io/crates/env_logger) +[![Documentation](https://docs.rs/env_logger/badge.svg)](https://docs.rs/env_logger) +[![Documentation](https://img.shields.io/badge/docs-master-blue.svg)](https://env-logger-rs.github.io/env_logger/env_logger/index.html) ========== Implements a logger that can be configured via environment variables. @@ -16,7 +21,7 @@ ```toml [dependencies] log = "0.4.0" -env_logger = "0.7.1" +env_logger = "0.8.4" ``` `env_logger` must be initialized as early as possible in the project. After it's initialized, you can use the `log` macros to do actual logging. @@ -34,7 +39,7 @@ } ``` -Then when running the executable, specify a value for the `RUST_LOG` +Then when running the executable, specify a value for the **`RUST_LOG`** environment variable that corresponds with the log messages you want to show. ```bash @@ -42,7 +47,37 @@ [2018-11-03T06:09:06Z INFO default] starting up ``` -`env_logger` can be configured in other ways besides an environment variable. See [the examples](https://github.com/sebasmagri/env_logger/tree/master/examples) for more approaches. +The letter case is not significant for the logging level names; e.g., `debug`, +`DEBUG`, and `dEbuG` all represent the same logging level. Therefore, the +previous example could also have been written this way, specifying the log +level as `INFO` rather than as `info`: + +```bash +$ RUST_LOG=INFO ./main +[2018-11-03T06:09:06Z INFO default] starting up +``` + +So which form should you use? For consistency, our convention is to use lower +case names. Where our docs do use other forms, they do so in the context of +specific examples, so you won't be surprised if you see similar usage in the +wild. + +The log levels that may be specified correspond to the [`log::Level`][level-enum] +enum from the `log` crate. They are: + + * `error` + * `warn` + * `info` + * `debug` + * `trace` + +[level-enum]: https://docs.rs/log/latest/log/enum.Level.html "log::Level (docs.rs)" + +There is also a pseudo logging level, `off`, which may be specified to disable +all logging for a given module or for the entire application. As with the +logging levels, the letter case is not significant. + +`env_logger` can be configured in other ways besides an environment variable. See [the examples](https://github.com/env-logger-rs/env_logger/tree/master/examples) for more approaches. ### In tests @@ -53,7 +88,7 @@ log = "0.4.0" [dev-dependencies] -env_logger = "0.7.1" +env_logger = "0.8.4" ``` ```rust diff -Nru rust-env-logger-0.7.1/src/filter/mod.rs rust-env-logger-0.9.0/src/filter/mod.rs --- rust-env-logger-0.7.1/src/filter/mod.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/src/filter/mod.rs 2021-07-14 12:52:16.000000000 +0000 @@ -52,7 +52,6 @@ //! //! fn flush(&self) {} //! } -//! # fn main() {} //! ``` //! //! [Enabling Logging]: ../index.html#enabling-logging @@ -60,6 +59,7 @@ //! [`Filter::matches`]: struct.Filter.html#method.matches use log::{Level, LevelFilter, Metadata, Record}; +use std::collections::HashMap; use std::env; use std::fmt; use std::mem; @@ -92,29 +92,23 @@ /// ## Example /// /// ``` -/// #[macro_use] -/// extern crate log; -/// extern crate env_logger; -/// -/// use std::env; -/// use std::io; +/// # #[macro_use] extern crate log; +/// # use std::env; /// use env_logger::filter::Builder; /// -/// fn main() { -/// let mut builder = Builder::new(); -/// -/// // Parse a logging filter from an environment variable. -/// if let Ok(rust_log) = env::var("RUST_LOG") { -/// builder.parse(&rust_log); -/// } +/// let mut builder = Builder::new(); /// -/// let filter = builder.build(); +/// // Parse a logging filter from an environment variable. +/// if let Ok(rust_log) = env::var("RUST_LOG") { +/// builder.parse(&rust_log); /// } +/// +/// let filter = builder.build(); /// ``` /// /// [`Filter`]: struct.Filter.html pub struct Builder { - directives: Vec, + directives: HashMap, LevelFilter>, filter: Option, built: bool, } @@ -132,20 +126,15 @@ /// # Example /// /// ```rust - /// extern crate log; - /// extern crate env_logger; - /// /// use log::LevelFilter; /// use env_logger::filter::Builder; /// - /// fn main() { - /// let mut builder = Builder::new(); - /// builder.filter(Some("module1"), LevelFilter::Info); - /// builder.filter(Some("module2"), LevelFilter::Error); + /// let mut builder = Builder::new(); + /// builder.filter(Some("module1"), LevelFilter::Info); + /// builder.filter(Some("module2"), LevelFilter::Error); /// - /// let filter = builder.build(); - /// assert_eq!(filter.filter(), LevelFilter::Info); - /// } + /// let filter = builder.build(); + /// assert_eq!(filter.filter(), LevelFilter::Info); /// ``` pub fn filter(&self) -> LevelFilter { self.directives @@ -183,7 +172,7 @@ /// Initializes the filter builder with defaults. pub fn new() -> Builder { Builder { - directives: Vec::new(), + directives: HashMap::new(), filter: None, built: false, } @@ -215,10 +204,7 @@ /// The given module (if any) will log at most the specified level provided. /// If no module is provided then the filter will apply to all log messages. pub fn filter(&mut self, module: Option<&str>, level: LevelFilter) -> &mut Self { - self.directives.push(Directive { - name: module.map(|s| s.to_string()), - level, - }); + self.directives.insert(module.map(|s| s.to_string()), level); self } @@ -233,7 +219,7 @@ self.filter = filter; for directive in directives { - self.directives.push(directive); + self.directives.insert(directive.name, directive.level); } self } @@ -243,16 +229,23 @@ assert!(!self.built, "attempt to re-use consumed builder"); self.built = true; + let mut directives = Vec::new(); if self.directives.is_empty() { // Adds the default filter if none exist - self.directives.push(Directive { + directives.push(Directive { name: None, level: LevelFilter::Error, }); } else { + // Consume map of directives. + let directives_map = mem::take(&mut self.directives); + directives = directives_map + .into_iter() + .map(|(name, level)| Directive { name, level }) + .collect(); // Sort the directives by length of their name, this allows a // little more efficient lookup at runtime. - self.directives.sort_by(|a, b| { + directives.sort_by(|a, b| { let alen = a.name.as_ref().map(|a| a.len()).unwrap_or(0); let blen = b.name.as_ref().map(|b| b.len()).unwrap_or(0); alen.cmp(&blen) @@ -260,7 +253,7 @@ } Filter { - directives: mem::replace(&mut self.directives, Vec::new()), + directives: mem::take(&mut directives), filter: mem::replace(&mut self.filter, None), } } @@ -310,9 +303,9 @@ ); return (dirs, None); } - mods.map(|m| { - for s in m.split(',') { - if s.len() == 0 { + if let Some(m) = mods { + for s in m.split(',').map(|ss| ss.trim()) { + if s.is_empty() { continue; } let mut parts = s.split('='); @@ -352,9 +345,9 @@ level: log_level, }); } - }); + } - let filter = filter.map_or(None, |filter| match inner::Filter::new(filter) { + let filter = filter.and_then(|filter| match inner::Filter::new(filter) { Ok(re) => Some(re), Err(e) => { eprintln!("warning: invalid regex filter - {}", e); @@ -362,7 +355,7 @@ } }); - return (dirs, filter); + (dirs, filter) } // Check whether a level and target are enabled by the set of directives. @@ -407,6 +400,26 @@ assert!(!enabled(&logger.directives, Level::Debug, "crate2")); } + // Some of our tests are only correct or complete when they cover the full + // universe of variants for log::Level. In the unlikely event that a new + // variant is added in the future, this test will detect the scenario and + // alert us to the need to review and update the tests. In such a + // situation, this test will fail to compile, and the error message will + // look something like this: + // + // error[E0004]: non-exhaustive patterns: `NewVariant` not covered + // --> src/filter/mod.rs:413:15 + // | + // 413 | match level_universe { + // | ^^^^^^^^^^^^^^ pattern `NewVariant` not covered + #[test] + fn ensure_tests_cover_level_universe() { + let level_universe: Level = Level::Trace; // use of trace variant is arbitrary + match level_universe { + Level::Error | Level::Warn | Level::Info | Level::Debug | Level::Trace => (), + } + } + #[test] fn parse_default() { let logger = Builder::new().parse("info,crate1::mod1=warn").build(); @@ -415,6 +428,166 @@ } #[test] + fn parse_default_bare_level_off_lc() { + let logger = Builder::new().parse("off").build(); + assert!(!enabled(&logger.directives, Level::Error, "")); + assert!(!enabled(&logger.directives, Level::Warn, "")); + assert!(!enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_off_uc() { + let logger = Builder::new().parse("OFF").build(); + assert!(!enabled(&logger.directives, Level::Error, "")); + assert!(!enabled(&logger.directives, Level::Warn, "")); + assert!(!enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_error_lc() { + let logger = Builder::new().parse("error").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(!enabled(&logger.directives, Level::Warn, "")); + assert!(!enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_error_uc() { + let logger = Builder::new().parse("ERROR").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(!enabled(&logger.directives, Level::Warn, "")); + assert!(!enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_warn_lc() { + let logger = Builder::new().parse("warn").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(!enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_warn_uc() { + let logger = Builder::new().parse("WARN").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(!enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_info_lc() { + let logger = Builder::new().parse("info").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_info_uc() { + let logger = Builder::new().parse("INFO").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(!enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_debug_lc() { + let logger = Builder::new().parse("debug").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_debug_uc() { + let logger = Builder::new().parse("DEBUG").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_trace_lc() { + let logger = Builder::new().parse("trace").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(enabled(&logger.directives, Level::Trace, "")); + } + + #[test] + fn parse_default_bare_level_trace_uc() { + let logger = Builder::new().parse("TRACE").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(enabled(&logger.directives, Level::Trace, "")); + } + + // In practice, the desired log level is typically specified by a token + // that is either all lowercase (e.g., 'trace') or all uppercase (.e.g, + // 'TRACE'), but this tests serves as a reminder that + // log::Level::from_str() ignores all case variants. + #[test] + fn parse_default_bare_level_debug_mixed() { + { + let logger = Builder::new().parse("Debug").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + { + let logger = Builder::new().parse("debuG").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + { + let logger = Builder::new().parse("deBug").build(); + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + { + let logger = Builder::new().parse("DeBuG").build(); // LaTeX flavor! + assert!(enabled(&logger.directives, Level::Error, "")); + assert!(enabled(&logger.directives, Level::Warn, "")); + assert!(enabled(&logger.directives, Level::Info, "")); + assert!(enabled(&logger.directives, Level::Debug, "")); + assert!(!enabled(&logger.directives, Level::Trace, "")); + } + } + + #[test] fn match_full_path() { let logger = make_logger_filter(vec![ Directive { @@ -570,6 +743,55 @@ } #[test] + fn parse_spec_empty_level_isolated() { + // test parse_spec with "" as log level (and the entire spec str) + let (dirs, filter) = parse_spec(""); // should be ignored + assert_eq!(dirs.len(), 0); + assert!(filter.is_none()); + } + + #[test] + fn parse_spec_blank_level_isolated() { + // test parse_spec with a white-space-only string specified as the log + // level (and the entire spec str) + let (dirs, filter) = parse_spec(" "); // should be ignored + assert_eq!(dirs.len(), 0); + assert!(filter.is_none()); + } + + #[test] + fn parse_spec_blank_level_isolated_comma_only() { + // The spec should contain zero or more comma-separated string slices, + // so a comma-only string should be interpretted as two empty strings + // (which should both be treated as invalid, so ignored). + let (dirs, filter) = parse_spec(","); // should be ignored + assert_eq!(dirs.len(), 0); + assert!(filter.is_none()); + } + + #[test] + fn parse_spec_blank_level_isolated_comma_blank() { + // The spec should contain zero or more comma-separated string slices, + // so this bogus spec should be interpretted as containing one empty + // string and one blank string. Both should both be treated as + // invalid, so ignored. + let (dirs, filter) = parse_spec(", "); // should be ignored + assert_eq!(dirs.len(), 0); + assert!(filter.is_none()); + } + + #[test] + fn parse_spec_blank_level_isolated_blank_comma() { + // The spec should contain zero or more comma-separated string slices, + // so this bogus spec should be interpretted as containing one blank + // string and one empty string. Both should both be treated as + // invalid, so ignored. + let (dirs, filter) = parse_spec(" ,"); // should be ignored + assert_eq!(dirs.len(), 0); + assert!(filter.is_none()); + } + + #[test] fn parse_spec_global() { // test parse_spec with no crate let (dirs, filter) = parse_spec("warn,crate2=debug"); @@ -581,6 +803,36 @@ assert!(filter.is_none()); } + #[test] + fn parse_spec_global_bare_warn_lc() { + // test parse_spec with no crate, in isolation, all lowercase + let (dirs, filter) = parse_spec("warn"); + assert_eq!(dirs.len(), 1); + assert_eq!(dirs[0].name, None); + assert_eq!(dirs[0].level, LevelFilter::Warn); + assert!(filter.is_none()); + } + + #[test] + fn parse_spec_global_bare_warn_uc() { + // test parse_spec with no crate, in isolation, all uppercase + let (dirs, filter) = parse_spec("WARN"); + assert_eq!(dirs.len(), 1); + assert_eq!(dirs[0].name, None); + assert_eq!(dirs[0].level, LevelFilter::Warn); + assert!(filter.is_none()); + } + + #[test] + fn parse_spec_global_bare_warn_mixed() { + // test parse_spec with no crate, in isolation, mixed case + let (dirs, filter) = parse_spec("wArN"); + assert_eq!(dirs.len(), 1); + assert_eq!(dirs[0].name, None); + assert_eq!(dirs[0].level, LevelFilter::Warn); + assert!(filter.is_none()); + } + #[test] fn parse_spec_valid_filter() { let (dirs, filter) = parse_spec("crate1::mod1=error,crate1::mod2,crate2=debug/abc"); diff -Nru rust-env-logger-0.7.1/src/fmt/mod.rs rust-env-logger-0.9.0/src/fmt/mod.rs --- rust-env-logger-0.7.1/src/fmt/mod.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/src/fmt/mod.rs 2021-07-14 12:52:16.000000000 +0000 @@ -136,13 +136,16 @@ } } +pub(crate) type FormatFn = Box io::Result<()> + Sync + Send>; + pub(crate) struct Builder { pub format_timestamp: Option, pub format_module_path: bool, + pub format_target: bool, pub format_level: bool, pub format_indent: Option, - #[allow(unknown_lints, bare_trait_objects)] - pub custom_format: Option io::Result<()> + Sync + Send>>, + pub custom_format: Option, + pub format_suffix: &'static str, built: bool, } @@ -150,10 +153,12 @@ fn default() -> Self { Builder { format_timestamp: Some(Default::default()), - format_module_path: true, + format_module_path: false, + format_target: true, format_level: true, format_indent: Some(4), custom_format: None, + format_suffix: "\n", built: false, } } @@ -165,8 +170,7 @@ /// If the `custom_format` is `Some`, then any `default_format` switches are ignored. /// If the `custom_format` is `None`, then a default format is returned. /// Any `default_format` switches set to `false` won't be written by the format. - #[allow(unknown_lints, bare_trait_objects)] - pub fn build(&mut self) -> Box io::Result<()> + Sync + Send> { + pub fn build(&mut self) -> FormatFn { assert!(!self.built, "attempt to re-use consumed builder"); let built = mem::replace( @@ -184,9 +188,11 @@ let fmt = DefaultFormat { timestamp: built.format_timestamp, module_path: built.format_module_path, + target: built.format_target, level: built.format_level, written_header_value: false, indent: built.format_indent, + suffix: built.format_suffix, buf, }; @@ -207,10 +213,12 @@ struct DefaultFormat<'a> { timestamp: Option, module_path: bool, + target: bool, level: bool, written_header_value: bool, indent: Option, buf: &'a mut Formatter, + suffix: &'a str, } impl<'a> DefaultFormat<'a> { @@ -218,6 +226,7 @@ self.write_timestamp()?; self.write_level(record)?; self.write_module_path(record)?; + self.write_target(record)?; self.finish_header()?; self.write_args(record) @@ -230,6 +239,7 @@ .style() .set_color(Color::Black) .set_intense(true) + .clone() .into_value(text) } #[cfg(not(feature = "termcolor"))] @@ -306,6 +316,17 @@ } } + fn write_target(&mut self, record: &Record) -> io::Result<()> { + if !self.target { + return Ok(()); + } + + match record.target() { + "" => Ok(()), + target => self.write_header_value(target), + } + } + fn finish_header(&mut self) -> io::Result<()> { if self.written_header_value { let close_brace = self.subtle_style("]"); @@ -318,7 +339,7 @@ fn write_args(&mut self, record: &Record) -> io::Result<()> { match self.indent { // Fast path for no indentation - None => writeln!(self.buf, "{}", record.args()), + None => write!(self.buf, "{}{}", record.args(), self.suffix), Some(indent_count) => { // Create a wrapper around the buffer only if we have to actually indent the message @@ -333,7 +354,13 @@ let mut first = true; for chunk in buf.split(|&x| x == b'\n') { if !first { - write!(self.fmt.buf, "\n{:width$}", "", width = self.indent_count)?; + write!( + self.fmt.buf, + "{}{:width$}", + self.fmt.suffix, + "", + width = self.indent_count + )?; } self.fmt.buf.write_all(chunk)?; first = false; @@ -356,7 +383,7 @@ write!(wrapper, "{}", record.args())?; } - writeln!(self.buf)?; + write!(self.buf, "{}", self.suffix)?; Ok(()) } @@ -370,23 +397,33 @@ use log::{Level, Record}; - fn write(fmt: DefaultFormat) -> String { + fn write_record(record: Record, fmt: DefaultFormat) -> String { let buf = fmt.buf.buf.clone(); - let record = Record::builder() - .args(format_args!("log\nmessage")) - .level(Level::Info) - .file(Some("test.rs")) - .line(Some(144)) - .module_path(Some("test::path")) - .build(); - fmt.write(&record).expect("failed to write record"); let buf = buf.borrow(); String::from_utf8(buf.bytes().to_vec()).expect("failed to read record") } + fn write_target<'a>(target: &'a str, fmt: DefaultFormat) -> String { + write_record( + Record::builder() + .args(format_args!("log\nmessage")) + .level(Level::Info) + .file(Some("test.rs")) + .line(Some(144)) + .module_path(Some("test::path")) + .target(target) + .build(), + fmt, + ) + } + + fn write(fmt: DefaultFormat) -> String { + write_target("", fmt) + } + #[test] fn format_with_header() { let writer = writer::Builder::new() @@ -398,9 +435,11 @@ let written = write(DefaultFormat { timestamp: None, module_path: true, + target: false, level: true, written_header_value: false, indent: None, + suffix: "\n", buf: &mut f, }); @@ -418,9 +457,11 @@ let written = write(DefaultFormat { timestamp: None, module_path: false, + target: false, level: false, written_header_value: false, indent: None, + suffix: "\n", buf: &mut f, }); @@ -438,9 +479,11 @@ let written = write(DefaultFormat { timestamp: None, module_path: true, + target: false, level: true, written_header_value: false, indent: Some(4), + suffix: "\n", buf: &mut f, }); @@ -458,9 +501,11 @@ let written = write(DefaultFormat { timestamp: None, module_path: true, + target: false, level: true, written_header_value: false, indent: Some(0), + suffix: "\n", buf: &mut f, }); @@ -478,12 +523,130 @@ let written = write(DefaultFormat { timestamp: None, module_path: false, + target: false, level: false, written_header_value: false, indent: Some(4), + suffix: "\n", buf: &mut f, }); assert_eq!("log\n message\n", written); } + + #[test] + fn format_suffix() { + let writer = writer::Builder::new() + .write_style(WriteStyle::Never) + .build(); + + let mut f = Formatter::new(&writer); + + let written = write(DefaultFormat { + timestamp: None, + module_path: false, + target: false, + level: false, + written_header_value: false, + indent: None, + suffix: "\n\n", + buf: &mut f, + }); + + assert_eq!("log\nmessage\n\n", written); + } + + #[test] + fn format_suffix_with_indent() { + let writer = writer::Builder::new() + .write_style(WriteStyle::Never) + .build(); + + let mut f = Formatter::new(&writer); + + let written = write(DefaultFormat { + timestamp: None, + module_path: false, + target: false, + level: false, + written_header_value: false, + indent: Some(4), + suffix: "\n\n", + buf: &mut f, + }); + + assert_eq!("log\n\n message\n\n", written); + } + + #[test] + fn format_target() { + let writer = writer::Builder::new() + .write_style(WriteStyle::Never) + .build(); + + let mut f = Formatter::new(&writer); + + let written = write_target( + "target", + DefaultFormat { + timestamp: None, + module_path: true, + target: true, + level: true, + written_header_value: false, + indent: None, + suffix: "\n", + buf: &mut f, + }, + ); + + assert_eq!("[INFO test::path target] log\nmessage\n", written); + } + + #[test] + fn format_empty_target() { + let writer = writer::Builder::new() + .write_style(WriteStyle::Never) + .build(); + + let mut f = Formatter::new(&writer); + + let written = write(DefaultFormat { + timestamp: None, + module_path: true, + target: true, + level: true, + written_header_value: false, + indent: None, + suffix: "\n", + buf: &mut f, + }); + + assert_eq!("[INFO test::path] log\nmessage\n", written); + } + + #[test] + fn format_no_target() { + let writer = writer::Builder::new() + .write_style(WriteStyle::Never) + .build(); + + let mut f = Formatter::new(&writer); + + let written = write_target( + "target", + DefaultFormat { + timestamp: None, + module_path: true, + target: false, + level: true, + written_header_value: false, + indent: None, + suffix: "\n", + buf: &mut f, + }, + ); + + assert_eq!("[INFO test::path] log\nmessage\n", written); + } } diff -Nru rust-env-logger-0.7.1/src/fmt/writer/atty.rs rust-env-logger-0.9.0/src/fmt/writer/atty.rs --- rust-env-logger-0.7.1/src/fmt/writer/atty.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/src/fmt/writer/atty.rs 2021-07-14 12:01:37.000000000 +0000 @@ -9,8 +9,6 @@ #[cfg(feature = "atty")] mod imp { - use atty; - pub(in crate::fmt) fn is_stdout() -> bool { atty::is(atty::Stream::Stdout) } diff -Nru rust-env-logger-0.7.1/src/fmt/writer/mod.rs rust-env-logger-0.9.0/src/fmt/writer/mod.rs --- rust-env-logger-0.7.1/src/fmt/writer/mod.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/src/fmt/writer/mod.rs 2021-07-14 12:43:39.000000000 +0000 @@ -3,22 +3,24 @@ use self::atty::{is_stderr, is_stdout}; use self::termcolor::BufferWriter; -use std::{fmt, io}; +use std::{fmt, io, mem, sync::Mutex}; -pub(in crate::fmt) mod glob { +pub(super) mod glob { pub use super::termcolor::glob::*; pub use super::*; } -pub(in crate::fmt) use self::termcolor::Buffer; +pub(super) use self::termcolor::Buffer; -/// Log target, either `stdout` or `stderr`. -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +/// Log target, either `stdout`, `stderr` or a custom pipe. +#[non_exhaustive] pub enum Target { /// Logs will be sent to standard output. Stdout, /// Logs will be sent to standard error. Stderr, + /// Logs will be sent to a custom pipe. + Pipe(Box), } impl Default for Target { @@ -27,6 +29,61 @@ } } +impl fmt::Debug for Target { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + Self::Stdout => "stdout", + Self::Stderr => "stderr", + Self::Pipe(_) => "pipe", + } + ) + } +} + +/// Log target, either `stdout`, `stderr` or a custom pipe. +/// +/// Same as `Target`, except the pipe is wrapped in a mutex for interior mutability. +pub(super) enum WritableTarget { + /// Logs will be sent to standard output. + Stdout, + /// Logs will be sent to standard error. + Stderr, + /// Logs will be sent to a custom pipe. + Pipe(Box>), +} + +impl From for WritableTarget { + fn from(target: Target) -> Self { + match target { + Target::Stdout => Self::Stdout, + Target::Stderr => Self::Stderr, + Target::Pipe(pipe) => Self::Pipe(Box::new(Mutex::new(pipe))), + } + } +} + +impl Default for WritableTarget { + fn default() -> Self { + Self::from(Target::default()) + } +} + +impl fmt::Debug for WritableTarget { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}", + match self { + Self::Stdout => "stdout", + Self::Stderr => "stderr", + Self::Pipe(_) => "pipe", + } + ) + } +} /// Whether or not to print styles to the target. #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum WriteStyle { @@ -55,11 +112,11 @@ self.write_style } - pub(in crate::fmt) fn buffer(&self) -> Buffer { + pub(super) fn buffer(&self) -> Buffer { self.inner.buffer() } - pub(in crate::fmt) fn print(&self, buf: &Buffer) -> io::Result<()> { + pub(super) fn print(&self, buf: &Buffer) -> io::Result<()> { self.inner.print(buf) } } @@ -67,8 +124,9 @@ /// A builder for a terminal writer. /// /// The target and style choice can be configured before building. +#[derive(Debug)] pub(crate) struct Builder { - target: Target, + target: WritableTarget, write_style: WriteStyle, is_test: bool, built: bool, @@ -87,7 +145,7 @@ /// Set the target to write to. pub(crate) fn target(&mut self, target: Target) -> &mut Self { - self.target = target; + self.target = target.into(); self } @@ -119,9 +177,10 @@ let color_choice = match self.write_style { WriteStyle::Auto => { - if match self.target { - Target::Stderr => is_stderr(), - Target::Stdout => is_stdout(), + if match &self.target { + WritableTarget::Stderr => is_stderr(), + WritableTarget::Stdout => is_stdout(), + WritableTarget::Pipe(_) => false, } { WriteStyle::Auto } else { @@ -131,9 +190,10 @@ color_choice => color_choice, }; - let writer = match self.target { - Target::Stderr => BufferWriter::stderr(self.is_test, color_choice), - Target::Stdout => BufferWriter::stdout(self.is_test, color_choice), + let writer = match mem::take(&mut self.target) { + WritableTarget::Stderr => BufferWriter::stderr(self.is_test, color_choice), + WritableTarget::Stdout => BufferWriter::stdout(self.is_test, color_choice), + WritableTarget::Pipe(pipe) => BufferWriter::pipe(self.is_test, color_choice, pipe), }; Writer { @@ -149,15 +209,6 @@ } } -impl fmt::Debug for Builder { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Logger") - .field("target", &self.target) - .field("write_style", &self.write_style) - .finish() - } -} - impl fmt::Debug for Writer { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Writer").finish() diff -Nru rust-env-logger-0.7.1/src/fmt/writer/termcolor/extern_impl.rs rust-env-logger-0.9.0/src/fmt/writer/termcolor/extern_impl.rs --- rust-env-logger-0.7.1/src/fmt/writer/termcolor/extern_impl.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/src/fmt/writer/termcolor/extern_impl.rs 2021-07-14 12:43:39.000000000 +0000 @@ -3,11 +3,12 @@ use std::fmt; use std::io::{self, Write}; use std::rc::Rc; +use std::sync::Mutex; use log::Level; use termcolor::{self, ColorChoice, ColorSpec, WriteColor}; -use crate::fmt::{Formatter, Target, WriteStyle}; +use crate::fmt::{Formatter, WritableTarget, WriteStyle}; pub(in crate::fmt::writer) mod glob { pub use super::*; @@ -51,8 +52,8 @@ pub fn default_level_style(&self, level: Level) -> Style { let mut level_style = self.style(); match level { - Level::Trace => level_style.set_color(Color::Black).set_intense(true), - Level::Debug => level_style.set_color(Color::White), + Level::Trace => level_style.set_color(Color::Cyan), + Level::Debug => level_style.set_color(Color::Blue), Level::Info => level_style.set_color(Color::Green), Level::Warn => level_style.set_color(Color::Yellow), Level::Error => level_style.set_color(Color::Red).set_bold(true), @@ -70,46 +71,71 @@ pub(in crate::fmt::writer) struct BufferWriter { inner: termcolor::BufferWriter, - test_target: Option, + test_target: Option, } pub(in crate::fmt) struct Buffer { inner: termcolor::Buffer, - test_target: Option, + has_test_target: bool, } impl BufferWriter { pub(in crate::fmt::writer) fn stderr(is_test: bool, write_style: WriteStyle) -> Self { BufferWriter { inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()), - test_target: if is_test { Some(Target::Stderr) } else { None }, + test_target: if is_test { + Some(WritableTarget::Stderr) + } else { + None + }, } } pub(in crate::fmt::writer) fn stdout(is_test: bool, write_style: WriteStyle) -> Self { BufferWriter { inner: termcolor::BufferWriter::stdout(write_style.into_color_choice()), - test_target: if is_test { Some(Target::Stdout) } else { None }, + test_target: if is_test { + Some(WritableTarget::Stdout) + } else { + None + }, + } + } + + pub(in crate::fmt::writer) fn pipe( + is_test: bool, + write_style: WriteStyle, + pipe: Box>, + ) -> Self { + BufferWriter { + // The inner Buffer is never printed from, but it is still needed to handle coloring and other formating + inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()), + test_target: if is_test { + Some(WritableTarget::Pipe(pipe)) + } else { + None + }, } } pub(in crate::fmt::writer) fn buffer(&self) -> Buffer { Buffer { inner: self.inner.buffer(), - test_target: self.test_target, + has_test_target: self.test_target.is_some(), } } pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> { - if let Some(target) = self.test_target { + if let Some(target) = &self.test_target { // This impl uses the `eprint` and `print` macros // instead of `termcolor`'s buffer. // This is so their output can be captured by `cargo test` let log = String::from_utf8_lossy(buf.bytes()); match target { - Target::Stderr => eprint!("{}", log), - Target::Stdout => print!("{}", log), + WritableTarget::Stderr => eprint!("{}", log), + WritableTarget::Stdout => print!("{}", log), + WritableTarget::Pipe(pipe) => write!(pipe.lock().unwrap(), "{}", log)?, } Ok(()) @@ -138,7 +164,7 @@ fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> { // Ignore styles for test captured logs because they can't be printed - if self.test_target.is_none() { + if !self.has_test_target { self.inner.set_color(spec) } else { Ok(()) @@ -147,7 +173,7 @@ fn reset(&mut self) -> io::Result<()> { // Ignore styles for test captured logs because they can't be printed - if self.test_target.is_none() { + if !self.has_test_target { self.inner.reset() } else { Ok(()) @@ -255,7 +281,7 @@ /// }); /// ``` pub fn set_color(&mut self, color: Color) -> &mut Style { - self.spec.set_fg(color.into_termcolor()); + self.spec.set_fg(Some(color.into_termcolor())); self } @@ -334,7 +360,7 @@ /// }); /// ``` pub fn set_bg(&mut self, color: Color) -> &mut Style { - self.spec.set_bg(color.into_termcolor()); + self.spec.set_bg(Some(color.into_termcolor())); self } @@ -370,9 +396,9 @@ } /// Wrap a value in the style by taking ownership of it. - pub(crate) fn into_value(&mut self, value: T) -> StyledValue<'static, T> { + pub(crate) fn into_value(self, value: T) -> StyledValue<'static, T> { StyledValue { - style: Cow::Owned(self.clone()), + style: Cow::Owned(self), value, } } @@ -451,6 +477,7 @@ /// /// Hexadecimal numbers are written with a `0x` prefix. #[allow(missing_docs)] +#[non_exhaustive] #[derive(Clone, Debug, Eq, PartialEq)] pub enum Color { Black, @@ -463,24 +490,21 @@ White, Ansi256(u8), Rgb(u8, u8, u8), - #[doc(hidden)] - __Nonexhaustive, } impl Color { - fn into_termcolor(self) -> Option { + fn into_termcolor(self) -> termcolor::Color { match self { - Color::Black => Some(termcolor::Color::Black), - Color::Blue => Some(termcolor::Color::Blue), - Color::Green => Some(termcolor::Color::Green), - Color::Red => Some(termcolor::Color::Red), - Color::Cyan => Some(termcolor::Color::Cyan), - Color::Magenta => Some(termcolor::Color::Magenta), - Color::Yellow => Some(termcolor::Color::Yellow), - Color::White => Some(termcolor::Color::White), - Color::Ansi256(value) => Some(termcolor::Color::Ansi256(value)), - Color::Rgb(r, g, b) => Some(termcolor::Color::Rgb(r, g, b)), - _ => None, + Color::Black => termcolor::Color::Black, + Color::Blue => termcolor::Color::Blue, + Color::Green => termcolor::Color::Green, + Color::Red => termcolor::Color::Red, + Color::Cyan => termcolor::Color::Cyan, + Color::Magenta => termcolor::Color::Magenta, + Color::Yellow => termcolor::Color::Yellow, + Color::White => termcolor::Color::White, + Color::Ansi256(value) => termcolor::Color::Ansi256(value), + Color::Rgb(r, g, b) => termcolor::Color::Rgb(r, g, b), } } } diff -Nru rust-env-logger-0.7.1/src/fmt/writer/termcolor/shim_impl.rs rust-env-logger-0.9.0/src/fmt/writer/termcolor/shim_impl.rs --- rust-env-logger-0.7.1/src/fmt/writer/termcolor/shim_impl.rs 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/src/fmt/writer/termcolor/shim_impl.rs 2021-07-14 12:43:39.000000000 +0000 @@ -1,11 +1,11 @@ -use std::io; +use std::{io, sync::Mutex}; -use crate::fmt::{Target, WriteStyle}; +use crate::fmt::{WritableTarget, WriteStyle}; pub(in crate::fmt::writer) mod glob {} pub(in crate::fmt::writer) struct BufferWriter { - target: Target, + target: WritableTarget, } pub(in crate::fmt) struct Buffer(Vec); @@ -13,13 +13,23 @@ impl BufferWriter { pub(in crate::fmt::writer) fn stderr(_is_test: bool, _write_style: WriteStyle) -> Self { BufferWriter { - target: Target::Stderr, + target: WritableTarget::Stderr, } } pub(in crate::fmt::writer) fn stdout(_is_test: bool, _write_style: WriteStyle) -> Self { BufferWriter { - target: Target::Stdout, + target: WritableTarget::Stdout, + } + } + + pub(in crate::fmt::writer) fn pipe( + _is_test: bool, + _write_style: WriteStyle, + pipe: Box>, + ) -> Self { + BufferWriter { + target: WritableTarget::Pipe(pipe), } } @@ -30,12 +40,12 @@ pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> { // This impl uses the `eprint` and `print` macros // instead of using the streams directly. - // This is so their output can be captured by `cargo test` - let log = String::from_utf8_lossy(&buf.0); - - match self.target { - Target::Stderr => eprint!("{}", log), - Target::Stdout => print!("{}", log), + // This is so their output can be captured by `cargo test`. + match &self.target { + // Safety: If the target type is `Pipe`, `target_pipe` will always be non-empty. + WritableTarget::Pipe(pipe) => pipe.lock().unwrap().write_all(&buf.0)?, + WritableTarget::Stdout => print!("{}", String::from_utf8_lossy(&buf.0)), + WritableTarget::Stderr => eprint!("{}", String::from_utf8_lossy(&buf.0)), } Ok(()) diff -Nru rust-env-logger-0.7.1/src/lib.rs rust-env-logger-0.9.0/src/lib.rs --- rust-env-logger-0.7.1/src/lib.rs 2019-10-17 05:07:35.000000000 +0000 +++ rust-env-logger-0.9.0/src/lib.rs 2021-07-14 12:52:16.000000000 +0000 @@ -8,27 +8,29 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! A simple logger configured via environment variables which writes -//! to stdout or stderr, for use with the logging facade exposed by the -//! [`log` crate][log-crate-url]. +//! A simple logger that can be configured via environment variables, for use +//! with the logging facade exposed by the [`log` crate][log-crate-url]. +//! +//! Despite having "env" in its name, **`env_logger`** can also be configured by +//! other means besides environment variables. See [the examples][gh-repo-examples] +//! in the source repository for more approaches. +//! +//! By default, `env_logger` writes logs to `stderr`, but can be configured to +//! instead write them to `stdout`. //! //! ## Example //! //! ``` -//! #[macro_use] extern crate log; -//! -//! use log::Level; +//! use log::{debug, error, log_enabled, info, Level}; //! -//! fn main() { -//! env_logger::init(); +//! env_logger::init(); //! -//! debug!("this is a debug {}", "message"); -//! error!("this is printed by default"); +//! debug!("this is a debug {}", "message"); +//! error!("this is printed by default"); //! -//! if log_enabled!(Level::Info) { -//! let x = 3 * 4; // expensive computation -//! info!("the answer was: {}", x); -//! } +//! if log_enabled!(Level::Info) { +//! let x = 3 * 4; // expensive computation +//! info!("the answer was: {}", x); //! } //! ``` //! @@ -87,37 +89,78 @@ //! //! ## Enabling logging //! -//! Log levels are controlled on a per-module basis, and by default all logging -//! is disabled except for `error!`. Logging is controlled via the `RUST_LOG` -//! environment variable. The value of this environment variable is a -//! comma-separated list of logging directives. A logging directive is of the -//! form: +//! Log levels are controlled on a per-module basis, and **by default all +//! logging is disabled except for the `error` level**. +//! +//! Logging is controlled via the **`RUST_LOG`** environment variable. The +//! value of this environment variable is a comma-separated list of *logging +//! directives*. A logging directive is of the form: //! //! ```text -//! path::to::module=level +//! example::log::target=level //! ``` //! -//! The path to the module is rooted in the name of the crate it was compiled -//! for, so if your program is contained in a file `hello.rs`, for example, to -//! turn on logging for this file you would use a value of `RUST_LOG=hello`. -//! Furthermore, this path is a prefix-search, so all modules nested in the -//! specified module will also have logging enabled. -//! -//! The actual `level` is optional to specify. If omitted, all logging will -//! be enabled. If specified, it must be one of the strings `debug`, `error`, -//! `info`, `warn`, or `trace`. +//! The log target is typically equal to the path of the module the message +//! in question originated from, though it can be overriden. +//! +//! The path is rooted in the name of the crate it was compiled for, so if +//! your program is in a file called, for example, `hello.rs`, the path would +//! simply be be `hello`. +//! +//! Furthermore, the the log can be filtered using prefix-search based on the +//! specified log target. A value of, for example, `RUST_LOG=example`, would +//! match all of the messages with targets: +//! +//! * `example` +//! * `example::test` +//! * `example::test::module::submodule` +//! * `examples::and_more_examples` +//! +//! When providing the crate name or a module path, explicitly specifying the +//! log level is optional. If omitted, all logging for the item will be +//! enabled. +//! +//! The names of the log levels that may be specified correspond to the +//! variations of the [`log::Level`][level-enum] enum from the `log` +//! crate. They are: +//! +//! * `error` +//! * `warn` +//! * `info` +//! * `debug` +//! * `trace` +//! +//! There is also a pseudo logging level, `off`, which may be specified to +//! disable all logging for a given module or for the entire application. As +//! with the logging levels, the letter case is not significant[^fn-off]. +//! +//! [^fn-off]: Similar to the universe of log level names, the `off` pseudo +//! log level feature is also provided by the underlying `log` crate. +//! +//! The letter case is not significant for the logging level names; e.g., +//! `debug`, `DEBUG`, and `dEbuG` all represent the same logging level. For +//! consistency, our convention is to use the lower case names. Where our docs +//! do use other forms, they do so in the context of specific examples, so you +//! won't be surprised if you see similar usage in the wild. //! //! As the log level for a module is optional, the module to enable logging for -//! is also optional. If only a `level` is provided, then the global log -//! level for all modules is set to this value. +//! is also optional. **If only a level is provided, then the global log +//! level for all modules is set to this value.** //! //! Some examples of valid values of `RUST_LOG` are: //! //! * `hello` turns on all logging for the 'hello' module +//! * `trace` turns on all logging for the application, regardless of its name +//! * `TRACE` turns on all logging for the application, regardless of its name (same as previous) //! * `info` turns on all info logging +//! * `INFO` turns on all info logging (same as previous) //! * `hello=debug` turns on debug logging for 'hello' +//! * `hello=DEBUG` turns on debug logging for 'hello' (same as previous) //! * `hello,std::option` turns on hello, and std's option logging //! * `error,hello=warn` turn on global error logging and also warn for hello +//! * `error,hello=off` turn on global error logging, but turn off logging for hello +//! * `off` turns off all logging for the application +//! * `OFF` turns off all logging for the application (same as previous) //! //! ## Filtering results //! @@ -146,7 +189,6 @@ //! //! ``` //! # #[macro_use] extern crate log; -//! # fn main() {} //! #[cfg(test)] //! mod tests { //! fn init() { @@ -225,9 +267,11 @@ //! ``` //! use env_logger::Env; //! -//! env_logger::from_env(Env::default().default_filter_or("warn")).init(); +//! env_logger::Builder::from_env(Env::default().default_filter_or("warn")).init(); //! ``` //! +//! [gh-repo-examples]: https://github.com/env-logger-rs/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 @@ -236,15 +280,13 @@ #![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", - html_root_url = "https://docs.rs/env_logger/0.7.1" + html_favicon_url = "https://www.rust-lang.org/static/images/favicon.ico" )] -#![cfg_attr(test, deny(warnings))] // 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, warnings)] +#![deny(missing_debug_implementations, missing_docs)] use std::{borrow::Cow, cell::RefCell, env, io}; @@ -257,13 +299,13 @@ use self::filter::Filter; use self::fmt::writer::{self, Writer}; -use self::fmt::Formatter; +use self::fmt::{FormatFn, Formatter}; /// The default name for the environment variable to read filters from. -pub const DEFAULT_FILTER_ENV: &'static str = "RUST_LOG"; +pub const DEFAULT_FILTER_ENV: &str = "RUST_LOG"; /// The default name for the environment variable to read style preferences from. -pub const DEFAULT_WRITE_STYLE_ENV: &'static str = "RUST_LOG_STYLE"; +pub const DEFAULT_WRITE_STYLE_ENV: &str = "RUST_LOG_STYLE"; /// Set of environment variables to configure from. /// @@ -309,8 +351,7 @@ pub struct Logger { writer: Writer, filter: Filter, - #[allow(unknown_lints, bare_trait_objects)] - format: Box io::Result<()> + Sync + Send>, + format: FormatFn, } /// `Builder` acts as builder for initializing a `Logger`. @@ -321,23 +362,20 @@ /// # Examples /// /// ``` -/// #[macro_use] extern crate log; -/// -/// use std::env; -/// use std::io::Write; -/// use log::LevelFilter; +/// # #[macro_use] extern crate log; +/// # use std::io::Write; /// use env_logger::Builder; +/// use log::LevelFilter; /// -/// fn main() { -/// let mut builder = Builder::from_default_env(); +/// let mut builder = Builder::from_default_env(); /// -/// builder.format(|buf, record| writeln!(buf, "{} - {}", record.level(), record.args())) -/// .filter(None, LevelFilter::Info) -/// .init(); -/// -/// error!("error message"); -/// info!("info message"); -/// } +/// builder +/// .format(|buf, record| writeln!(buf, "{} - {}", record.level(), record.args())) +/// .filter(None, LevelFilter::Info) +/// .init(); +/// +/// error!("error message"); +/// info!("info message"); /// ``` #[derive(Default)] pub struct Builder { @@ -359,16 +397,15 @@ /// Create a new builder and configure filters and style: /// /// ``` - /// # fn main() { /// use log::LevelFilter; /// use env_logger::{Builder, WriteStyle}; /// /// let mut builder = Builder::new(); /// - /// builder.filter(None, LevelFilter::Info) - /// .write_style(WriteStyle::Always) - /// .init(); - /// # } + /// builder + /// .filter(None, LevelFilter::Info) + /// .write_style(WriteStyle::Always) + /// .init(); /// ``` /// /// [`filter`]: #method.filter @@ -412,17 +449,61 @@ E: Into>, { let mut builder = Builder::new(); + builder.parse_env(env); + builder + } + + /// Applies the configuration from the environment. + /// + /// This function allows a builder to be configured with default parameters, + /// to be then overridden by the environment. + /// + /// # Examples + /// + /// Initialise a logger with filter level `Off`, then override the log + /// filter from an environment variable called `MY_LOG`: + /// + /// ``` + /// use log::LevelFilter; + /// use env_logger::Builder; + /// + /// let mut builder = Builder::new(); + /// + /// builder.filter_level(LevelFilter::Off); + /// builder.parse_env("MY_LOG"); + /// builder.init(); + /// ``` + /// + /// Initialise a logger with filter level `Off`, then use the `MY_LOG` + /// variable to override filtering and `MY_LOG_STYLE` to override whether + /// or not to write styles: + /// + /// ``` + /// use log::LevelFilter; + /// use env_logger::{Builder, Env}; + /// + /// let env = Env::new().filter("MY_LOG").write_style("MY_LOG_STYLE"); + /// + /// let mut builder = Builder::new(); + /// builder.filter_level(LevelFilter::Off); + /// builder.parse_env(env); + /// builder.init(); + /// ``` + pub fn parse_env<'a, E>(&mut self, env: E) -> &mut Self + where + E: Into>, + { let env = env.into(); if let Some(s) = env.get_filter() { - builder.parse_filters(&s); + self.parse_filters(&s); } if let Some(s) = env.get_write_style() { - builder.parse_write_style(&s); + self.parse_write_style(&s); } - builder + self } /// Initializes the log builder from the environment using default variable names. @@ -447,6 +528,32 @@ Self::from_env(Env::default()) } + /// Applies the configuration from the environment using default variable names. + /// + /// This method is a convenient way to call `parse_env(Env::default())` without + /// having to use the `Env` type explicitly. The builder will use the + /// [default environment variables]. + /// + /// # Examples + /// + /// Initialise a logger with filter level `Off`, then configure it using the + /// default environment variables: + /// + /// ``` + /// use log::LevelFilter; + /// use env_logger::Builder; + /// + /// let mut builder = Builder::new(); + /// builder.filter_level(LevelFilter::Off); + /// builder.parse_default_env(); + /// builder.init(); + /// ``` + /// + /// [default environment variables]: struct.Env.html#default-environment-variables + pub fn parse_default_env(&mut self) -> &mut Self { + self.parse_env(Env::default()) + } + /// Sets the format function for formatting the log output. /// /// This function is called on each record logged and should format the @@ -501,6 +608,12 @@ self } + /// Whether or not to write the target in the default format. + pub fn format_target(&mut self, write: bool) -> &mut Self { + self.format.format_target = write; + self + } + /// Configures the amount of spaces to use to indent multiline log records. /// A value of `None` disables any kind of indentation. pub fn format_indent(&mut self, indent: Option) -> &mut Self { @@ -534,21 +647,25 @@ self.format_timestamp(Some(fmt::TimestampPrecision::Nanos)) } + /// Configures the end of line suffix. + pub fn format_suffix(&mut self, suffix: &'static str) -> &mut Self { + self.format.format_suffix = suffix; + self + } + /// Adds a directive to the filter for a specific module. /// /// # Examples /// - /// Only include messages for warning and above for logs in `path::to::module`: + /// Only include messages for info and above for logs in `path::to::module`: /// /// ``` - /// # fn main() { - /// use log::LevelFilter; /// use env_logger::Builder; + /// use log::LevelFilter; /// /// let mut builder = Builder::new(); /// /// builder.filter_module("path::to::module", LevelFilter::Info); - /// # } /// ``` pub fn filter_module(&mut self, module: &str, level: LevelFilter) -> &mut Self { self.filter.filter_module(module, level); @@ -559,17 +676,15 @@ /// /// # Examples /// - /// Only include messages for warning and above for logs in `path::to::module`: + /// Only include messages for info and above for logs in `path::to::module`: /// /// ``` - /// # fn main() { - /// use log::LevelFilter; /// use env_logger::Builder; + /// use log::LevelFilter; /// /// let mut builder = Builder::new(); /// /// builder.filter_level(LevelFilter::Info); - /// # } /// ``` pub fn filter_level(&mut self, level: LevelFilter) -> &mut Self { self.filter.filter_level(level); @@ -583,17 +698,15 @@ /// /// # Examples /// - /// Only include messages for warning and above for logs in `path::to::module`: + /// Only include messages for info and above for logs in `path::to::module`: /// /// ``` - /// # fn main() { - /// use log::LevelFilter; /// use env_logger::Builder; + /// use log::LevelFilter; /// /// let mut builder = Builder::new(); /// /// builder.filter(Some("path::to::module"), LevelFilter::Info); - /// # } /// ``` pub fn filter(&mut self, module: Option<&str>, level: LevelFilter) -> &mut Self { self.filter.filter(module, level); @@ -611,7 +724,10 @@ /// Sets the target for the log output. /// - /// Env logger can log to either stdout or stderr. The default is stderr. + /// Env logger can log to either stdout, stderr or a custom pipe. The default is stderr. + /// + /// The custom pipe can be used to send the log messages to a custom sink (for example a file). + /// Do note that direct writes to a file can become a bottleneck due to IO operation times. /// /// # Examples /// @@ -1054,7 +1170,6 @@ /// and `MY_LOG_STYLE` for writing colors: /// /// ``` -/// # extern crate env_logger; /// use env_logger::{Builder, Env}; /// /// # fn run() -> Result<(), Box<::std::error::Error>> { @@ -1064,7 +1179,7 @@ /// /// Ok(()) /// # } -/// # fn main() { run().unwrap(); } +/// # run().unwrap(); /// ``` /// /// # Errors @@ -1114,6 +1229,9 @@ /// Create a new builder with the default environment variables. /// /// The builder can be configured before being initialized. +/// This is a convenient way of calling [`Builder::from_default_env`]. +/// +/// [`Builder::from_default_env`]: struct.Builder.html#method.from_default_env pub fn builder() -> Builder { Builder::from_default_env() } @@ -1121,6 +1239,10 @@ /// Create a builder from the given environment variables. /// /// The builder can be configured before being initialized. +#[deprecated( + since = "0.8.0", + note = "Prefer `env_logger::Builder::from_env()` instead." +)] pub fn from_env<'a, E>(env: E) -> Builder where E: Into>, @@ -1174,4 +1296,20 @@ assert_eq!(Some("from default".to_owned()), env.get_write_style()); } + + #[test] + fn builder_parse_env_overrides_existing_filters() { + env::set_var( + "builder_parse_default_env_overrides_existing_filters", + "debug", + ); + let env = Env::new().filter("builder_parse_default_env_overrides_existing_filters"); + + let mut builder = Builder::new(); + builder.filter_level(LevelFilter::Trace); + // Overrides global level to debug + builder.parse_env(env); + + assert_eq!(builder.filter.build().filter(), LevelFilter::Debug); + } } diff -Nru rust-env-logger-0.7.1/.travis.yml rust-env-logger-0.9.0/.travis.yml --- rust-env-logger-0.7.1/.travis.yml 2019-10-17 04:19:26.000000000 +0000 +++ rust-env-logger-0.9.0/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -language: rust -sudo: false -rust: - - 1.31.0 - - stable - - beta - - nightly -before_script: - - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH -script: - - if [ "${MINIMAL_VERSIONS}" = "y" ]; then cargo update -Z minimal-versions; fi - - cargo run -p ci - - cargo run --example default -after_success: - - travis-cargo --only nightly doc-upload - -matrix: - include: - - rust: nightly - env: MINIMAL_VERSIONS=y - -notifications: - email: -on_success: never