Bug 1813411 - Force-upgrade env_logger to 0.10. r=emilio

This preemptively avoids the addition of a new version of the crate.

Differential Revision: https://phabricator.services.mozilla.com/D168221
This commit is contained in:
Mike Hommey 2023-01-30 17:35:12 +00:00
Родитель 525a2026d3
Коммит 970620c00a
23 изменённых файлов: 710 добавлений и 48 удалений

23
Cargo.lock сгенерированный
Просмотреть файл

@ -71,7 +71,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e9dd62f37dea550caf48c77591dc50bd1a378ce08855be1a0c42a97b7550fb"
dependencies = [
"android_log-sys",
"env_logger",
"env_logger 0.9.999",
"log",
"once_cell",
]
@ -1566,9 +1566,16 @@ dependencies = [
[[package]]
name = "env_logger"
version = "0.9.3"
version = "0.9.999"
dependencies = [
"env_logger 0.10.0",
]
[[package]]
name = "env_logger"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
dependencies = [
"log",
]
@ -2057,7 +2064,7 @@ name = "gecko_logger"
version = "0.1.0"
dependencies = [
"app_services_logger",
"env_logger",
"env_logger 0.9.999",
"lazy_static",
"log",
]
@ -2316,7 +2323,7 @@ dependencies = [
"bincode",
"chrono",
"crossbeam-channel",
"env_logger",
"env_logger 0.9.999",
"flate2",
"log",
"once_cell",
@ -3641,7 +3648,7 @@ version = "0.6.3"
source = "git+https://github.com/mozilla/neqo?tag=v0.6.3#4fe628bb911e4437169d974baa628c159e96f879"
dependencies = [
"chrono",
"env_logger",
"env_logger 0.9.999",
"lazy_static",
"log",
"qlog",
@ -3982,7 +3989,7 @@ version = "0.1.4"
dependencies = [
"byteorder",
"core-foundation",
"env_logger",
"env_logger 0.9.999",
"lazy_static",
"libloading",
"log",
@ -5002,7 +5009,7 @@ name = "smoosh"
version = "0.1.0"
dependencies = [
"bumpalo",
"env_logger",
"env_logger 0.9.999",
"jsparagus",
"log",
]

Просмотреть файл

@ -104,6 +104,9 @@ memmap2 = { path = "build/rust/memmap2" }
# Patch getrandom 0.7 to 0.8
rand = { path = "build/rust/rand" }
# Patch env_logger 0.9 to 0.10
env_logger = { path = "build/rust/env_logger" }
# Patch parking_lot 0.12 down to 0.11, which is compatible for most crates that use it, to avoid
# dependencies on windows-sys.
parking_lot = { path = "build/rust/parking_lot" }

Просмотреть файл

@ -0,0 +1,19 @@
[package]
name = "env_logger"
version = "0.9.999"
edition = "2018"
license = "MPL-2.0"
[lib]
path = "lib.rs"
[dependencies.env_logger]
version = "0.10"
default-features = false
[features]
default = ["env_logger/default"]
termcolor = ["env_logger/color"]
atty = ["env_logger/auto-color"]
humantime = ["env_logger/humantime"]
regex = ["env_logger/regex"]

Просмотреть файл

@ -0,0 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
pub use env_logger::*;

Просмотреть файл

@ -1 +1 @@
{"files":{"CHANGELOG.md":"34c3abc5bfaeb865e9b901c245f7e41f02a96b6be50beef5302458bff548ef3c","Cargo.toml":"a91f488aed0df3b4a1ddc1558f2b2fd05a543f9a37ce28e47548f8d9269ed979","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"c126e3dffb9c9e40c9355b5b0261ca84aa72425c5819bbe13abc40a161c51c78","src/filter/mod.rs":"92e7fd89ef1d5d46851de394a10349230045cb1e97f552f09f42031f372ab3dd","src/filter/regex.rs":"bdf875bac25e089e1e462f5dd01a88678067c24118ecd6268561c6a6af39747d","src/filter/string.rs":"fac54d51189fc0b5d2bff334b7a7e465177b431e3428299e345e1f90062d832e","src/fmt/humantime/extern_impl.rs":"97e0a128275c086b02760a33c22db8524f005994ebb1318a6ac582fd51cf444a","src/fmt/humantime/mod.rs":"f4111c26cf2ffb85c1d639bd7674d55af7e1736e7e98c52f7be3070046a3253f","src/fmt/humantime/shim_impl.rs":"cce9a252abd5952fa109a72b1dfb85a593d237e22606b2b608a32c69184560e9","src/fmt/mod.rs":"eb28817c0db5ed729f516927b981d0833cc3fe8bd2cf48256e03a04400d763df","src/fmt/writer/atty.rs":"09d14097dee61492828daaabdbde9f43251e2cb32e79d66c1c0e63f317761704","src/fmt/writer/mod.rs":"f3fb4adc740a1d9057bd398d751a9af24dead7ac108a8e2c571567778ce0f23e","src/fmt/writer/termcolor/extern_impl.rs":"4f02bdca6ad627856af1ac2eef0813104bd383685a2ff87983da9f7dee8261e3","src/fmt/writer/termcolor/mod.rs":"a790f9391a50cd52be6823e3e55942de13a8d12e23d63765342ae9e8dd6d091c","src/fmt/writer/termcolor/shim_impl.rs":"8e6e7d40782b14e33c6b75b81899a612549c2c7937ce28b48cdc60e1e3f8b855","src/lib.rs":"921561bf8d4efad4ab8938b36bc14e277968bfc364d131203822e64eb6e8265e","tests/init-twice-retains-filter.rs":"be5cd2132342d89ede1f5c4266173bb3c4d51cc22a1847f133d299a1c5430ccb","tests/log-in-log.rs":"29fecc65c1e0d1c22d79c97e7ca843ad44a91f27934148d7a05c48899a3f39d8","tests/log_tls_dtors.rs":"7320667d774a9b05037f7bf273fb2574dec0705707692a9cd2f46f4cd5bc68dd","tests/regexp_filter.rs":"a84263c995b534b6479a1d0abadf63f4f0264958ff86d9173d6b2139b82c4dc5"},"package":"a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"}
{"files":{"Cargo.lock":"a38131bba6684887371b472dec50908e55bfccf06eb3029b26e4dddc5ee55a7a","Cargo.toml":"4efdae82e55c1f6a72d80d9853dc2caab904e1ea822255418b78549e4d87fc89","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"c126e3dffb9c9e40c9355b5b0261ca84aa72425c5819bbe13abc40a161c51c78","examples/custom_default_format.rs":"a6fe2b9255248a19e2cac58033ac80ff1fbf78af9786a7331efcbafe469815a2","examples/custom_format.rs":"dbdf157c45a071e491cbe1038ad83d50a0154ea0691ee07dc4bd15fc1ca9205f","examples/custom_logger.rs":"d78a0998191b843bc902608dbb535c008ec53202528d7a626aaa0a2282a89494","examples/default.rs":"7ed1c6a8a8fe457a86676bd3a75c07d4ec7fb54147cf2825c9d299a5878a24cd","examples/direct_logger.rs":"5ae565fab0583c06de4cc3554fb4c8dc64cee8e2e1337b9aafff44e1bfb94e43","examples/filters_from_code.rs":"57edd53e811873c67b3069b4ea8fac619a0d5a507f6462ea4d0682bdf5d84a56","examples/in_tests.rs":"0b714146ab6f38d23394bfa5a5383fca2262a184a7628b8182d57b267e0917e7","examples/syslog_friendly_format.rs":"4269a86f549253bad54c7e8aae03d5ab09959a5c9d798d3fc6c4745cd5d96cd9","src/filter/mod.rs":"8c93f6ee0825ef537a554db0a6393c1c9334998852e9328b136058654a7bba1a","src/filter/regex.rs":"bdf875bac25e089e1e462f5dd01a88678067c24118ecd6268561c6a6af39747d","src/filter/string.rs":"fac54d51189fc0b5d2bff334b7a7e465177b431e3428299e345e1f90062d832e","src/fmt/humantime/extern_impl.rs":"97e0a128275c086b02760a33c22db8524f005994ebb1318a6ac582fd51cf444a","src/fmt/humantime/mod.rs":"f4111c26cf2ffb85c1d639bd7674d55af7e1736e7e98c52f7be3070046a3253f","src/fmt/humantime/shim_impl.rs":"cce9a252abd5952fa109a72b1dfb85a593d237e22606b2b608a32c69184560e9","src/fmt/mod.rs":"b4e23397f7b33df0c353339c4573901f259cfc222975c9f7bec1da0cfa50f159","src/fmt/writer/atty.rs":"098f4c358177d34b0d5a8202ac308f23b08a694b053557c6213f73ab29f8d96e","src/fmt/writer/mod.rs":"ba0723bfdbc5d5210dc59fe74de95affd038a7e15a9d9ca7a71b0413d77ff5bd","src/fmt/writer/termcolor/extern_impl.rs":"d3c0f1f8152b455cb7ac99cf29835ad1c8653d75b2873f1705517c0a45b3b549","src/fmt/writer/termcolor/mod.rs":"9c4e0ffea8ccffa87224af1dbf620483131bf346f86bd81233e4b69d872d1df6","src/fmt/writer/termcolor/shim_impl.rs":"8e6e7d40782b14e33c6b75b81899a612549c2c7937ce28b48cdc60e1e3f8b855","src/lib.rs":"90b2e514025283577be0e7d888746019cc755f0f490323237277e13a2e8d3fd2","tests/init-twice-retains-filter.rs":"be5cd2132342d89ede1f5c4266173bb3c4d51cc22a1847f133d299a1c5430ccb","tests/log-in-log.rs":"29fecc65c1e0d1c22d79c97e7ca843ad44a91f27934148d7a05c48899a3f39d8","tests/log_tls_dtors.rs":"7320667d774a9b05037f7bf273fb2574dec0705707692a9cd2f46f4cd5bc68dd","tests/regexp_filter.rs":"a84263c995b534b6479a1d0abadf63f4f0264958ff86d9173d6b2139b82c4dc5"},"package":"85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"}

3
third_party/rust/env_logger/CHANGELOG.md поставляемый
Просмотреть файл

@ -1,3 +0,0 @@
Changes to this crate are tracked via [GitHub Releases][releases].
[releases]: https://github.com/env-logger-rs/env_logger/releases

254
third_party/rust/env_logger/Cargo.lock сгенерированный поставляемый Normal file
Просмотреть файл

@ -0,0 +1,254 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
dependencies = [
"memchr",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cc"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "env_logger"
version = "0.10.0"
dependencies = [
"humantime",
"is-terminal",
"log",
"regex",
"termcolor",
]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
"libc",
]
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "io-lifetimes"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7d367024b3f3414d8e01f437f704f41a9f64ab36f9067fa73e526ad4c763c87"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "is-terminal"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae5bc6e2eb41c9def29a3e0f1306382807764b9b53112030eff57435667352d"
dependencies = [
"hermit-abi",
"io-lifetimes",
"rustix",
"windows-sys",
]
[[package]]
name = "libc"
version = "0.2.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
[[package]]
name = "linux-raw-sys"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "regex"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "rustix"
version = "0.36.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"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.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
[[package]]
name = "windows_i686_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
[[package]]
name = "windows_i686_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"

70
third_party/rust/env_logger/Cargo.toml поставляемый
Просмотреть файл

@ -10,21 +10,24 @@
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
edition = "2021"
rust-version = "1.60.0"
name = "env_logger"
version = "0.9.3"
version = "0.10.0"
include = [
"build.rs",
"src/**/*",
"tests",
"LICENSE-*",
"Cargo.toml",
"LICENSE*",
"README.md",
"CHANGELOG.md",
"tests/**/*",
"benches/**/*",
"examples/**/*",
]
description = """
A logging implementation for `log` which is configured via an environment
variable.
"""
documentation = "https://docs.rs/env_logger"
readme = "README.md"
keywords = [
"logging",
@ -33,7 +36,42 @@ keywords = [
]
categories = ["development-tools::debugging"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/env-logger-rs/env_logger/"
repository = "https://github.com/rust-cli/env_logger/"
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "Unreleased"
replace = "{{version}}"
min = 1
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = '\.\.\.HEAD'
replace = "...{{tag_name}}"
exactly = 1
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "ReleaseDate"
replace = "{{date}}"
min = 1
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "<!-- next-header -->"
replace = """
<!-- next-header -->
## [Unreleased] - ReleaseDate
"""
exactly = 1
[[package.metadata.release.pre-release-replacements]]
file = "CHANGELOG.md"
search = "<!-- next-url -->"
replace = """
<!-- next-url -->
[Unreleased]: https://github.com/rust-cli/env_logger/compare/{{tag_name}}...HEAD"""
exactly = 1
[[test]]
name = "regexp_filter"
@ -51,14 +89,14 @@ harness = false
name = "init-twice-retains-filter"
harness = false
[dependencies.atty]
version = "0.2.5"
optional = true
[dependencies.humantime]
version = "2.0.0"
optional = true
[dependencies.is-terminal]
version = "0.4.0"
optional = true
[dependencies.log]
version = "0.4.8"
features = ["std"]
@ -77,9 +115,15 @@ version = "1.1.1"
optional = true
[features]
auto-color = [
"dep:is-terminal",
"color",
]
color = ["dep:termcolor"]
default = [
"termcolor",
"atty",
"auto-color",
"humantime",
"regex",
]
humantime = ["dep:humantime"]
regex = ["dep:regex"]

40
third_party/rust/env_logger/examples/custom_default_format.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,40 @@
/*!
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");
Builder::from_env(env)
.format_level(false)
.format_timestamp_nanos()
.init();
}
fn main() {
init_logger();
info!("a log from `MyLogger`");
}

54
third_party/rust/env_logger/examples/custom_format.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,54 @@
/*!
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 = "color", feature = "humantime"))]
fn main() {
use env_logger::{fmt::Color, 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(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 = "color", feature = "humantime")))]
fn main() {}

62
third_party/rust/env_logger/examples/custom_logger.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,62 @@
/*!
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::{Builder, Filter};
use log::{Log, Metadata, Record, SetLoggerError};
const FILTER_ENV: &str = "MY_LOG_LEVEL";
struct MyLogger {
inner: Filter,
}
impl MyLogger {
fn new() -> MyLogger {
let mut builder = Builder::from_env(FILTER_ENV);
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`");
}

38
third_party/rust/env_logger/examples/default.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,38 @@
/*!
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");
}

39
third_party/rust/env_logger/examples/direct_logger.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,39 @@
/*!
Using `env_logger::Logger` and the `log::Log` trait directly.
This example doesn't rely on environment variables, or having a static logger installed.
*/
use env_logger::{Builder, WriteStyle};
use log::{Level, LevelFilter, Log, MetadataBuilder, Record};
fn record() -> Record<'static> {
let error_metadata = MetadataBuilder::new()
.target("myApp")
.level(Level::Error)
.build();
Record::builder()
.metadata(error_metadata)
.args(format_args!("Error!"))
.line(Some(433))
.file(Some("app.rs"))
.module_path(Some("server"))
.build()
}
fn main() {
let stylish_logger = Builder::new()
.filter(None, LevelFilter::Error)
.write_style(WriteStyle::Always)
.build();
let unstylish_logger = Builder::new()
.filter(None, LevelFilter::Error)
.write_style(WriteStyle::Never)
.build();
stylish_logger.log(&record());
unstylish_logger.log(&record());
}

20
third_party/rust/env_logger/examples/filters_from_code.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,20 @@
/*!
Specify logging filters in code instead of using an environment variable.
*/
#[macro_use]
extern crate log;
use env_logger::Builder;
use log::LevelFilter;
fn main() {
Builder::new().filter_level(LevelFilter::max()).init();
trace!("some trace log");
debug!("some debug log");
info!("some information log");
warn!("some warning log");
error!("some error log");
}

54
third_party/rust/env_logger/examples/in_tests.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,54 @@
/*!
Using `env_logger` in tests.
Log events will be captured by `cargo` and only printed if the test fails.
You can run this example by calling:
```text
cargo test --example in_tests
```
You should see the `it_does_not_work` test fail and include its log output.
*/
#[cfg_attr(test, macro_use)]
extern crate log;
fn main() {}
#[cfg(test)]
mod tests {
fn init_logger() {
let _ = env_logger::builder()
// Include all events in tests
.filter_level(log::LevelFilter::max())
// Ensure events are captured by `cargo test`
.is_test(true)
// Ignore errors initializing the logger if tests race to configure it
.try_init();
}
#[test]
fn it_works() {
init_logger();
let a = 1;
let b = 2;
debug!("checking whether {} + {} = 3", a, b);
assert_eq!(3, a + b);
}
#[test]
fn it_does_not_work() {
init_logger();
let a = 1;
let b = 2;
debug!("checking whether {} + {} = 6", a, b);
assert_eq!(6, a + b);
}
}

24
third_party/rust/env_logger/examples/syslog_friendly_format.rs поставляемый Normal file
Просмотреть файл

@ -0,0 +1,24 @@
use std::io::Write;
fn main() {
match std::env::var("RUST_LOG_STYLE") {
Ok(s) if s == "SYSTEMD" => env_logger::builder()
.format(|buf, record| {
writeln!(
buf,
"<{}>{}: {}",
match record.level() {
log::Level::Error => 3,
log::Level::Warn => 4,
log::Level::Info => 6,
log::Level::Debug => 7,
log::Level::Trace => 7,
},
record.target(),
record.args()
)
})
.init(),
_ => env_logger::init(),
};
}

Просмотреть файл

@ -762,7 +762,7 @@ mod tests {
#[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
// so a comma-only string should be interpreted 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);
@ -772,7 +772,7 @@ mod tests {
#[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
// so this bogus spec should be interpreted 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
@ -783,7 +783,7 @@ mod tests {
#[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
// so this bogus spec should be interpreted 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

12
third_party/rust/env_logger/src/fmt/mod.rs поставляемый
Просмотреть файл

@ -202,9 +202,9 @@ impl Builder {
}
}
#[cfg(feature = "termcolor")]
#[cfg(feature = "color")]
type SubtleStyle = StyledValue<'static, &'static str>;
#[cfg(not(feature = "termcolor"))]
#[cfg(not(feature = "color"))]
type SubtleStyle = &'static str;
/// The default format.
@ -233,7 +233,7 @@ impl<'a> DefaultFormat<'a> {
}
fn subtle_style(&self, text: &'static str) -> SubtleStyle {
#[cfg(feature = "termcolor")]
#[cfg(feature = "color")]
{
self.buf
.style()
@ -242,7 +242,7 @@ impl<'a> DefaultFormat<'a> {
.clone()
.into_value(text)
}
#[cfg(not(feature = "termcolor"))]
#[cfg(not(feature = "color"))]
{
text
}
@ -268,11 +268,11 @@ impl<'a> DefaultFormat<'a> {
}
let level = {
#[cfg(feature = "termcolor")]
#[cfg(feature = "color")]
{
self.buf.default_styled_level(record.level())
}
#[cfg(not(feature = "termcolor"))]
#[cfg(not(feature = "color"))]
{
record.level()
}

Просмотреть файл

@ -1,24 +1,25 @@
/*
This internal module contains the terminal detection implementation.
If the `atty` crate is available then we use it to detect whether we're
attached to a particular TTY. If the `atty` crate is not available we
assume we're not attached to anything. This effectively prevents styles
from being printed.
If the `auto-color` feature is enabled then we detect whether we're attached to a particular TTY.
Otherwise, assume we're not attached to anything. This effectively prevents styles from being
printed.
*/
#[cfg(feature = "atty")]
#[cfg(feature = "auto-color")]
mod imp {
use is_terminal::IsTerminal;
pub(in crate::fmt) fn is_stdout() -> bool {
atty::is(atty::Stream::Stdout)
std::io::stdout().is_terminal()
}
pub(in crate::fmt) fn is_stderr() -> bool {
atty::is(atty::Stream::Stderr)
std::io::stderr().is_terminal()
}
}
#[cfg(not(feature = "atty"))]
#[cfg(not(feature = "auto-color"))]
mod imp {
pub(in crate::fmt) fn is_stdout() -> bool {
false

Просмотреть файл

@ -165,6 +165,7 @@ impl Builder {
}
/// Whether or not to capture logs for `cargo test`.
#[allow(clippy::wrong_self_convention)]
pub(crate) fn is_test(&mut self, is_test: bool) -> &mut Self {
self.is_test = is_test;
self

Просмотреть файл

@ -107,7 +107,7 @@ impl BufferWriter {
pipe: Box<Mutex<dyn io::Write + Send + 'static>>,
) -> Self {
BufferWriter {
// The inner Buffer is never printed from, but it is still needed to handle coloring and other formating
// The inner Buffer is never printed from, but it is still needed to handle coloring and other formatting
inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()),
uncolored_target: Some(WritableTarget::Pipe(pipe)),
}

Просмотреть файл

@ -5,8 +5,8 @@ Its public API is available when the `termcolor` crate is available.
The terminal printing is shimmed when the `termcolor` crate is not available.
*/
#[cfg_attr(feature = "termcolor", path = "extern_impl.rs")]
#[cfg_attr(not(feature = "termcolor"), path = "shim_impl.rs")]
#[cfg_attr(feature = "color", path = "extern_impl.rs")]
#[cfg_attr(not(feature = "color"), path = "shim_impl.rs")]
mod imp;
pub(in crate::fmt) use self::imp::*;

6
third_party/rust/env_logger/src/lib.rs поставляемый
Просмотреть файл

@ -97,7 +97,7 @@
//! ```
//!
//! The log target is typically equal to the path of the module the message
//! in question originated from, though it can be overriden.
//! in question originated from, though it can be overridden.
//!
//! 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
@ -907,7 +907,7 @@ impl Log for Logger {
fn log(&self, record: &Record) {
if self.matches(record) {
// Log records are written to a thread-local buffer before being printed
// to the terminal. We clear these buffers afterwards, but they aren't shrinked
// to the terminal. We clear these buffers afterwards, but they aren't shrunk
// so will always at least have capacity for the largest log record formatted
// on that thread.
//
@ -1168,7 +1168,7 @@ pub fn init() {
/// ```
/// use env_logger::{Builder, Env};
///
/// # fn run() -> Result<(), Box<::std::error::Error>> {
/// # fn run() -> Result<(), Box<dyn ::std::error::Error>> {
/// let env = Env::new().filter("MY_LOG").write_style("MY_LOG_STYLE");
///
/// env_logger::try_init_from_env(env)?;