feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support: - Splash screen on boot (1.5s) with project name, version, board - Dashboard showing radio state, config, counters, RSSI/SNR - RSSI history sparkline (64-sample ring buffer, 2px-wide bars) - DisplayOn/DisplayOff host commands routed via dedicated channel - Pure render functions against generic DrawTarget (no hardware coupling) - Display on/off control bypasses radio task entirely Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
17624 files changed
+4564928
-38
No files matched your search
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"files":{".cargo_vcs_info.json":"fe75b2d660e4f5cecfc6e8926b75370a30752399a8d0293a90902fcd3be8caaa",".github/workflows/main.yml":"ec945c9615b558fa1125e012369675daa107997389f25ad70d923898aaf2dd0c","CHANGELOG.md":"a216e6550df9437781c01c09783c59276245b0121d3d39b874675148d412d361","Cargo.lock":"7439a99151c8c47a4df860560ff30531aff5fb80dc7583d3e25652da288b1a38","Cargo.toml":"1471858c37a27ccb84d7274816ead00082c0e4acbbb28acc547a6329e3bdaf22","Cargo.toml.orig":"f9bcbe8c7872abcca77b6a3f8b0346835c17326baa861fa8a0f47b2c9d957ef1","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"486c6cf85f99a2a3ea14dbd5fc6d6075fdc047a0dbf2b93682595db0de6a115f","benches/value.rs":"b613ff353d3cf0ef8cb98e4ca461ea929b8ba553fe299f2eb2942d77a5b1b6a0","src/__private_api.rs":"c1b8541fe7b7906a654ad1c23a643c516a3b735de4fbd1d07ca7a7a5754b74ac","src/kv/error.rs":"6dae12424164c33b93915f5e70bd6d99d616c969c8bfb543806721dd9b423981","src/kv/key.rs":"9037de97791fa0fb6def6c44ada324351d10ed0f4db8015c9ac4e90504141b87","src/kv/mod.rs":"a62c4dbfbcf28fc755c3662ea4a1e79268edc15311d5ca97b7f0325cc2dfb43f","src/kv/source.rs":"0f7c3a89c8998fe3805ae35f3e87778bca30a444da9f67964e674028f7864625","src/kv/value.rs":"b6df78e50ca912f2d97fdb1155408b538669e5be237b1f9471f9443c9d01f748","src/lib.rs":"5f47680950577eb5213a99b022f7789c2cf22dc3d6ddacda94a54f8e035c6ca2","src/macros.rs":"34c367a645483e21eee4c7846d0efbf97c29a52156d56536c82cdfe1d226a54d","src/serde.rs":"ead8df70c3ca3fafeed062f7a42d9b6f87bc7826055d71d8c4b77a0a25b57634","tests/integration.rs":"0980b3bd85d36863bc9f355e80bc7cf7987d2599adbc87e8e0082861a08a1097","tests/macros.rs":"a94f3cc181c9ecb30af6b5ca8bd2b4e5accc93689c0eb19051b8479a298dc21b","triagebot.toml":"a135e10c777cd13459559bdf74fb704c1379af7c9b0f70bc49fa6f5a837daa81"},"package":"5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "b1e2df7bce7a1b685aa9bfd1db0a5cac1f0fc27d"
|
||||
},
|
||||
"path_in_vcs": ""
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
name: CI
|
||||
on: [push, pull_request]
|
||||
|
||||
# Ensure only read permission is granted
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- build: stable
|
||||
os: ubuntu-latest
|
||||
rust: stable
|
||||
- build: beta
|
||||
os: ubuntu-latest
|
||||
rust: beta
|
||||
- build: nightly
|
||||
os: ubuntu-latest
|
||||
rust: nightly
|
||||
- build: macos
|
||||
os: macos-latest
|
||||
rust: stable
|
||||
- build: win32
|
||||
os: windows-latest
|
||||
rust: stable-i686-pc-windows-msvc
|
||||
- build: win64
|
||||
os: windows-latest
|
||||
rust: stable-x86_64-pc-windows-msvc
|
||||
- build: mingw
|
||||
os: windows-latest
|
||||
rust: stable-x86_64-pc-windows-gnu
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
- uses: taiki-e/install-action@cargo-hack
|
||||
- run: cargo hack test --feature-powerset --exclude-features max_level_off,max_level_error,max_level_warn,max_level_info,max_level_debug,max_level_trace,release_max_level_off,release_max_level_error,release_max_level_warn,release_max_level_info,release_max_level_debug,release_max_level_trace
|
||||
- run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml
|
||||
- run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml --release
|
||||
|
||||
check:
|
||||
name: Check Format and Clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
components: clippy
|
||||
- run: cargo fmt -- --check
|
||||
- run: cargo fmt --manifest-path test_max_level_features/Cargo.toml -- --check
|
||||
- run: cargo clippy --verbose
|
||||
- run: cargo clippy --verbose --manifest-path test_max_level_features/Cargo.toml
|
||||
|
||||
doc:
|
||||
name: Check Documentation
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- name: Run rustdoc
|
||||
env:
|
||||
RUSTDOCFLAGS: "-D warnings"
|
||||
run: cargo doc --verbose --features std,kv,kv_std,kv_sval,kv_serde
|
||||
|
||||
features:
|
||||
name: Feature check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- run: cargo build --verbose -Z avoid-dev-deps --features kv
|
||||
- run: cargo build --verbose -Z avoid-dev-deps --features "kv std"
|
||||
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_sval"
|
||||
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_serde"
|
||||
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_std"
|
||||
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_sval kv_serde"
|
||||
|
||||
minimalv:
|
||||
name: Minimal versions
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@nightly
|
||||
- run: cargo build --verbose -Z minimal-versions --features kv
|
||||
- run: cargo build --verbose -Z minimal-versions --features "kv std"
|
||||
- run: cargo build --verbose -Z minimal-versions --features "kv kv_sval"
|
||||
- run: cargo build --verbose -Z minimal-versions --features "kv kv_serde"
|
||||
- run: cargo build --verbose -Z minimal-versions --features "kv kv_std"
|
||||
- run: cargo build --verbose -Z minimal-versions --features "kv kv_sval kv_serde"
|
||||
|
||||
msrv:
|
||||
name: MSRV
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@1.68.0
|
||||
with:
|
||||
components: clippy
|
||||
- uses: taiki-e/install-action@cargo-hack
|
||||
- run: cargo hack test --feature-powerset --exclude-features max_level_off,max_level_error,max_level_warn,max_level_info,max_level_debug,max_level_trace,release_max_level_off,release_max_level_error,release_max_level_warn,release_max_level_info,release_max_level_debug,release_max_level_trace
|
||||
- run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml
|
||||
- run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml --release
|
||||
|
||||
embedded:
|
||||
name: Embedded
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- run: rustup target add thumbv6m-none-eabi riscv32imc-unknown-none-elf
|
||||
- run: cargo build --verbose --target=thumbv6m-none-eabi
|
||||
- run: cargo build --verbose --target=riscv32imc-unknown-none-elf
|
||||
Vendored
+423
@@ -0,0 +1,423 @@
|
||||
# Change Log
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.4.29] - 2025-12-02
|
||||
|
||||
## What's Changed
|
||||
* perf: reduce llvm-lines of FromStr for `Level` and `LevelFilter` by @dishmaker in https://github.com/rust-lang/log/pull/709
|
||||
* Replace serde with serde_core by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/712
|
||||
|
||||
## New Contributors
|
||||
* @AldaronLau made their first contribution in https://github.com/rust-lang/log/pull/703
|
||||
* @dishmaker made their first contribution in https://github.com/rust-lang/log/pull/709
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.28...0.4.29
|
||||
|
||||
## [0.4.28] - 2025-09-02
|
||||
|
||||
## What's Changed
|
||||
* ci: drop really old trick and ensure MSRV for all feature combo by @tisonkun in https://github.com/rust-lang/log/pull/676
|
||||
* Chore: delete compare_exchange method for AtomicUsize on platforms without atomics by @HaoliangXu in https://github.com/rust-lang/log/pull/690
|
||||
* Add `increment_severity()` and `decrement_severity()` methods for `Level` and `LevelFilter` by @nebkor in https://github.com/rust-lang/log/pull/692
|
||||
|
||||
## New Contributors
|
||||
* @xixishidibei made their first contribution in https://github.com/rust-lang/log/pull/677
|
||||
* @ZylosLumen made their first contribution in https://github.com/rust-lang/log/pull/688
|
||||
* @HaoliangXu made their first contribution in https://github.com/rust-lang/log/pull/690
|
||||
* @nebkor made their first contribution in https://github.com/rust-lang/log/pull/692
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.27...0.4.28
|
||||
|
||||
### Notable Changes
|
||||
* MSRV is bumped to 1.61.0 in https://github.com/rust-lang/log/pull/676
|
||||
|
||||
## [0.4.27] - 2025-03-24
|
||||
|
||||
### What's Changed
|
||||
* A few minor lint fixes by @nyurik in https://github.com/rust-lang/log/pull/671
|
||||
* Enable clippy support for format-like macros by @nyurik in https://github.com/rust-lang/log/pull/665
|
||||
* Add an optional logger param by @tisonkun in https://github.com/rust-lang/log/pull/664
|
||||
* Pass global logger by value, supplied logger by ref by @KodrAus in https://github.com/rust-lang/log/pull/673
|
||||
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.26...0.4.27
|
||||
|
||||
|
||||
## [0.4.26] - 2025-02-18
|
||||
|
||||
### What's Changed
|
||||
* Derive `Clone` for `kv::Value` by @SpriteOvO in https://github.com/rust-lang/log/pull/668
|
||||
* Add `spdlog-rs` link to crate doc by @SpriteOvO in https://github.com/rust-lang/log/pull/669
|
||||
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.25...0.4.26
|
||||
|
||||
## [0.4.25] - 2025-01-14
|
||||
|
||||
### What's Changed
|
||||
* Revert loosening of kv cargo features by @KodrAus in https://github.com/rust-lang/log/pull/662
|
||||
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.24...0.4.25
|
||||
|
||||
## [0.4.24] - 2025-01-11
|
||||
|
||||
### What's Changed
|
||||
* Fix up kv feature activation by @KodrAus in https://github.com/rust-lang/log/pull/659
|
||||
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.23...0.4.24
|
||||
|
||||
## [0.4.23] - 2025-01-10 (yanked)
|
||||
|
||||
### What's Changed
|
||||
* Fix some typos by @Kleinmarb in https://github.com/rust-lang/log/pull/637
|
||||
* Add logforth to implementation by @tisonkun in https://github.com/rust-lang/log/pull/638
|
||||
* Add `spdlog-rs` link to README by @SpriteOvO in https://github.com/rust-lang/log/pull/639
|
||||
* Add correct lifetime to kv::Value::to_borrowed_str by @stevenroose in https://github.com/rust-lang/log/pull/643
|
||||
* docs: Add logforth as an impl by @tisonkun in https://github.com/rust-lang/log/pull/642
|
||||
* Add clang_log implementation by @DDAN-17 in https://github.com/rust-lang/log/pull/646
|
||||
* Bind lifetimes of &str returned from Key by the lifetime of 'k rather than the lifetime of the Key struct by @gbbosak in https://github.com/rust-lang/log/pull/648
|
||||
* Fix up key lifetimes and add method to try get a borrowed key by @KodrAus in https://github.com/rust-lang/log/pull/653
|
||||
* Add Ftail implementation by @tjardoo in https://github.com/rust-lang/log/pull/652
|
||||
|
||||
### New Contributors
|
||||
* @Kleinmarb made their first contribution in https://github.com/rust-lang/log/pull/637
|
||||
* @tisonkun made their first contribution in https://github.com/rust-lang/log/pull/638
|
||||
* @SpriteOvO made their first contribution in https://github.com/rust-lang/log/pull/639
|
||||
* @stevenroose made their first contribution in https://github.com/rust-lang/log/pull/643
|
||||
* @DDAN-17 made their first contribution in https://github.com/rust-lang/log/pull/646
|
||||
* @gbbosak made their first contribution in https://github.com/rust-lang/log/pull/648
|
||||
* @tjardoo made their first contribution in https://github.com/rust-lang/log/pull/652
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.22...0.4.23
|
||||
|
||||
## [0.4.22] - 2024-06-27
|
||||
|
||||
### What's Changed
|
||||
* Add some clarifications to the library docs by @KodrAus in https://github.com/rust-lang/log/pull/620
|
||||
* Add links to `colog` crate by @chrivers in https://github.com/rust-lang/log/pull/621
|
||||
* adding line_number test + updating some testing infrastructure by @DIvkov575 in https://github.com/rust-lang/log/pull/619
|
||||
* Clarify the actual set of functions that can race in _racy variants by @KodrAus in https://github.com/rust-lang/log/pull/623
|
||||
* Replace deprecated std::sync::atomic::spin_loop_hint() by @Catamantaloedis in https://github.com/rust-lang/log/pull/625
|
||||
* Check usage of max_level features by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/627
|
||||
* Remove unneeded import by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/628
|
||||
* Loosen orderings for logger initialization in https://github.com/rust-lang/log/pull/632. Originally by @pwoolcoc in https://github.com/rust-lang/log/pull/599
|
||||
* Use Location::caller() for file and line info in https://github.com/rust-lang/log/pull/633. Originally by @Cassy343 in https://github.com/rust-lang/log/pull/520
|
||||
|
||||
### New Contributors
|
||||
* @chrivers made their first contribution in https://github.com/rust-lang/log/pull/621
|
||||
* @DIvkov575 made their first contribution in https://github.com/rust-lang/log/pull/619
|
||||
* @Catamantaloedis made their first contribution in https://github.com/rust-lang/log/pull/625
|
||||
|
||||
**Full Changelog**: https://github.com/rust-lang/log/compare/0.4.21...0.4.22
|
||||
|
||||
## [0.4.21] - 2024-02-27
|
||||
|
||||
### What's Changed
|
||||
* Minor clippy nits by @nyurik in https://github.com/rust-lang/log/pull/578
|
||||
* Simplify Display impl by @nyurik in https://github.com/rust-lang/log/pull/579
|
||||
* Set all crates to 2021 edition by @nyurik in https://github.com/rust-lang/log/pull/580
|
||||
* Various changes based on review by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/583
|
||||
* Fix typo in file_static() method doc by @dimo414 in https://github.com/rust-lang/log/pull/590
|
||||
* Specialize empty key value pairs by @EFanZh in https://github.com/rust-lang/log/pull/576
|
||||
* Fix incorrect lifetime in Value::to_str() by @peterjoel in https://github.com/rust-lang/log/pull/587
|
||||
* Remove some API of the key-value feature by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/585
|
||||
* Add logcontrol-log and log-reload by @swsnr in https://github.com/rust-lang/log/pull/595
|
||||
* Add Serialization section to kv::Value docs by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/593
|
||||
* Rename Value::to_str to to_cow_str by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/592
|
||||
* Clarify documentation and simplify initialization of `STATIC_MAX_LEVEL` by @ptosi in https://github.com/rust-lang/log/pull/594
|
||||
* Update docs to 2021 edition, test by @nyurik in https://github.com/rust-lang/log/pull/577
|
||||
* Add "alterable_logger" link to README.md by @brummer-simon in https://github.com/rust-lang/log/pull/589
|
||||
* Normalize line ending by @EFanZh in https://github.com/rust-lang/log/pull/602
|
||||
* Remove `ok_or` in favor of `Option::ok_or` by @AngelicosPhosphoros in https://github.com/rust-lang/log/pull/607
|
||||
* Use `Acquire` ordering for initialization check by @AngelicosPhosphoros in https://github.com/rust-lang/log/pull/610
|
||||
* Get structured logging API ready for stabilization by @KodrAus in https://github.com/rust-lang/log/pull/613
|
||||
|
||||
### New Contributors
|
||||
* @nyurik made their first contribution in https://github.com/rust-lang/log/pull/578
|
||||
* @dimo414 made their first contribution in https://github.com/rust-lang/log/pull/590
|
||||
* @peterjoel made their first contribution in https://github.com/rust-lang/log/pull/587
|
||||
* @ptosi made their first contribution in https://github.com/rust-lang/log/pull/594
|
||||
* @brummer-simon made their first contribution in https://github.com/rust-lang/log/pull/589
|
||||
* @AngelicosPhosphoros made their first contribution in https://github.com/rust-lang/log/pull/607
|
||||
|
||||
## [0.4.20] - 2023-07-11
|
||||
|
||||
* Remove rustversion dev-dependency by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/568
|
||||
* Remove `local_inner_macros` usage by @EFanZh in https://github.com/rust-lang/log/pull/570
|
||||
|
||||
## [0.4.19] - 2023-06-10
|
||||
|
||||
* Use target_has_atomic instead of the old atomic_cas cfg by @GuillaumeGomez in https://github.com/rust-lang/log/pull/555
|
||||
* Put MSRV into Cargo.toml by @est31 in https://github.com/rust-lang/log/pull/557
|
||||
|
||||
## [0.4.18] - 2023-05-28
|
||||
|
||||
* fix Markdown links (again) by @hellow554 in https://github.com/rust-lang/log/pull/513
|
||||
* add cargo doc to workflow by @hellow554 in https://github.com/rust-lang/log/pull/515
|
||||
* Apply Clippy lints by @hellow554 in https://github.com/rust-lang/log/pull/516
|
||||
* Replace ad-hoc eq_ignore_ascii_case with slice::eq_ignore_ascii_case by @glandium in https://github.com/rust-lang/log/pull/519
|
||||
* fix up windows targets by @KodrAus in https://github.com/rust-lang/log/pull/528
|
||||
* typo fix by @jiangying000 in https://github.com/rust-lang/log/pull/529
|
||||
* Remove dependency on cfg_if by @EriKWDev in https://github.com/rust-lang/log/pull/536
|
||||
* GitHub Workflows security hardening by @sashashura in https://github.com/rust-lang/log/pull/538
|
||||
* Fix build status badge by @atouchet in https://github.com/rust-lang/log/pull/539
|
||||
* Add call_logger to the documentation by @a1ecbr0wn in https://github.com/rust-lang/log/pull/547
|
||||
* Use stable internals for key-value API by @KodrAus in https://github.com/rust-lang/log/pull/550
|
||||
* Change wording of list of implementations by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/553
|
||||
* Add std-logger to list of implementations by @Thomasdezeeuw in https://github.com/rust-lang/log/pull/554
|
||||
* Add `set_max_level_racy` and gate `set_max_level` by @djkoloski in https://github.com/rust-lang/log/pull/544
|
||||
* [doc] src/lib.rs : prefix an unused variable with an underscore by @OccupyMars2025 in https://github.com/rust-lang/log/pull/561
|
||||
* [doc] src/macros.rs : correct grammar errors of an example in lib documentation by @OccupyMars2025 in https://github.com/rust-lang/log/pull/562
|
||||
|
||||
## [0.4.17] - 2022-04-29
|
||||
|
||||
* Update `kv_unstable` internal dependencies.
|
||||
|
||||
## [0.4.16] - 2022-03-22
|
||||
|
||||
* Fix a conflict with unqualified `Option` use in macros.
|
||||
|
||||
## [0.4.15] - 2022-02-23
|
||||
|
||||
* Silence a warning about the deprecated `spin_loop_hint`.
|
||||
* Relax ordering in the atomic `set_max_level` call.
|
||||
* Add thumbv4t-none-eabi to targets that don't support atomics
|
||||
* Allow levels to be iterated over.
|
||||
* Implement `Log` on some common wrapper types.
|
||||
* Improvements to test coverage.
|
||||
* Improvements to documentation.
|
||||
* Add key-value support to the `log!` macros.
|
||||
* Tighten `kv_unstable` internal dependencies, so they don't bump past their current alpha.
|
||||
* Add a simple visit API to `kv_unstable`.
|
||||
* Support `NonZero*` integers as values in structured logging
|
||||
* Support static strings as keys in structured logging
|
||||
|
||||
## [0.4.14] - 2021-01-27
|
||||
|
||||
* Remove the `__private_api_log_lit` special case.
|
||||
* Fixed incorrect combination of `kv_unstable` and `std` features causing compile failures.
|
||||
* Remove unstable `Value::to_*` conversions that were incorrectly using `as`.
|
||||
* Rename unstable `Value::to_error` to `Value::to_borrowed_error`.
|
||||
|
||||
## [0.4.13] - 2021-01-11
|
||||
|
||||
* This is the same as `0.4.11`, except with a `kv_unstable_std` feature added to aid migrating current dependents to `0.4.14` (which was originally going to be `0.4.13` until it was decided to create a patch from `0.4.11` to minimize disruption).
|
||||
|
||||
## [0.4.12] - 2020-12-24
|
||||
|
||||
### New
|
||||
|
||||
* Support platforms without atomics by racing instead of failing to compile
|
||||
* Implement `Log` for `Box<T: Log>`
|
||||
* Update `cfg-if` to `1.0`
|
||||
* Internal reworks of the structured logging API. Removed the `Fill` API
|
||||
and added `source::as_map` and `source::as_list` to easily serialize a `Source`
|
||||
as either a map of `{key: value, ..}` or as a list of `[(key, value), ..]`.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed deserialization of `LevelFilter` to use their `u64` index variants
|
||||
|
||||
## [0.4.11] - 2020-07-09
|
||||
|
||||
### New
|
||||
|
||||
* Support coercing structured values into concrete types.
|
||||
* Reference the `win_dbg_logger` in the readme.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Updates a few deprecated items used internally.
|
||||
* Fixed issues in docs and expands sections.
|
||||
* Show the correct build badge in the readme.
|
||||
* Fix up a possible inference breakage with structured value errors.
|
||||
* Respect formatting flags in structured value formatting.
|
||||
|
||||
## [0.4.10] - 2019-12-16 (yanked)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed the `log!` macros, so they work in expression context (this regressed in `0.4.9`, which has been yanked).
|
||||
|
||||
## [0.4.9] - 2019-12-12 (yanked)
|
||||
|
||||
### Minimum Supported Rust Version
|
||||
|
||||
This release bumps the minimum compiler version to `1.31.0`. This was mainly needed for `cfg-if`,
|
||||
but between `1.16.0` and `1.31.0` there are a lot of language and library improvements we now
|
||||
take advantage of.
|
||||
|
||||
### New
|
||||
|
||||
* Unstable support for capturing key-value pairs in a record using the `log!` macros
|
||||
|
||||
### Improved
|
||||
|
||||
* Better documentation for max level filters.
|
||||
* Internal updates to line up with bumped MSRV
|
||||
|
||||
## [0.4.8] - 2019-07-28
|
||||
|
||||
### New
|
||||
|
||||
* Support attempting to get `Record` fields as static strings.
|
||||
|
||||
## [0.4.7] - 2019-07-06
|
||||
|
||||
### New
|
||||
|
||||
* Support for embedded environments with thread-unsafe initialization.
|
||||
* Initial unstable support for capturing structured data under the `kv_unstable`
|
||||
feature gate. This new API doesn't affect existing users and may change in future
|
||||
patches (so those changes may not appear in the changelog until it stabilizes).
|
||||
|
||||
### Improved
|
||||
|
||||
* Docs for using `log` with the 2018 edition.
|
||||
* Error messages for macros missing arguments.
|
||||
|
||||
## [0.4.6] - 2018-10-27
|
||||
|
||||
### Improved
|
||||
|
||||
* Support 2018-style macro import for the `log_enabled!` macro.
|
||||
|
||||
## [0.4.5] - 2018-09-03
|
||||
|
||||
### Improved
|
||||
|
||||
* Make `log`'s internal helper macros less likely to conflict with user-defined
|
||||
macros.
|
||||
|
||||
## [0.4.4] - 2018-08-17
|
||||
|
||||
### Improved
|
||||
|
||||
* Support 2018-style imports of the log macros.
|
||||
|
||||
## [0.4.3] - 2018-06-29
|
||||
|
||||
### Improved
|
||||
|
||||
* More code generation improvements.
|
||||
|
||||
## [0.4.2] - 2018-06-05
|
||||
|
||||
### Improved
|
||||
|
||||
* Log invocations now generate less code.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Example Logger implementations now properly set the max log level.
|
||||
|
||||
## [0.4.1] - 2017-12-30
|
||||
|
||||
### Fixed
|
||||
|
||||
* Some doc links were fixed.
|
||||
|
||||
## [0.4.0] - 2017-12-24
|
||||
|
||||
The changes in this release include cleanup of some obscure functionality and a more robust public
|
||||
API designed to support bridges to other logging systems, and provide more flexibility to new
|
||||
features in the future.
|
||||
|
||||
### Compatibility
|
||||
|
||||
Vast portions of the Rust ecosystem use the 0.3.x release series of log, and we don't want to force
|
||||
the community to go through the pain of upgrading every crate to 0.4.x at the exact same time. Along
|
||||
with 0.4.0, we've published a new 0.3.9 release which acts as a "shim" over 0.4.0. This will allow
|
||||
crates using either version to coexist without losing messages from one side or the other.
|
||||
|
||||
There is one caveat - a log message generated by a crate using 0.4.x but consumed by a logging
|
||||
implementation using 0.3.x will not have a file name or module path. Applications affected by this
|
||||
can upgrade their logging implementations to one using 0.4.x to avoid losing this information. The
|
||||
other direction does not lose any information, fortunately!
|
||||
|
||||
**TL;DR** Libraries should feel comfortable upgrading to 0.4.0 without treating that as a breaking
|
||||
change. Applications may need to update their logging implementation (e.g. env-logger) to a newer
|
||||
version using log 0.4.x to avoid losing module and file information.
|
||||
|
||||
### New
|
||||
|
||||
* The crate is now `no_std` by default.
|
||||
* `Level` and `LevelFilter` now implement `Serialize` and `Deserialize` when the `serde` feature is
|
||||
enabled.
|
||||
* The `Record` and `Metadata` types can now be constructed by third-party code via a builder API.
|
||||
* The `logger` free function returns a reference to the logger implementation. This, along with the
|
||||
ability to construct `Record`s, makes it possible to bridge from another logging framework to
|
||||
this one without digging into the private internals of the crate. The standard `error!` `warn!`,
|
||||
etc., macros now exclusively use the public API of the crate rather than "secret" internal APIs.
|
||||
* `Log::flush` has been added to allow crates to tell the logging implementation to ensure that all
|
||||
"in flight" log events have been persisted. This can be used, for example, just before an
|
||||
application exits to ensure that asynchronous log sinks finish their work.
|
||||
|
||||
### Removed
|
||||
|
||||
* The `shutdown` and `shutdown_raw` functions have been removed. Supporting shutdown significantly
|
||||
complicated the implementation and imposed a performance cost on each logging operation.
|
||||
* The `log_panics` function and its associated `nightly` Cargo feature have been removed. Use the
|
||||
[log-panics](https://crates.io/crates/log-panics) instead.
|
||||
|
||||
### Changed
|
||||
|
||||
* The `Log` prefix has been removed from type names. For example, `LogLevelFilter` is now
|
||||
`LevelFilter`, and `LogRecord` is now `Record`.
|
||||
* The `MaxLogLevelFilter` object has been removed in favor of a `set_max_level` free function.
|
||||
* The `set_logger` free functions have been restructured. The logger is now directly passed to the
|
||||
functions rather than a closure which returns the logger. `set_logger` now takes a `&'static
|
||||
Log` and is usable in `no_std` contexts in place of the old `set_logger_raw`. `set_boxed_logger`
|
||||
is a convenience function which takes a `Box<Log>` but otherwise acts like `set_logger`. It
|
||||
requires the `std` feature.
|
||||
* The `file` and `module_path` values in `Record` no longer have the `'static` lifetime to support
|
||||
integration with other logging frameworks that don't provide a `'static` lifetime for the
|
||||
equivalent values.
|
||||
* The `file`, `line`, and `module_path` values in `Record` are now `Option`s to support integration
|
||||
with other logging frameworks that don't provide those values.
|
||||
|
||||
### In the Future
|
||||
|
||||
* We're looking to add support for *structured* logging - the inclusion of extra key-value pairs of
|
||||
information in a log event in addition to the normal string message. This should be able to be
|
||||
added in a backwards compatible manner to the 0.4.x series when the design is worked out.
|
||||
|
||||
## Older
|
||||
|
||||
Look at the [release tags] for information about older releases.
|
||||
|
||||
[Unreleased]: https://github.com/rust-lang-nursery/log/compare/0.4.29...HEAD
|
||||
[0.4.29]: https://github.com/rust-lang/log/compare/0.4.28...0.4.29
|
||||
[0.4.28]: https://github.com/rust-lang/log/compare/0.4.27...0.4.28
|
||||
[0.4.27]: https://github.com/rust-lang/log/compare/0.4.26...0.4.27
|
||||
[0.4.26]: https://github.com/rust-lang/log/compare/0.4.25...0.4.26
|
||||
[0.4.25]: https://github.com/rust-lang/log/compare/0.4.24...0.4.25
|
||||
[0.4.24]: https://github.com/rust-lang/log/compare/0.4.23...0.4.24
|
||||
[0.4.23]: https://github.com/rust-lang/log/compare/0.4.22...0.4.23
|
||||
[0.4.22]: https://github.com/rust-lang/log/compare/0.4.21...0.4.22
|
||||
[0.4.21]: https://github.com/rust-lang/log/compare/0.4.20...0.4.21
|
||||
[0.4.20]: https://github.com/rust-lang-nursery/log/compare/0.4.19...0.4.20
|
||||
[0.4.19]: https://github.com/rust-lang-nursery/log/compare/0.4.18...0.4.19
|
||||
[0.4.18]: https://github.com/rust-lang-nursery/log/compare/0.4.17...0.4.18
|
||||
[0.4.17]: https://github.com/rust-lang-nursery/log/compare/0.4.16...0.4.17
|
||||
[0.4.16]: https://github.com/rust-lang-nursery/log/compare/0.4.15...0.4.16
|
||||
[0.4.15]: https://github.com/rust-lang-nursery/log/compare/0.4.13...0.4.15
|
||||
[0.4.14]: https://github.com/rust-lang-nursery/log/compare/0.4.13...0.4.14
|
||||
[0.4.13]: https://github.com/rust-lang-nursery/log/compare/0.4.11...0.4.13
|
||||
[0.4.12]: https://github.com/rust-lang-nursery/log/compare/0.4.11...0.4.12
|
||||
[0.4.11]: https://github.com/rust-lang-nursery/log/compare/0.4.10...0.4.11
|
||||
[0.4.10]: https://github.com/rust-lang-nursery/log/compare/0.4.9...0.4.10
|
||||
[0.4.9]: https://github.com/rust-lang-nursery/log/compare/0.4.8...0.4.9
|
||||
[0.4.8]: https://github.com/rust-lang-nursery/log/compare/0.4.7...0.4.8
|
||||
[0.4.7]: https://github.com/rust-lang-nursery/log/compare/0.4.6...0.4.7
|
||||
[0.4.6]: https://github.com/rust-lang-nursery/log/compare/0.4.5...0.4.6
|
||||
[0.4.5]: https://github.com/rust-lang-nursery/log/compare/0.4.4...0.4.5
|
||||
[0.4.4]: https://github.com/rust-lang-nursery/log/compare/0.4.3...0.4.4
|
||||
[0.4.3]: https://github.com/rust-lang-nursery/log/compare/0.4.2...0.4.3
|
||||
[0.4.2]: https://github.com/rust-lang-nursery/log/compare/0.4.1...0.4.2
|
||||
[0.4.1]: https://github.com/rust-lang-nursery/log/compare/0.4.0...0.4.1
|
||||
[0.4.0]: https://github.com/rust-lang-nursery/log/compare/0.3.8...0.4.0
|
||||
[release tags]: https://github.com/rust-lang-nursery/log/releases
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "erased-serde"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89e8918065695684b2b0702da20382d5ae6065cf3327bc2d6436bd49a71ce9f3"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_core",
|
||||
"typeid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.29"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"serde_json",
|
||||
"serde_test",
|
||||
"sval",
|
||||
"sval_derive",
|
||||
"sval_ref",
|
||||
"value-bag",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_fmt"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e497af288b3b95d067a23a4f749f2861121ffcb2f6d8379310dcda040c345ed"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.145"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_test"
|
||||
version = "1.0.177"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f901ee573cab6b3060453d2d5f0bae4e6d628c23c0a962ff9b5f1d7c8d4f1ed"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "502b8906c4736190684646827fbab1e954357dfe541013bbd7994d033d53a1ca"
|
||||
|
||||
[[package]]
|
||||
name = "sval_buffer"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4b854348b15b6c441bdd27ce9053569b016a0723eab2d015b1fd8e6abe4f708"
|
||||
dependencies = [
|
||||
"sval",
|
||||
"sval_ref",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_derive"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d32579aae2a134498be6d360355d7f085260377479d08cb032f0a90340bfd72d"
|
||||
dependencies = [
|
||||
"sval_derive_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_derive_macros"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c855576b719497b925e9646ec865ffb79122027aeafee855b18f0612cc998947"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_dynamic"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0bd9e8b74410ddad37c6962587c5f9801a2caadba9e11f3f916ee3f31ae4a1f"
|
||||
dependencies = [
|
||||
"sval",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_fmt"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fe17b8deb33a9441280b4266c2d257e166bafbaea6e66b4b34ca139c91766d9"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"sval",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_json"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "854addb048a5bafb1f496c98e0ab5b9b581c3843f03ca07c034ae110d3b7c623"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"sval",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_nested"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96cf068f482108ff44ae8013477cb047a1665d5f1a635ad7cf79582c1845dce9"
|
||||
dependencies = [
|
||||
"sval",
|
||||
"sval_buffer",
|
||||
"sval_ref",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_ref"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed02126365ffe5ab8faa0abd9be54fbe68d03d607cd623725b0a71541f8aaa6f"
|
||||
dependencies = [
|
||||
"sval",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sval_serde"
|
||||
version = "2.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a263383c6aa2076c4ef6011d3bae1b356edf6ea2613e3d8e8ebaa7b57dd707d5"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"sval",
|
||||
"sval_nested",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.111"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typeid"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "value-bag"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ba6f5989077681266825251a52748b8c1d8a4ad098cc37e440103d0ea717fc0"
|
||||
dependencies = [
|
||||
"value-bag-serde1",
|
||||
"value-bag-sval2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "value-bag-serde1"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16530907bfe2999a1773ca5900a65101e092c70f642f25cc23ca0c43573262c5"
|
||||
dependencies = [
|
||||
"erased-serde",
|
||||
"serde_core",
|
||||
"serde_fmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "value-bag-sval2"
|
||||
version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d00ae130edd690eaa877e4f40605d534790d1cf1d651e7685bd6a144521b251f"
|
||||
dependencies = [
|
||||
"sval",
|
||||
"sval_buffer",
|
||||
"sval_dynamic",
|
||||
"sval_fmt",
|
||||
"sval_json",
|
||||
"sval_ref",
|
||||
"sval_serde",
|
||||
]
|
||||
Vendored
+152
@@ -0,0 +1,152 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
rust-version = "1.68.0"
|
||||
name = "log"
|
||||
version = "0.4.29"
|
||||
authors = ["The Rust Project Developers"]
|
||||
build = false
|
||||
exclude = ["rfcs/**/*"]
|
||||
autolib = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
autobenches = false
|
||||
description = """
|
||||
A lightweight logging facade for Rust
|
||||
"""
|
||||
documentation = "https://docs.rs/log"
|
||||
readme = "README.md"
|
||||
keywords = ["logging"]
|
||||
categories = ["development-tools::debugging"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-lang/log"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = [
|
||||
"std",
|
||||
"serde",
|
||||
"kv_std",
|
||||
"kv_sval",
|
||||
"kv_serde",
|
||||
]
|
||||
|
||||
[features]
|
||||
kv = []
|
||||
kv_serde = [
|
||||
"kv_std",
|
||||
"value-bag/serde",
|
||||
"serde",
|
||||
]
|
||||
kv_std = [
|
||||
"std",
|
||||
"kv",
|
||||
"value-bag/error",
|
||||
]
|
||||
kv_sval = [
|
||||
"kv",
|
||||
"value-bag/sval",
|
||||
"sval",
|
||||
"sval_ref",
|
||||
]
|
||||
kv_unstable = [
|
||||
"kv",
|
||||
"value-bag",
|
||||
]
|
||||
kv_unstable_serde = [
|
||||
"kv_serde",
|
||||
"kv_unstable_std",
|
||||
]
|
||||
kv_unstable_std = [
|
||||
"kv_std",
|
||||
"kv_unstable",
|
||||
]
|
||||
kv_unstable_sval = [
|
||||
"kv_sval",
|
||||
"kv_unstable",
|
||||
]
|
||||
max_level_debug = []
|
||||
max_level_error = []
|
||||
max_level_info = []
|
||||
max_level_off = []
|
||||
max_level_trace = []
|
||||
max_level_warn = []
|
||||
release_max_level_debug = []
|
||||
release_max_level_error = []
|
||||
release_max_level_info = []
|
||||
release_max_level_off = []
|
||||
release_max_level_trace = []
|
||||
release_max_level_warn = []
|
||||
serde = ["serde_core"]
|
||||
std = []
|
||||
|
||||
[lib]
|
||||
name = "log"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[test]]
|
||||
name = "integration"
|
||||
path = "tests/integration.rs"
|
||||
|
||||
[[test]]
|
||||
name = "macros"
|
||||
path = "tests/macros.rs"
|
||||
|
||||
[[bench]]
|
||||
name = "value"
|
||||
path = "benches/value.rs"
|
||||
|
||||
[dependencies.serde_core]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.sval]
|
||||
version = "2.16"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.sval_ref]
|
||||
version = "2.16"
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dependencies.value-bag]
|
||||
version = "1.12"
|
||||
features = ["inline-i128"]
|
||||
optional = true
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.proc-macro2]
|
||||
version = "1.0.63"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.serde]
|
||||
version = "1.0"
|
||||
features = ["derive"]
|
||||
|
||||
[dev-dependencies.serde_json]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.serde_test]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.sval]
|
||||
version = "2.16"
|
||||
|
||||
[dev-dependencies.sval_derive]
|
||||
version = "2.16"
|
||||
|
||||
[dev-dependencies.value-bag]
|
||||
version = "1.12"
|
||||
features = ["test"]
|
||||
Vendored
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2014 The Rust Project Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
Vendored
+134
@@ -0,0 +1,134 @@
|
||||
log
|
||||
===
|
||||
|
||||
A Rust library providing a lightweight logging *facade*.
|
||||
|
||||
[](https://github.com/rust-lang/log/actions)
|
||||
[](https://crates.io/crates/log)
|
||||
[](https://docs.rs/log)
|
||||

|
||||
|
||||
* [`log` documentation](https://docs.rs/log)
|
||||
|
||||
A logging facade provides a single logging API that abstracts over the actual
|
||||
logging implementation. Libraries can use the logging API provided by this
|
||||
crate, and the consumer of those libraries can choose the logging
|
||||
implementation that is most suitable for its use case.
|
||||
|
||||
|
||||
## Minimum supported `rustc`
|
||||
|
||||
`1.61.0+`
|
||||
|
||||
This version is explicitly tested in CI and may be bumped in any release as needed. Maintaining compatibility with older compilers is a priority though, so the bar for bumping the minimum supported version is set very high. Any changes to the supported minimum version will be called out in the release notes.
|
||||
|
||||
## Usage
|
||||
|
||||
### In libraries
|
||||
|
||||
Libraries should link only to the `log` crate, and use the provided macros to
|
||||
log whatever information will be useful to downstream consumers:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
```
|
||||
|
||||
```rust
|
||||
use log::{info, trace, warn};
|
||||
|
||||
pub fn shave_the_yak(yak: &mut Yak) {
|
||||
trace!("Commencing yak shaving");
|
||||
|
||||
loop {
|
||||
match find_a_razor() {
|
||||
Ok(razor) => {
|
||||
info!("Razor located: {razor}");
|
||||
yak.shave(razor);
|
||||
break;
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("Unable to locate a razor: {err}, retrying");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### In executables
|
||||
|
||||
In order to produce log output, executables have to use a logger implementation compatible with the facade.
|
||||
There are many available implementations to choose from, here are some options:
|
||||
|
||||
* Simple minimal loggers:
|
||||
* [`env_logger`](https://docs.rs/env_logger/*/env_logger/)
|
||||
* [`colog`](https://docs.rs/colog/*/colog/)
|
||||
* [`simple_logger`](https://docs.rs/simple_logger/*/simple_logger/)
|
||||
* [`simplelog`](https://docs.rs/simplelog/*/simplelog/)
|
||||
* [`pretty_env_logger`](https://docs.rs/pretty_env_logger/*/pretty_env_logger/)
|
||||
* [`stderrlog`](https://docs.rs/stderrlog/*/stderrlog/)
|
||||
* [`flexi_logger`](https://docs.rs/flexi_logger/*/flexi_logger/)
|
||||
* [`call_logger`](https://docs.rs/call_logger/*/call_logger/)
|
||||
* [`std-logger`](https://docs.rs/std-logger/*/std_logger/)
|
||||
* [`structured-logger`](https://docs.rs/structured-logger/latest/structured_logger/)
|
||||
* [`clang_log`](https://docs.rs/clang_log/latest/clang_log)
|
||||
* [`ftail`](https://docs.rs/ftail/latest/ftail/)
|
||||
* Complex configurable frameworks:
|
||||
* [`log4rs`](https://docs.rs/log4rs/*/log4rs/)
|
||||
* [`logforth`](https://docs.rs/logforth/*/logforth/)
|
||||
* [`fern`](https://docs.rs/fern/*/fern/)
|
||||
* [`spdlog-rs`](https://docs.rs/spdlog-rs/*/spdlog/)
|
||||
* Adaptors for other facilities:
|
||||
* [`syslog`](https://docs.rs/syslog/*/syslog/)
|
||||
* [`systemd-journal-logger`](https://docs.rs/systemd-journal-logger/*/systemd_journal_logger/)
|
||||
* [`slog-stdlog`](https://docs.rs/slog-stdlog/*/slog_stdlog/)
|
||||
* [`android_log`](https://docs.rs/android_log/*/android_log/)
|
||||
* [`win_dbg_logger`](https://docs.rs/win_dbg_logger/*/win_dbg_logger/)
|
||||
* [`db_logger`](https://docs.rs/db_logger/*/db_logger/)
|
||||
* [`log-to-defmt`](https://docs.rs/log-to-defmt/*/log_to_defmt/)
|
||||
* [`logcontrol-log`](https://docs.rs/logcontrol-log/*/logcontrol_log/)
|
||||
* For WebAssembly binaries:
|
||||
* [`console_log`](https://docs.rs/console_log/*/console_log/)
|
||||
* For dynamic libraries:
|
||||
* You may need to construct [an FFI-safe wrapper over `log`](https://github.com/rust-lang/log/issues/421) to initialize in your libraries.
|
||||
* Utilities:
|
||||
* [`log_err`](https://docs.rs/log_err/*/log_err/)
|
||||
* [`log-reload`](https://docs.rs/log-reload/*/log_reload/)
|
||||
* [`alterable_logger`](https://docs.rs/alterable_logger/*/alterable_logger)
|
||||
|
||||
Executables should choose a logger implementation and initialize it early in the
|
||||
runtime of the program. Logger implementations will typically include a
|
||||
function to do this. Any log messages generated before the logger is
|
||||
initialized will be ignored.
|
||||
|
||||
The executable itself may use the `log` crate to log as well.
|
||||
|
||||
## Structured logging
|
||||
|
||||
If you enable the `kv` feature, you can associate structured data with your log records:
|
||||
|
||||
```rust
|
||||
use log::{info, trace, warn};
|
||||
|
||||
pub fn shave_the_yak(yak: &mut Yak) {
|
||||
// `yak:serde` will capture `yak` using its `serde::Serialize` impl
|
||||
//
|
||||
// You could also use `:?` for `Debug`, or `:%` for `Display`. For a
|
||||
// full list, see the `log` crate documentation
|
||||
trace!(target = "yak_events", yak:serde; "Commencing yak shaving");
|
||||
|
||||
loop {
|
||||
match find_a_razor() {
|
||||
Ok(razor) => {
|
||||
info!(razor; "Razor located");
|
||||
yak.shave(razor);
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
// `e:err` will capture `e` using its `std::error::Error` impl
|
||||
warn!(e:err; "Unable to locate a razor, retrying");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
#![cfg(feature = "kv")]
|
||||
#![feature(test)]
|
||||
|
||||
use log::kv::Value;
|
||||
|
||||
#[bench]
|
||||
fn u8_to_value(b: &mut test::Bencher) {
|
||||
b.iter(|| Value::from(1u8));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn u8_to_value_debug(b: &mut test::Bencher) {
|
||||
b.iter(|| Value::from_debug(&1u8));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn str_to_value_debug(b: &mut test::Bencher) {
|
||||
b.iter(|| Value::from_debug(&"a string"));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn custom_to_value_debug(b: &mut test::Bencher) {
|
||||
#[derive(Debug)]
|
||||
struct A;
|
||||
|
||||
b.iter(|| Value::from_debug(&A));
|
||||
}
|
||||
Vendored
+151
@@ -0,0 +1,151 @@
|
||||
//! WARNING: this is not part of the crate's public API and is subject to change at any time
|
||||
|
||||
use self::sealed::KVs;
|
||||
use crate::{logger, Level, Log, Metadata, Record};
|
||||
use std::fmt::Arguments;
|
||||
use std::panic::Location;
|
||||
pub use std::{format_args, module_path, stringify};
|
||||
|
||||
#[cfg(not(feature = "kv"))]
|
||||
pub type Value<'a> = &'a str;
|
||||
|
||||
mod sealed {
|
||||
/// Types for the `kv` argument.
|
||||
pub trait KVs<'a> {
|
||||
fn into_kvs(self) -> Option<&'a [(&'a str, super::Value<'a>)]>;
|
||||
}
|
||||
}
|
||||
|
||||
// Types for the `kv` argument.
|
||||
|
||||
impl<'a> KVs<'a> for &'a [(&'a str, Value<'a>)] {
|
||||
#[inline]
|
||||
fn into_kvs(self) -> Option<&'a [(&'a str, Value<'a>)]> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> KVs<'a> for () {
|
||||
#[inline]
|
||||
fn into_kvs(self) -> Option<&'a [(&'a str, Value<'a>)]> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// Log implementation.
|
||||
|
||||
/// The global logger proxy.
|
||||
#[derive(Debug)]
|
||||
pub struct GlobalLogger;
|
||||
|
||||
impl Log for GlobalLogger {
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
logger().enabled(metadata)
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
logger().log(record)
|
||||
}
|
||||
|
||||
fn flush(&self) {
|
||||
logger().flush()
|
||||
}
|
||||
}
|
||||
|
||||
// Split from `log` to reduce generics and code size
|
||||
fn log_impl<L: Log>(
|
||||
logger: L,
|
||||
args: Arguments,
|
||||
level: Level,
|
||||
&(target, module_path, loc): &(&str, &'static str, &'static Location),
|
||||
kvs: Option<&[(&str, Value)]>,
|
||||
) {
|
||||
#[cfg(not(feature = "kv"))]
|
||||
if kvs.is_some() {
|
||||
panic!("key-value support is experimental and must be enabled using the `kv` feature")
|
||||
}
|
||||
|
||||
let mut builder = Record::builder();
|
||||
|
||||
builder
|
||||
.args(args)
|
||||
.level(level)
|
||||
.target(target)
|
||||
.module_path_static(Some(module_path))
|
||||
.file_static(Some(loc.file()))
|
||||
.line(Some(loc.line()));
|
||||
|
||||
#[cfg(feature = "kv")]
|
||||
builder.key_values(&kvs);
|
||||
|
||||
logger.log(&builder.build());
|
||||
}
|
||||
|
||||
pub fn log<'a, K, L>(
|
||||
logger: L,
|
||||
args: Arguments,
|
||||
level: Level,
|
||||
target_module_path_and_loc: &(&str, &'static str, &'static Location),
|
||||
kvs: K,
|
||||
) where
|
||||
K: KVs<'a>,
|
||||
L: Log,
|
||||
{
|
||||
log_impl(
|
||||
logger,
|
||||
args,
|
||||
level,
|
||||
target_module_path_and_loc,
|
||||
kvs.into_kvs(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn enabled<L: Log>(logger: L, level: Level, target: &str) -> bool {
|
||||
logger.enabled(&Metadata::builder().level(level).target(target).build())
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
pub fn loc() -> &'static Location<'static> {
|
||||
Location::caller()
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv")]
|
||||
mod kv_support {
|
||||
use crate::kv;
|
||||
|
||||
pub type Value<'a> = kv::Value<'a>;
|
||||
|
||||
// NOTE: Many functions here accept a double reference &&V
|
||||
// This is so V itself can be ?Sized, while still letting us
|
||||
// erase it to some dyn Trait (because &T is sized)
|
||||
|
||||
pub fn capture_to_value<'a, V: kv::ToValue + ?Sized>(v: &'a &'a V) -> Value<'a> {
|
||||
v.to_value()
|
||||
}
|
||||
|
||||
pub fn capture_debug<'a, V: core::fmt::Debug + ?Sized>(v: &'a &'a V) -> Value<'a> {
|
||||
Value::from_debug(v)
|
||||
}
|
||||
|
||||
pub fn capture_display<'a, V: core::fmt::Display + ?Sized>(v: &'a &'a V) -> Value<'a> {
|
||||
Value::from_display(v)
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_std")]
|
||||
pub fn capture_error<'a>(v: &'a (dyn std::error::Error + 'static)) -> Value<'a> {
|
||||
Value::from_dyn_error(v)
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_sval")]
|
||||
pub fn capture_sval<'a, V: sval::Value + ?Sized>(v: &'a &'a V) -> Value<'a> {
|
||||
Value::from_sval(v)
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_serde")]
|
||||
pub fn capture_serde<'a, V: serde_core::Serialize + ?Sized>(v: &'a &'a V) -> Value<'a> {
|
||||
Value::from_serde(v)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv")]
|
||||
pub use self::kv_support::*;
|
||||
Vendored
+94
@@ -0,0 +1,94 @@
|
||||
use std::fmt;
|
||||
|
||||
/// An error encountered while working with structured data.
|
||||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
inner: Inner,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Inner {
|
||||
#[cfg(feature = "std")]
|
||||
Boxed(std_support::BoxedError),
|
||||
Msg(&'static str),
|
||||
#[cfg(feature = "value-bag")]
|
||||
Value(crate::kv::value::inner::Error),
|
||||
Fmt,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// Create an error from a message.
|
||||
pub fn msg(msg: &'static str) -> Self {
|
||||
Error {
|
||||
inner: Inner::Msg(msg),
|
||||
}
|
||||
}
|
||||
|
||||
// Not public so we don't leak the `crate::kv::value::inner` API
|
||||
#[cfg(feature = "value-bag")]
|
||||
pub(super) fn from_value(err: crate::kv::value::inner::Error) -> Self {
|
||||
Error {
|
||||
inner: Inner::Value(err),
|
||||
}
|
||||
}
|
||||
|
||||
// Not public so we don't leak the `crate::kv::value::inner` API
|
||||
#[cfg(feature = "value-bag")]
|
||||
pub(super) fn into_value(self) -> crate::kv::value::inner::Error {
|
||||
match self.inner {
|
||||
Inner::Value(err) => err,
|
||||
#[cfg(feature = "kv_std")]
|
||||
_ => crate::kv::value::inner::Error::boxed(self),
|
||||
#[cfg(not(feature = "kv_std"))]
|
||||
_ => crate::kv::value::inner::Error::msg("error inspecting a value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::Inner::*;
|
||||
match &self.inner {
|
||||
#[cfg(feature = "std")]
|
||||
Boxed(err) => err.fmt(f),
|
||||
#[cfg(feature = "value-bag")]
|
||||
Value(err) => err.fmt(f),
|
||||
Msg(msg) => msg.fmt(f),
|
||||
Fmt => fmt::Error.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<fmt::Error> for Error {
|
||||
fn from(_: fmt::Error) -> Self {
|
||||
Error { inner: Inner::Fmt }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod std_support {
|
||||
use super::*;
|
||||
use std::{error, io};
|
||||
|
||||
pub(super) type BoxedError = Box<dyn error::Error + Send + Sync>;
|
||||
|
||||
impl Error {
|
||||
/// Create an error from a standard error type.
|
||||
pub fn boxed<E>(err: E) -> Self
|
||||
where
|
||||
E: Into<BoxedError>,
|
||||
{
|
||||
Error {
|
||||
inner: Inner::Boxed(err.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(err: io::Error) -> Self {
|
||||
Error::boxed(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+164
@@ -0,0 +1,164 @@
|
||||
//! Structured keys.
|
||||
|
||||
use std::borrow::Borrow;
|
||||
use std::fmt;
|
||||
|
||||
/// A type that can be converted into a [`Key`](struct.Key.html).
|
||||
pub trait ToKey {
|
||||
/// Perform the conversion.
|
||||
fn to_key(&self) -> Key<'_>;
|
||||
}
|
||||
|
||||
impl<T> ToKey for &T
|
||||
where
|
||||
T: ToKey + ?Sized,
|
||||
{
|
||||
fn to_key(&self) -> Key<'_> {
|
||||
(**self).to_key()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> ToKey for Key<'k> {
|
||||
fn to_key(&self) -> Key<'_> {
|
||||
Key { key: self.key }
|
||||
}
|
||||
}
|
||||
|
||||
impl ToKey for str {
|
||||
fn to_key(&self) -> Key<'_> {
|
||||
Key::from_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// A key in a key-value.
|
||||
// These impls must only be based on the as_str() representation of the key
|
||||
// If a new field (such as an optional index) is added to the key they must not affect comparison
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Key<'k> {
|
||||
// NOTE: This may become `Cow<'k, str>`
|
||||
key: &'k str,
|
||||
}
|
||||
|
||||
impl<'k> Key<'k> {
|
||||
/// Get a key from a borrowed string.
|
||||
#[allow(clippy::should_implement_trait)] // Part of the public API now.
|
||||
pub fn from_str(key: &'k str) -> Self {
|
||||
Key { key }
|
||||
}
|
||||
|
||||
/// Get a borrowed string from this key.
|
||||
///
|
||||
/// The lifetime of the returned string is bound to the borrow of `self` rather
|
||||
/// than to `'k`.
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.key
|
||||
}
|
||||
|
||||
/// Try get a borrowed string for the lifetime `'k` from this key.
|
||||
///
|
||||
/// If the key is a borrow of a longer lived string, this method will return `Some`.
|
||||
/// If the key is internally buffered, this method will return `None`.
|
||||
pub fn to_borrowed_str(&self) -> Option<&'k str> {
|
||||
// NOTE: If the internals of `Key` support buffering this
|
||||
// won't be unconditionally `Some` anymore. We want to keep
|
||||
// this option open
|
||||
Some(self.key)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> fmt::Display for Key<'k> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.key.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> AsRef<str> for Key<'k> {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> Borrow<str> for Key<'k> {
|
||||
fn borrow(&self) -> &str {
|
||||
self.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'k> From<&'k str> for Key<'k> {
|
||||
fn from(s: &'k str) -> Self {
|
||||
Key::from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod std_support {
|
||||
use super::*;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
impl ToKey for String {
|
||||
fn to_key(&self) -> Key<'_> {
|
||||
Key::from_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ToKey for Cow<'a, str> {
|
||||
fn to_key(&self) -> Key<'_> {
|
||||
Key::from_str(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_sval")]
|
||||
mod sval_support {
|
||||
use super::*;
|
||||
|
||||
use sval::Value;
|
||||
use sval_ref::ValueRef;
|
||||
|
||||
impl<'a> Value for Key<'a> {
|
||||
fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(
|
||||
&'sval self,
|
||||
stream: &mut S,
|
||||
) -> sval::Result {
|
||||
self.key.stream(stream)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ValueRef<'a> for Key<'a> {
|
||||
fn stream_ref<S: sval::Stream<'a> + ?Sized>(&self, stream: &mut S) -> sval::Result {
|
||||
self.key.stream(stream)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "kv_serde")]
|
||||
mod serde_support {
|
||||
use super::*;
|
||||
|
||||
use serde_core::{Serialize, Serializer};
|
||||
|
||||
impl<'a> Serialize for Key<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.key.serialize(serializer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn key_from_string() {
|
||||
assert_eq!("a key", Key::from_str("a key").as_str());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_to_borrowed() {
|
||||
assert_eq!("a key", Key::from_str("a key").to_borrowed_str().unwrap());
|
||||
}
|
||||
}
|
||||
Vendored
+265
@@ -0,0 +1,265 @@
|
||||
//! Structured logging.
|
||||
//!
|
||||
//! Add the `kv` feature to your `Cargo.toml` to enable
|
||||
//! this module:
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies.log]
|
||||
//! features = ["kv"]
|
||||
//! ```
|
||||
//!
|
||||
//! # Structured logging in `log`
|
||||
//!
|
||||
//! Structured logging enhances traditional text-based log records with user-defined
|
||||
//! attributes. Structured logs can be analyzed using a variety of data processing
|
||||
//! techniques, without needing to find and parse attributes from unstructured text first.
|
||||
//!
|
||||
//! In `log`, user-defined attributes are part of a [`Source`] on the log record.
|
||||
//! Each attribute is a key-value; a pair of [`Key`] and [`Value`]. Keys are strings
|
||||
//! and values are a datum of any type that can be formatted or serialized. Simple types
|
||||
//! like strings, booleans, and numbers are supported, as well as arbitrarily complex
|
||||
//! structures involving nested objects and sequences.
|
||||
//!
|
||||
//! ## Adding key-values to log records
|
||||
//!
|
||||
//! Key-values appear before the message format in the `log!` macros:
|
||||
//!
|
||||
//! ```
|
||||
//! # use log::info;
|
||||
//! info!(a = 1; "Something of interest");
|
||||
//! ```
|
||||
//!
|
||||
//! Key-values support the same shorthand identifier syntax as `format_args`:
|
||||
//!
|
||||
//! ```
|
||||
//! # use log::info;
|
||||
//! let a = 1;
|
||||
//!
|
||||
//! info!(a; "Something of interest");
|
||||
//! ```
|
||||
//!
|
||||
//! Values are capturing using the [`ToValue`] trait by default. To capture a value
|
||||
//! using a different trait implementation, use a modifier after its key. Here's how
|
||||
//! the same example can capture `a` using its `Debug` implementation instead:
|
||||
//!
|
||||
//! ```
|
||||
//! # use log::info;
|
||||
//! info!(a:? = 1; "Something of interest");
|
||||
//! ```
|
||||
//!
|
||||
//! The following capturing modifiers are supported:
|
||||
//!
|
||||
//! - `:?` will capture the value using `Debug`.
|
||||
//! - `:debug` will capture the value using `Debug`.
|
||||
//! - `:%` will capture the value using `Display`.
|
||||
//! - `:display` will capture the value using `Display`.
|
||||
//! - `:err` will capture the value using `std::error::Error` (requires the `kv_std` feature).
|
||||
//! - `:sval` will capture the value using `sval::Value` (requires the `kv_sval` feature).
|
||||
//! - `:serde` will capture the value using `serde::Serialize` (requires the `kv_serde` feature).
|
||||
//!
|
||||
//! ## Working with key-values on log records
|
||||
//!
|
||||
//! Use the [`Record::key_values`](../struct.Record.html#method.key_values) method to access key-values.
|
||||
//!
|
||||
//! Individual values can be pulled from the source by their key:
|
||||
//!
|
||||
//! ```
|
||||
//! # fn main() -> Result<(), log::kv::Error> {
|
||||
//! use log::kv::{Source, Key, Value};
|
||||
//! # let record = log::Record::builder().key_values(&[("a", 1)]).build();
|
||||
//!
|
||||
//! // info!(a = 1; "Something of interest");
|
||||
//!
|
||||
//! let a: Value = record.key_values().get(Key::from("a")).unwrap();
|
||||
//! assert_eq!(1, a.to_i64().unwrap());
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! All key-values can also be enumerated using a [`VisitSource`]:
|
||||
//!
|
||||
//! ```
|
||||
//! # fn main() -> Result<(), log::kv::Error> {
|
||||
//! use std::collections::BTreeMap;
|
||||
//!
|
||||
//! use log::kv::{self, Source, Key, Value, VisitSource};
|
||||
//!
|
||||
//! struct Collect<'kvs>(BTreeMap<Key<'kvs>, Value<'kvs>>);
|
||||
//!
|
||||
//! impl<'kvs> VisitSource<'kvs> for Collect<'kvs> {
|
||||
//! fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), kv::Error> {
|
||||
//! self.0.insert(key, value);
|
||||
//!
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! let mut visitor = Collect(BTreeMap::new());
|
||||
//!
|
||||
//! # let record = log::Record::builder().key_values(&[("a", 1), ("b", 2), ("c", 3)]).build();
|
||||
//! // info!(a = 1, b = 2, c = 3; "Something of interest");
|
||||
//!
|
||||
//! record.key_values().visit(&mut visitor)?;
|
||||
//!
|
||||
//! let collected = visitor.0;
|
||||
//!
|
||||
//! assert_eq!(
|
||||
//! vec!["a", "b", "c"],
|
||||
//! collected
|
||||
//! .keys()
|
||||
//! .map(|k| k.as_str())
|
||||
//! .collect::<Vec<_>>(),
|
||||
//! );
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! [`Value`]s have methods for conversions to common types:
|
||||
//!
|
||||
//! ```
|
||||
//! # fn main() -> Result<(), log::kv::Error> {
|
||||
//! use log::kv::{Source, Key};
|
||||
//! # let record = log::Record::builder().key_values(&[("a", 1)]).build();
|
||||
//!
|
||||
//! // info!(a = 1; "Something of interest");
|
||||
//!
|
||||
//! let a = record.key_values().get(Key::from("a")).unwrap();
|
||||
//!
|
||||
//! assert_eq!(1, a.to_i64().unwrap());
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! Values also have their own [`VisitValue`] type. Value visitors are a lightweight
|
||||
//! API for working with primitives types:
|
||||
//!
|
||||
//! ```
|
||||
//! # fn main() -> Result<(), log::kv::Error> {
|
||||
//! use log::kv::{self, Source, Key, VisitValue};
|
||||
//! # let record = log::Record::builder().key_values(&[("a", 1)]).build();
|
||||
//!
|
||||
//! struct IsNumeric(bool);
|
||||
//!
|
||||
//! impl<'kvs> VisitValue<'kvs> for IsNumeric {
|
||||
//! fn visit_any(&mut self, _value: kv::Value) -> Result<(), kv::Error> {
|
||||
//! self.0 = false;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn visit_u64(&mut self, _value: u64) -> Result<(), kv::Error> {
|
||||
//! self.0 = true;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn visit_i64(&mut self, _value: i64) -> Result<(), kv::Error> {
|
||||
//! self.0 = true;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn visit_u128(&mut self, _value: u128) -> Result<(), kv::Error> {
|
||||
//! self.0 = true;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn visit_i128(&mut self, _value: i128) -> Result<(), kv::Error> {
|
||||
//! self.0 = true;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn visit_f64(&mut self, _value: f64) -> Result<(), kv::Error> {
|
||||
//! self.0 = true;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! // info!(a = 1; "Something of interest");
|
||||
//!
|
||||
//! let a = record.key_values().get(Key::from("a")).unwrap();
|
||||
//!
|
||||
//! let mut visitor = IsNumeric(false);
|
||||
//!
|
||||
//! a.visit(&mut visitor)?;
|
||||
//!
|
||||
//! let is_numeric = visitor.0;
|
||||
//!
|
||||
//! assert!(is_numeric);
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! To serialize a value to a format like JSON, you can also use either `serde` or `sval`:
|
||||
//!
|
||||
//! ```
|
||||
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
//! # #[cfg(feature = "kv_serde")]
|
||||
//! # {
|
||||
//! # use log::kv::Key;
|
||||
//! #[derive(serde::Serialize)]
|
||||
//! struct Data {
|
||||
//! a: i32, b: bool,
|
||||
//! c: &'static str,
|
||||
//! }
|
||||
//!
|
||||
//! let data = Data { a: 1, b: true, c: "Some data" };
|
||||
//!
|
||||
//! # let source = [("a", log::kv::Value::from_serde(&data))];
|
||||
//! # let record = log::Record::builder().key_values(&source).build();
|
||||
//! // info!(a = data; "Something of interest");
|
||||
//!
|
||||
//! let a = record.key_values().get(Key::from("a")).unwrap();
|
||||
//!
|
||||
//! assert_eq!("{\"a\":1,\"b\":true,\"c\":\"Some data\"}", serde_json::to_string(&a)?);
|
||||
//! # }
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! The choice of serialization framework depends on the needs of the consumer.
|
||||
//! If you're in a no-std environment, you can use `sval`. In other cases, you can use `serde`.
|
||||
//! Log producers and log consumers don't need to agree on the serialization framework.
|
||||
//! A value can be captured using its `serde::Serialize` implementation and still be serialized
|
||||
//! through `sval` without losing any structure or data.
|
||||
//!
|
||||
//! Values can also always be formatted using the standard `Debug` and `Display`
|
||||
//! traits:
|
||||
//!
|
||||
//! ```
|
||||
//! # use log::kv::Key;
|
||||
//! #[derive(Debug)]
|
||||
//! struct Data {
|
||||
//! a: i32,
|
||||
//! b: bool,
|
||||
//! c: &'static str,
|
||||
//! }
|
||||
//!
|
||||
//! let data = Data { a: 1, b: true, c: "Some data" };
|
||||
//!
|
||||
//! # let source = [("a", log::kv::Value::from_debug(&data))];
|
||||
//! # let record = log::Record::builder().key_values(&source).build();
|
||||
//! // info!(a = data; "Something of interest");
|
||||
//!
|
||||
//! let a = record.key_values().get(Key::from("a")).unwrap();
|
||||
//!
|
||||
//! assert_eq!("Data { a: 1, b: true, c: \"Some data\" }", format!("{a:?}"));
|
||||
//! ```
|
||||
|
||||
mod error;
|
||||
mod key;
|
||||
|
||||
#[cfg(not(feature = "kv_unstable"))]
|
||||
mod source;
|
||||
#[cfg(not(feature = "kv_unstable"))]
|
||||
mod value;
|
||||
|
||||
pub use self::error::Error;
|
||||
pub use self::key::{Key, ToKey};
|
||||
pub use self::source::{Source, VisitSource};
|
||||
pub use self::value::{ToValue, Value, VisitValue};
|
||||
|
||||
#[cfg(feature = "kv_unstable")]
|
||||
pub mod source;
|
||||
#[cfg(feature = "kv_unstable")]
|
||||
pub mod value;
|
||||
|
||||
#[cfg(feature = "kv_unstable")]
|
||||
pub use self::source::Visitor;
|
||||
Vendored
+515
@@ -0,0 +1,515 @@
|
||||
//! Sources for key-values.
|
||||
//!
|
||||
//! This module defines the [`Source`] type and supporting APIs for
|
||||
//! working with collections of key-values.
|
||||
|
||||
use crate::kv::{Error, Key, ToKey, ToValue, Value};
|
||||
use std::fmt;
|
||||
|
||||
/// A source of key-values.
|
||||
///
|
||||
/// The source may be a single pair, a set of pairs, or a filter over a set of pairs.
|
||||
/// Use the [`VisitSource`](trait.VisitSource.html) trait to inspect the structured data
|
||||
/// in a source.
|
||||
///
|
||||
/// A source is like an iterator over its key-values, except with a push-based API
|
||||
/// instead of a pull-based one.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Enumerating the key-values in a source:
|
||||
///
|
||||
/// ```
|
||||
/// # fn main() -> Result<(), log::kv::Error> {
|
||||
/// use log::kv::{self, Source, Key, Value, VisitSource};
|
||||
///
|
||||
/// // A `VisitSource` that prints all key-values
|
||||
/// // VisitSources are fed the key-value pairs of each key-values
|
||||
/// struct Printer;
|
||||
///
|
||||
/// impl<'kvs> VisitSource<'kvs> for Printer {
|
||||
/// fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), kv::Error> {
|
||||
/// println!("{key}: {value}");
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// // A source with 3 key-values
|
||||
/// // Common collection types implement the `Source` trait
|
||||
/// let source = &[
|
||||
/// ("a", 1),
|
||||
/// ("b", 2),
|
||||
/// ("c", 3),
|
||||
/// ];
|
||||
///
|
||||
/// // Pass an instance of the `VisitSource` to a `Source` to visit it
|
||||
/// source.visit(&mut Printer)?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub trait Source {
|
||||
/// Visit key-values.
|
||||
///
|
||||
/// A source doesn't have to guarantee any ordering or uniqueness of key-values.
|
||||
/// If the given visitor returns an error then the source may early-return with it,
|
||||
/// even if there are more key-values.
|
||||
///
|
||||
/// # Implementation notes
|
||||
///
|
||||
/// A source should yield the same key-values to a subsequent visitor unless
|
||||
/// that visitor itself fails.
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error>;
|
||||
|
||||
/// Get the value for a given key.
|
||||
///
|
||||
/// If the key appears multiple times in the source then which key is returned
|
||||
/// is implementation specific.
|
||||
///
|
||||
/// # Implementation notes
|
||||
///
|
||||
/// A source that can provide a more efficient implementation of this method
|
||||
/// should override it.
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
get_default(self, key)
|
||||
}
|
||||
|
||||
/// Count the number of key-values that can be visited.
|
||||
///
|
||||
/// # Implementation notes
|
||||
///
|
||||
/// A source that knows the number of key-values upfront may provide a more
|
||||
/// efficient implementation.
|
||||
///
|
||||
/// A subsequent call to `visit` should yield the same number of key-values.
|
||||
fn count(&self) -> usize {
|
||||
count_default(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// The default implementation of `Source::get`
|
||||
fn get_default<'v>(source: &'v (impl Source + ?Sized), key: Key) -> Option<Value<'v>> {
|
||||
struct Get<'k, 'v> {
|
||||
key: Key<'k>,
|
||||
found: Option<Value<'v>>,
|
||||
}
|
||||
|
||||
impl<'k, 'kvs> VisitSource<'kvs> for Get<'k, 'kvs> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
if self.key == key {
|
||||
self.found = Some(value);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut get = Get { key, found: None };
|
||||
|
||||
let _ = source.visit(&mut get);
|
||||
get.found
|
||||
}
|
||||
|
||||
/// The default implementation of `Source::count`.
|
||||
fn count_default(source: impl Source) -> usize {
|
||||
struct Count(usize);
|
||||
|
||||
impl<'kvs> VisitSource<'kvs> for Count {
|
||||
fn visit_pair(&mut self, _: Key<'kvs>, _: Value<'kvs>) -> Result<(), Error> {
|
||||
self.0 += 1;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
let mut count = Count(0);
|
||||
let _ = source.visit(&mut count);
|
||||
count.0
|
||||
}
|
||||
|
||||
impl<T> Source for &T
|
||||
where
|
||||
T: Source + ?Sized,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Source for (K, V)
|
||||
where
|
||||
K: ToKey,
|
||||
V: ToValue,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
visitor.visit_pair(self.0.to_key(), self.1.to_value())
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
if self.0.to_key() == key {
|
||||
Some(self.1.to_value())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for [S]
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
for source in self {
|
||||
source.visit(visitor)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
for source in self {
|
||||
if let Some(found) = source.get(key.clone()) {
|
||||
return Some(found);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.iter().map(Source::count).sum()
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize, S> Source for [S; N]
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(self as &[_], visitor)
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
Source::get(self as &[_], key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(self as &[_])
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Option<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
if let Some(source) = self {
|
||||
source.visit(visitor)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
self.as_ref().and_then(|s| s.get(key))
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.as_ref().map_or(0, Source::count)
|
||||
}
|
||||
}
|
||||
|
||||
/// A visitor for the key-value pairs in a [`Source`](trait.Source.html).
|
||||
pub trait VisitSource<'kvs> {
|
||||
/// Visit a key-value pair.
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_lifetimes)] // Not needless.
|
||||
impl<'a, 'kvs, T> VisitSource<'kvs> for &'a mut T
|
||||
where
|
||||
T: VisitSource<'kvs> + ?Sized,
|
||||
{
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
(**self).visit_pair(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> VisitSource<'kvs> for fmt::DebugMap<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.entry(&key, &value);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> VisitSource<'kvs> for fmt::DebugList<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.entry(&(key, value));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> VisitSource<'kvs> for fmt::DebugSet<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.entry(&(key, value));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, 'kvs> VisitSource<'kvs> for fmt::DebugTuple<'a, 'b> {
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
self.field(&key);
|
||||
self.field(&value);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod std_support {
|
||||
use super::*;
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::hash::{BuildHasher, Hash};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
impl<S> Source for Box<S>
|
||||
where
|
||||
S: Source + ?Sized,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Arc<S>
|
||||
where
|
||||
S: Source + ?Sized,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Rc<S>
|
||||
where
|
||||
S: Source + ?Sized,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Source for Vec<S>
|
||||
where
|
||||
S: Source,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
Source::visit(&**self, visitor)
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
Source::get(&**self, key)
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
Source::count(&**self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'kvs, V> VisitSource<'kvs> for Box<V>
|
||||
where
|
||||
V: VisitSource<'kvs> + ?Sized,
|
||||
{
|
||||
fn visit_pair(&mut self, key: Key<'kvs>, value: Value<'kvs>) -> Result<(), Error> {
|
||||
(**self).visit_pair(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, S> Source for HashMap<K, V, S>
|
||||
where
|
||||
K: ToKey + Borrow<str> + Eq + Hash,
|
||||
V: ToValue,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
for (key, value) in self {
|
||||
visitor.visit_pair(key.to_key(), value.to_value())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
HashMap::get(self, key.as_str()).map(|v| v.to_value())
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V> Source for BTreeMap<K, V>
|
||||
where
|
||||
K: ToKey + Borrow<str> + Ord,
|
||||
V: ToValue,
|
||||
{
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
for (key, value) in self {
|
||||
visitor.visit_pair(key.to_key(), value.to_value())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(&self, key: Key) -> Option<Value<'_>> {
|
||||
BTreeMap::get(self, key.as_str()).map(|v| v.to_value())
|
||||
}
|
||||
|
||||
fn count(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::kv::value;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn count() {
|
||||
assert_eq!(1, Source::count(&Box::new(("a", 1))));
|
||||
assert_eq!(2, Source::count(&vec![("a", 1), ("b", 2)]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get() {
|
||||
let source = vec![("a", 1), ("b", 2), ("a", 1)];
|
||||
assert_eq!(
|
||||
value::inner::Token::I64(1),
|
||||
Source::get(&source, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
|
||||
let source = Box::new(None::<(&str, i32)>);
|
||||
assert!(Source::get(&source, Key::from_str("a")).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_map() {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("a", 1);
|
||||
map.insert("b", 2);
|
||||
|
||||
assert_eq!(2, Source::count(&map));
|
||||
assert_eq!(
|
||||
value::inner::Token::I64(1),
|
||||
Source::get(&map, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn btree_map() {
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert("a", 1);
|
||||
map.insert("b", 2);
|
||||
|
||||
assert_eq!(2, Source::count(&map));
|
||||
assert_eq!(
|
||||
value::inner::Token::I64(1),
|
||||
Source::get(&map, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Deprecated; but aliases can't carry this attribute
|
||||
#[cfg(feature = "kv_unstable")]
|
||||
pub use VisitSource as Visitor;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::kv::value;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn source_is_object_safe() {
|
||||
fn _check(_: &dyn Source) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visitor_is_object_safe() {
|
||||
fn _check(_: &dyn VisitSource) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count() {
|
||||
struct OnePair {
|
||||
key: &'static str,
|
||||
value: i32,
|
||||
}
|
||||
|
||||
impl Source for OnePair {
|
||||
fn visit<'kvs>(&'kvs self, visitor: &mut dyn VisitSource<'kvs>) -> Result<(), Error> {
|
||||
visitor.visit_pair(self.key.to_key(), self.value.to_value())
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(1, Source::count(&("a", 1)));
|
||||
assert_eq!(2, Source::count(&[("a", 1), ("b", 2)] as &[_]));
|
||||
assert_eq!(0, Source::count(&None::<(&str, i32)>));
|
||||
assert_eq!(1, Source::count(&OnePair { key: "a", value: 1 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get() {
|
||||
let source = &[("a", 1), ("b", 2), ("a", 1)] as &[_];
|
||||
assert_eq!(
|
||||
value::inner::Token::I64(1),
|
||||
Source::get(source, Key::from_str("a")).unwrap().to_token()
|
||||
);
|
||||
assert_eq!(
|
||||
value::inner::Token::I64(2),
|
||||
Source::get(source, Key::from_str("b")).unwrap().to_token()
|
||||
);
|
||||
assert!(Source::get(&source, Key::from_str("c")).is_none());
|
||||
|
||||
let source = None::<(&str, i32)>;
|
||||
assert!(Source::get(&source, Key::from_str("a")).is_none());
|
||||
}
|
||||
}
|
||||
Vendored
+1396
File diff suppressed because it is too large.
Load diff
Vendored
+2010
File diff suppressed because it is too large.
Load diff
Vendored
+579
@@ -0,0 +1,579 @@
|
||||
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
/// The standard logging macro.
|
||||
///
|
||||
/// This macro will generically log with the specified `Level` and `format!`
|
||||
/// based argument list.
|
||||
///
|
||||
/// ```
|
||||
/// use log::{log, Level};
|
||||
///
|
||||
/// let data = (42, "Forty-two");
|
||||
/// let private_data = "private";
|
||||
///
|
||||
/// log!(Level::Error, "Received errors: {}, {}", data.0, data.1);
|
||||
/// ```
|
||||
///
|
||||
/// Optionally, you can specify a `target` argument to attach a specific target
|
||||
/// to the log record. By default, the target is the module path of the caller.
|
||||
///
|
||||
/// ```
|
||||
/// use log::{log, Level};
|
||||
///
|
||||
/// let data = (42, "Forty-two");
|
||||
/// let private_data = "private";
|
||||
///
|
||||
/// log!(
|
||||
/// target: "app_events",
|
||||
/// Level::Error,
|
||||
/// "Received errors: {}, {}",
|
||||
/// data.0, data.1
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// And optionally, you can specify a `logger` argument to use a specific logger
|
||||
/// instead of the default global logger.
|
||||
///
|
||||
/// ```
|
||||
/// # struct MyLogger {}
|
||||
/// # impl Log for MyLogger {
|
||||
/// # fn enabled(&self, _metadata: &log::Metadata) -> bool {
|
||||
/// # false
|
||||
/// # }
|
||||
/// # fn log(&self, _record: &log::Record) {}
|
||||
/// # fn flush(&self) {}
|
||||
/// # }
|
||||
/// use log::{log, Level, Log};
|
||||
///
|
||||
/// let data = (42, "Forty-two");
|
||||
/// let private_data = "private";
|
||||
///
|
||||
/// let my_logger = MyLogger {};
|
||||
/// log!(
|
||||
/// logger: my_logger,
|
||||
/// Level::Error,
|
||||
/// "Received errors: {}, {}",
|
||||
/// data.0, data.1
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// The `logger` argument accepts a value that implements the `Log` trait. The value
|
||||
/// will be borrowed within the macro.
|
||||
///
|
||||
/// Note that the global level set via Cargo features, or through `set_max_level` will
|
||||
/// still apply, even when a custom logger is supplied with the `logger` argument.
|
||||
#[macro_export]
|
||||
#[clippy::format_args]
|
||||
macro_rules! log {
|
||||
// log!(logger: my_logger, target: "my_target", Level::Info, "a {} event", "log");
|
||||
(logger: $logger:expr, target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
|
||||
$crate::__log!(
|
||||
logger: $crate::__log_logger!($logger),
|
||||
target: $target,
|
||||
$lvl,
|
||||
$($arg)+
|
||||
)
|
||||
});
|
||||
|
||||
// log!(logger: my_logger, Level::Info, "a log event")
|
||||
(logger: $logger:expr, $lvl:expr, $($arg:tt)+) => ({
|
||||
$crate::__log!(
|
||||
logger: $crate::__log_logger!($logger),
|
||||
target: $crate::__private_api::module_path!(),
|
||||
$lvl,
|
||||
$($arg)+
|
||||
)
|
||||
});
|
||||
|
||||
// log!(target: "my_target", Level::Info, "a log event")
|
||||
(target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
|
||||
$crate::__log!(
|
||||
logger: $crate::__log_logger!(__log_global_logger),
|
||||
target: $target,
|
||||
$lvl,
|
||||
$($arg)+
|
||||
)
|
||||
});
|
||||
|
||||
// log!(Level::Info, "a log event")
|
||||
($lvl:expr, $($arg:tt)+) => ({
|
||||
$crate::__log!(
|
||||
logger: $crate::__log_logger!(__log_global_logger),
|
||||
target: $crate::__private_api::module_path!(),
|
||||
$lvl,
|
||||
$($arg)+
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __log {
|
||||
// log!(logger: my_logger, target: "my_target", Level::Info, key1:? = 42, key2 = true; "a {} event", "log");
|
||||
(logger: $logger:expr, target: $target:expr, $lvl:expr, $($key:tt $(:$capture:tt)? $(= $value:expr)?),+; $($arg:tt)+) => ({
|
||||
let lvl = $lvl;
|
||||
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
|
||||
$crate::__private_api::log(
|
||||
$logger,
|
||||
$crate::__private_api::format_args!($($arg)+),
|
||||
lvl,
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::loc()),
|
||||
&[$(($crate::__log_key!($key), $crate::__log_value!($key $(:$capture)* = $($value)*))),+] as &[_],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// log!(logger: my_logger, target: "my_target", Level::Info, "a {} event", "log");
|
||||
(logger: $logger:expr, target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
|
||||
let lvl = $lvl;
|
||||
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
|
||||
$crate::__private_api::log(
|
||||
$logger,
|
||||
$crate::__private_api::format_args!($($arg)+),
|
||||
lvl,
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::loc()),
|
||||
(),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Logs a message at the error level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use log::error;
|
||||
///
|
||||
/// # let my_logger = log::__private_api::GlobalLogger;
|
||||
/// let (err_info, port) = ("No connection", 22);
|
||||
///
|
||||
/// error!("Error: {err_info} on port {port}");
|
||||
/// error!(target: "app_events", "App Error: {err_info}, Port: {port}");
|
||||
/// error!(logger: my_logger, "App Error: {err_info}, Port: {port}");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[clippy::format_args]
|
||||
macro_rules! error {
|
||||
// error!(logger: my_logger, target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// error!(logger: my_logger, target: "my_target", "a {} event", "log")
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), target: $target, $crate::Level::Error, $($arg)+)
|
||||
});
|
||||
|
||||
// error!(logger: my_logger, key1 = 42, key2 = true; "a {} event", "log")
|
||||
// error!(logger: my_logger, "a {} event", "log")
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), $crate::Level::Error, $($arg)+)
|
||||
});
|
||||
|
||||
// error!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// error!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(target: $target, $crate::Level::Error, $($arg)+)
|
||||
});
|
||||
|
||||
// error!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Error, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the warn level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use log::warn;
|
||||
///
|
||||
/// # let my_logger = log::__private_api::GlobalLogger;
|
||||
/// let warn_description = "Invalid Input";
|
||||
///
|
||||
/// warn!("Warning! {warn_description}!");
|
||||
/// warn!(target: "input_events", "App received warning: {warn_description}");
|
||||
/// warn!(logger: my_logger, "App received warning: {warn_description}");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[clippy::format_args]
|
||||
macro_rules! warn {
|
||||
// warn!(logger: my_logger, target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// warn!(logger: my_logger, target: "my_target", "a {} event", "log")
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), target: $target, $crate::Level::Warn, $($arg)+)
|
||||
});
|
||||
|
||||
// warn!(logger: my_logger, key1 = 42, key2 = true; "a {} event", "log")
|
||||
// warn!(logger: my_logger, "a {} event", "log")
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), $crate::Level::Warn, $($arg)+)
|
||||
});
|
||||
|
||||
// warn!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// warn!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(target: $target, $crate::Level::Warn, $($arg)+)
|
||||
});
|
||||
|
||||
// warn!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Warn, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the info level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use log::info;
|
||||
///
|
||||
/// # let my_logger = log::__private_api::GlobalLogger;
|
||||
/// # struct Connection { port: u32, speed: f32 }
|
||||
/// let conn_info = Connection { port: 40, speed: 3.20 };
|
||||
///
|
||||
/// info!("Connected to port {} at {} Mb/s", conn_info.port, conn_info.speed);
|
||||
/// info!(
|
||||
/// target: "connection_events",
|
||||
/// "Successful connection, port: {}, speed: {}",
|
||||
/// conn_info.port, conn_info.speed
|
||||
/// );
|
||||
/// info!(
|
||||
/// logger: my_logger,
|
||||
/// "Successful connection, port: {}, speed: {}",
|
||||
/// conn_info.port, conn_info.speed
|
||||
/// );
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[clippy::format_args]
|
||||
macro_rules! info {
|
||||
// info!(logger: my_logger, target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// info!(logger: my_logger, target: "my_target", "a {} event", "log")
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), target: $target, $crate::Level::Info, $($arg)+)
|
||||
});
|
||||
|
||||
// info!(logger: my_logger, key1 = 42, key2 = true; "a {} event", "log")
|
||||
// info!(logger: my_logger, "a {} event", "log")
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), $crate::Level::Info, $($arg)+)
|
||||
});
|
||||
|
||||
// info!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// info!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(target: $target, $crate::Level::Info, $($arg)+)
|
||||
});
|
||||
|
||||
// info!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Info, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the debug level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use log::debug;
|
||||
///
|
||||
/// # let my_logger = log::__private_api::GlobalLogger;
|
||||
/// # struct Position { x: f32, y: f32 }
|
||||
/// let pos = Position { x: 3.234, y: -1.223 };
|
||||
///
|
||||
/// debug!("New position: x: {}, y: {}", pos.x, pos.y);
|
||||
/// debug!(target: "app_events", "New position: x: {}, y: {}", pos.x, pos.y);
|
||||
/// debug!(logger: my_logger, "New position: x: {}, y: {}", pos.x, pos.y);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[clippy::format_args]
|
||||
macro_rules! debug {
|
||||
// debug!(logger: my_logger, target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// debug!(logger: my_logger, target: "my_target", "a {} event", "log")
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), target: $target, $crate::Level::Debug, $($arg)+)
|
||||
});
|
||||
|
||||
// debug!(logger: my_logger, key1 = 42, key2 = true; "a {} event", "log")
|
||||
// debug!(logger: my_logger, "a {} event", "log")
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), $crate::Level::Debug, $($arg)+)
|
||||
});
|
||||
|
||||
// debug!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// debug!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(target: $target, $crate::Level::Debug, $($arg)+)
|
||||
});
|
||||
|
||||
// debug!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Debug, $($arg)+))
|
||||
}
|
||||
|
||||
/// Logs a message at the trace level.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use log::trace;
|
||||
///
|
||||
/// # let my_logger = log::__private_api::GlobalLogger;
|
||||
/// # struct Position { x: f32, y: f32 }
|
||||
/// let pos = Position { x: 3.234, y: -1.223 };
|
||||
///
|
||||
/// trace!("Position is: x: {}, y: {}", pos.x, pos.y);
|
||||
/// trace!(target: "app_events", "x is {} and y is {}",
|
||||
/// if pos.x >= 0.0 { "positive" } else { "negative" },
|
||||
/// if pos.y >= 0.0 { "positive" } else { "negative" });
|
||||
/// trace!(logger: my_logger, "x is {} and y is {}",
|
||||
/// if pos.x >= 0.0 { "positive" } else { "negative" },
|
||||
/// if pos.y >= 0.0 { "positive" } else { "negative" });
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[clippy::format_args]
|
||||
macro_rules! trace {
|
||||
// trace!(logger: my_logger, target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// trace!(logger: my_logger, target: "my_target", "a {} event", "log")
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), target: $target, $crate::Level::Trace, $($arg)+)
|
||||
});
|
||||
|
||||
// trace!(logger: my_logger, key1 = 42, key2 = true; "a {} event", "log")
|
||||
// trace!(logger: my_logger, "a {} event", "log")
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(logger: $crate::__log_logger!($logger), $crate::Level::Trace, $($arg)+)
|
||||
});
|
||||
|
||||
// trace!(target: "my_target", key1 = 42, key2 = true; "a {} event", "log")
|
||||
// trace!(target: "my_target", "a {} event", "log")
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
$crate::log!(target: $target, $crate::Level::Trace, $($arg)+)
|
||||
});
|
||||
|
||||
// trace!("a {} event", "log")
|
||||
($($arg:tt)+) => ($crate::log!($crate::Level::Trace, $($arg)+))
|
||||
}
|
||||
|
||||
/// Determines if a message logged at the specified level in that module will
|
||||
/// be logged.
|
||||
///
|
||||
/// This can be used to avoid expensive computation of log message arguments if
|
||||
/// the message would be ignored anyway.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use log::{debug, log_enabled, Level};
|
||||
///
|
||||
/// # struct Data { x: u32, y: u32 }
|
||||
/// # fn expensive_call() -> Data { Data { x: 0, y: 0 } }
|
||||
/// # let my_logger = log::__private_api::GlobalLogger;
|
||||
/// if log_enabled!(Level::Debug) {
|
||||
/// let data = expensive_call();
|
||||
/// debug!("expensive debug data: {} {}", data.x, data.y);
|
||||
/// }
|
||||
///
|
||||
/// if log_enabled!(target: "Global", Level::Debug) {
|
||||
/// let data = expensive_call();
|
||||
/// debug!(target: "Global", "expensive debug data: {} {}", data.x, data.y);
|
||||
/// }
|
||||
///
|
||||
/// if log_enabled!(logger: my_logger, Level::Debug) {
|
||||
/// let data = expensive_call();
|
||||
/// debug!(target: "Global", "expensive debug data: {} {}", data.x, data.y);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This macro accepts the same `target` and `logger` arguments as [`macro@log`].
|
||||
#[macro_export]
|
||||
macro_rules! log_enabled {
|
||||
// log_enabled!(logger: my_logger, target: "my_target", Level::Info)
|
||||
(logger: $logger:expr, target: $target:expr, $lvl:expr) => ({
|
||||
$crate::__log_enabled!(logger: $crate::__log_logger!($logger), target: $target, $lvl)
|
||||
});
|
||||
|
||||
// log_enabled!(logger: my_logger, Level::Info)
|
||||
(logger: $logger:expr, $lvl:expr) => ({
|
||||
$crate::__log_enabled!(logger: $crate::__log_logger!($logger), target: $crate::__private_api::module_path!(), $lvl)
|
||||
});
|
||||
|
||||
// log_enabled!(target: "my_target", Level::Info)
|
||||
(target: $target:expr, $lvl:expr) => ({
|
||||
$crate::__log_enabled!(logger: $crate::__log_logger!(__log_global_logger), target: $target, $lvl)
|
||||
});
|
||||
|
||||
// log_enabled!(Level::Info)
|
||||
($lvl:expr) => ({
|
||||
$crate::__log_enabled!(logger: $crate::__log_logger!(__log_global_logger), target: $crate::__private_api::module_path!(), $lvl)
|
||||
});
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __log_enabled {
|
||||
// log_enabled!(logger: my_logger, target: "my_target", Level::Info)
|
||||
(logger: $logger:expr, target: $target:expr, $lvl:expr) => {{
|
||||
let lvl = $lvl;
|
||||
lvl <= $crate::STATIC_MAX_LEVEL
|
||||
&& lvl <= $crate::max_level()
|
||||
&& $crate::__private_api::enabled($logger, lvl, $target)
|
||||
}};
|
||||
}
|
||||
|
||||
// Determine the logger to use, and whether to take it by-value or by reference
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __log_logger {
|
||||
(__log_global_logger) => {{
|
||||
$crate::__private_api::GlobalLogger
|
||||
}};
|
||||
|
||||
($logger:expr) => {{
|
||||
&($logger)
|
||||
}};
|
||||
}
|
||||
|
||||
// These macros use a pattern of #[cfg]s to produce nicer error
|
||||
// messages when log features aren't available
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(feature = "kv")]
|
||||
macro_rules! __log_key {
|
||||
// key1 = 42
|
||||
($($args:ident)*) => {
|
||||
$crate::__private_api::stringify!($($args)*)
|
||||
};
|
||||
// "key1" = 42
|
||||
($($args:expr)*) => {
|
||||
$($args)*
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "kv"))]
|
||||
macro_rules! __log_key {
|
||||
($($args:tt)*) => {
|
||||
compile_error!("key value support requires the `kv` feature of `log`")
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(feature = "kv")]
|
||||
macro_rules! __log_value {
|
||||
// Entrypoint
|
||||
($key:tt = $args:expr) => {
|
||||
$crate::__log_value!(($args):value)
|
||||
};
|
||||
($key:tt :$capture:tt = $args:expr) => {
|
||||
$crate::__log_value!(($args):$capture)
|
||||
};
|
||||
($key:ident =) => {
|
||||
$crate::__log_value!(($key):value)
|
||||
};
|
||||
($key:ident :$capture:tt =) => {
|
||||
$crate::__log_value!(($key):$capture)
|
||||
};
|
||||
// ToValue
|
||||
(($args:expr):value) => {
|
||||
$crate::__private_api::capture_to_value(&&$args)
|
||||
};
|
||||
// Debug
|
||||
(($args:expr):?) => {
|
||||
$crate::__private_api::capture_debug(&&$args)
|
||||
};
|
||||
(($args:expr):debug) => {
|
||||
$crate::__private_api::capture_debug(&&$args)
|
||||
};
|
||||
// Display
|
||||
(($args:expr):%) => {
|
||||
$crate::__private_api::capture_display(&&$args)
|
||||
};
|
||||
(($args:expr):display) => {
|
||||
$crate::__private_api::capture_display(&&$args)
|
||||
};
|
||||
//Error
|
||||
(($args:expr):err) => {
|
||||
$crate::__log_value_error!($args)
|
||||
};
|
||||
// sval::Value
|
||||
(($args:expr):sval) => {
|
||||
$crate::__log_value_sval!($args)
|
||||
};
|
||||
// serde::Serialize
|
||||
(($args:expr):serde) => {
|
||||
$crate::__log_value_serde!($args)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "kv"))]
|
||||
macro_rules! __log_value {
|
||||
($($args:tt)*) => {
|
||||
compile_error!("key value support requires the `kv` feature of `log`")
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(feature = "kv_sval")]
|
||||
macro_rules! __log_value_sval {
|
||||
($args:expr) => {
|
||||
$crate::__private_api::capture_sval(&&$args)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "kv_sval"))]
|
||||
macro_rules! __log_value_sval {
|
||||
($args:expr) => {
|
||||
compile_error!("capturing values as `sval::Value` requites the `kv_sval` feature of `log`")
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(feature = "kv_serde")]
|
||||
macro_rules! __log_value_serde {
|
||||
($args:expr) => {
|
||||
$crate::__private_api::capture_serde(&&$args)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "kv_serde"))]
|
||||
macro_rules! __log_value_serde {
|
||||
($args:expr) => {
|
||||
compile_error!(
|
||||
"capturing values as `serde::Serialize` requites the `kv_serde` feature of `log`"
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(feature = "kv_std")]
|
||||
macro_rules! __log_value_error {
|
||||
($args:expr) => {
|
||||
$crate::__private_api::capture_error(&$args)
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "kv_std"))]
|
||||
macro_rules! __log_value_error {
|
||||
($args:expr) => {
|
||||
compile_error!(
|
||||
"capturing values as `std::error::Error` requites the `kv_std` feature of `log`"
|
||||
)
|
||||
};
|
||||
}
|
||||
Vendored
+397
@@ -0,0 +1,397 @@
|
||||
#![cfg(feature = "serde_core")]
|
||||
|
||||
use serde_core::de::{
|
||||
Deserialize, DeserializeSeed, Deserializer, EnumAccess, Error, Unexpected, VariantAccess,
|
||||
Visitor,
|
||||
};
|
||||
use serde_core::ser::{Serialize, Serializer};
|
||||
|
||||
use crate::{Level, LevelFilter, LOG_LEVEL_NAMES};
|
||||
|
||||
use std::fmt;
|
||||
use std::str::{self, FromStr};
|
||||
|
||||
// The Deserialize impls are handwritten to be case-insensitive using FromStr.
|
||||
|
||||
impl Serialize for Level {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match *self {
|
||||
Level::Error => serializer.serialize_unit_variant("Level", 0, "ERROR"),
|
||||
Level::Warn => serializer.serialize_unit_variant("Level", 1, "WARN"),
|
||||
Level::Info => serializer.serialize_unit_variant("Level", 2, "INFO"),
|
||||
Level::Debug => serializer.serialize_unit_variant("Level", 3, "DEBUG"),
|
||||
Level::Trace => serializer.serialize_unit_variant("Level", 4, "TRACE"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for Level {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct LevelIdentifier;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelIdentifier {
|
||||
type Value = Level;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level")
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = LOG_LEVEL_NAMES[1..]
|
||||
.get(v as usize)
|
||||
.ok_or_else(|| Error::invalid_value(Unexpected::Unsigned(v), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
// Case-insensitive.
|
||||
FromStr::from_str(s).map_err(|_| Error::unknown_variant(s, &LOG_LEVEL_NAMES[1..]))
|
||||
}
|
||||
|
||||
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = str::from_utf8(value)
|
||||
.map_err(|_| Error::invalid_value(Unexpected::Bytes(value), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> DeserializeSeed<'de> for LevelIdentifier {
|
||||
type Value = Level;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_identifier(LevelIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
struct LevelEnum;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelEnum {
|
||||
type Value = Level;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level")
|
||||
}
|
||||
|
||||
fn visit_enum<A>(self, value: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: EnumAccess<'de>,
|
||||
{
|
||||
let (level, variant) = value.variant_seed(LevelIdentifier)?;
|
||||
// Every variant is a unit variant.
|
||||
variant.unit_variant()?;
|
||||
Ok(level)
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_enum("Level", &LOG_LEVEL_NAMES[1..], LevelEnum)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for LevelFilter {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
match *self {
|
||||
LevelFilter::Off => serializer.serialize_unit_variant("LevelFilter", 0, "OFF"),
|
||||
LevelFilter::Error => serializer.serialize_unit_variant("LevelFilter", 1, "ERROR"),
|
||||
LevelFilter::Warn => serializer.serialize_unit_variant("LevelFilter", 2, "WARN"),
|
||||
LevelFilter::Info => serializer.serialize_unit_variant("LevelFilter", 3, "INFO"),
|
||||
LevelFilter::Debug => serializer.serialize_unit_variant("LevelFilter", 4, "DEBUG"),
|
||||
LevelFilter::Trace => serializer.serialize_unit_variant("LevelFilter", 5, "TRACE"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for LevelFilter {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct LevelFilterIdentifier;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelFilterIdentifier {
|
||||
type Value = LevelFilter;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level filter")
|
||||
}
|
||||
|
||||
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = LOG_LEVEL_NAMES
|
||||
.get(v as usize)
|
||||
.ok_or_else(|| Error::invalid_value(Unexpected::Unsigned(v), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
// Case-insensitive.
|
||||
FromStr::from_str(s).map_err(|_| Error::unknown_variant(s, &LOG_LEVEL_NAMES))
|
||||
}
|
||||
|
||||
fn visit_bytes<E>(self, value: &[u8]) -> Result<Self::Value, E>
|
||||
where
|
||||
E: Error,
|
||||
{
|
||||
let variant = str::from_utf8(value)
|
||||
.map_err(|_| Error::invalid_value(Unexpected::Bytes(value), &self))?;
|
||||
|
||||
self.visit_str(variant)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> DeserializeSeed<'de> for LevelFilterIdentifier {
|
||||
type Value = LevelFilter;
|
||||
|
||||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_identifier(LevelFilterIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
struct LevelFilterEnum;
|
||||
|
||||
impl<'de> Visitor<'de> for LevelFilterEnum {
|
||||
type Value = LevelFilter;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("log level filter")
|
||||
}
|
||||
|
||||
fn visit_enum<A>(self, value: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: EnumAccess<'de>,
|
||||
{
|
||||
let (level_filter, variant) = value.variant_seed(LevelFilterIdentifier)?;
|
||||
// Every variant is a unit variant.
|
||||
variant.unit_variant()?;
|
||||
Ok(level_filter)
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_enum("LevelFilter", &LOG_LEVEL_NAMES, LevelFilterEnum)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{Level, LevelFilter};
|
||||
use serde_test::{assert_de_tokens, assert_de_tokens_error, assert_tokens, Token};
|
||||
|
||||
fn level_token(variant: &'static str) -> Token {
|
||||
Token::UnitVariant {
|
||||
name: "Level",
|
||||
variant,
|
||||
}
|
||||
}
|
||||
|
||||
fn level_bytes_tokens(variant: &'static [u8]) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum { name: "Level" },
|
||||
Token::Bytes(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
fn level_variant_tokens(variant: u32) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum { name: "Level" },
|
||||
Token::U32(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
fn level_filter_token(variant: &'static str) -> Token {
|
||||
Token::UnitVariant {
|
||||
name: "LevelFilter",
|
||||
variant,
|
||||
}
|
||||
}
|
||||
|
||||
fn level_filter_bytes_tokens(variant: &'static [u8]) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum {
|
||||
name: "LevelFilter",
|
||||
},
|
||||
Token::Bytes(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
fn level_filter_variant_tokens(variant: u32) -> [Token; 3] {
|
||||
[
|
||||
Token::Enum {
|
||||
name: "LevelFilter",
|
||||
},
|
||||
Token::U32(variant),
|
||||
Token::Unit,
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_ser_de() {
|
||||
let cases = &[
|
||||
(Level::Error, [level_token("ERROR")]),
|
||||
(Level::Warn, [level_token("WARN")]),
|
||||
(Level::Info, [level_token("INFO")]),
|
||||
(Level::Debug, [level_token("DEBUG")]),
|
||||
(Level::Trace, [level_token("TRACE")]),
|
||||
];
|
||||
|
||||
for (s, expected) in cases {
|
||||
assert_tokens(s, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_case_insensitive() {
|
||||
let cases = &[
|
||||
(Level::Error, [level_token("error")]),
|
||||
(Level::Warn, [level_token("warn")]),
|
||||
(Level::Info, [level_token("info")]),
|
||||
(Level::Debug, [level_token("debug")]),
|
||||
(Level::Trace, [level_token("trace")]),
|
||||
];
|
||||
|
||||
for (s, expected) in cases {
|
||||
assert_de_tokens(s, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_de_bytes() {
|
||||
let cases = &[
|
||||
(Level::Error, level_bytes_tokens(b"ERROR")),
|
||||
(Level::Warn, level_bytes_tokens(b"WARN")),
|
||||
(Level::Info, level_bytes_tokens(b"INFO")),
|
||||
(Level::Debug, level_bytes_tokens(b"DEBUG")),
|
||||
(Level::Trace, level_bytes_tokens(b"TRACE")),
|
||||
];
|
||||
|
||||
for (value, tokens) in cases {
|
||||
assert_de_tokens(value, tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_de_variant_index() {
|
||||
let cases = &[
|
||||
(Level::Error, level_variant_tokens(0)),
|
||||
(Level::Warn, level_variant_tokens(1)),
|
||||
(Level::Info, level_variant_tokens(2)),
|
||||
(Level::Debug, level_variant_tokens(3)),
|
||||
(Level::Trace, level_variant_tokens(4)),
|
||||
];
|
||||
|
||||
for (value, tokens) in cases {
|
||||
assert_de_tokens(value, tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_de_error() {
|
||||
let msg = "unknown variant `errorx`, expected one of \
|
||||
`ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`";
|
||||
assert_de_tokens_error::<Level>(&[level_token("errorx")], msg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_ser_de() {
|
||||
let cases = &[
|
||||
(LevelFilter::Off, [level_filter_token("OFF")]),
|
||||
(LevelFilter::Error, [level_filter_token("ERROR")]),
|
||||
(LevelFilter::Warn, [level_filter_token("WARN")]),
|
||||
(LevelFilter::Info, [level_filter_token("INFO")]),
|
||||
(LevelFilter::Debug, [level_filter_token("DEBUG")]),
|
||||
(LevelFilter::Trace, [level_filter_token("TRACE")]),
|
||||
];
|
||||
|
||||
for (s, expected) in cases {
|
||||
assert_tokens(s, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_case_insensitive() {
|
||||
let cases = &[
|
||||
(LevelFilter::Off, [level_filter_token("off")]),
|
||||
(LevelFilter::Error, [level_filter_token("error")]),
|
||||
(LevelFilter::Warn, [level_filter_token("warn")]),
|
||||
(LevelFilter::Info, [level_filter_token("info")]),
|
||||
(LevelFilter::Debug, [level_filter_token("debug")]),
|
||||
(LevelFilter::Trace, [level_filter_token("trace")]),
|
||||
];
|
||||
|
||||
for (s, expected) in cases {
|
||||
assert_de_tokens(s, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_de_bytes() {
|
||||
let cases = &[
|
||||
(LevelFilter::Off, level_filter_bytes_tokens(b"OFF")),
|
||||
(LevelFilter::Error, level_filter_bytes_tokens(b"ERROR")),
|
||||
(LevelFilter::Warn, level_filter_bytes_tokens(b"WARN")),
|
||||
(LevelFilter::Info, level_filter_bytes_tokens(b"INFO")),
|
||||
(LevelFilter::Debug, level_filter_bytes_tokens(b"DEBUG")),
|
||||
(LevelFilter::Trace, level_filter_bytes_tokens(b"TRACE")),
|
||||
];
|
||||
|
||||
for (value, tokens) in cases {
|
||||
assert_de_tokens(value, tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_de_variant_index() {
|
||||
let cases = &[
|
||||
(LevelFilter::Off, level_filter_variant_tokens(0)),
|
||||
(LevelFilter::Error, level_filter_variant_tokens(1)),
|
||||
(LevelFilter::Warn, level_filter_variant_tokens(2)),
|
||||
(LevelFilter::Info, level_filter_variant_tokens(3)),
|
||||
(LevelFilter::Debug, level_filter_variant_tokens(4)),
|
||||
(LevelFilter::Trace, level_filter_variant_tokens(5)),
|
||||
];
|
||||
|
||||
for (value, tokens) in cases {
|
||||
assert_de_tokens(value, tokens);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_level_filter_de_error() {
|
||||
let msg = "unknown variant `errorx`, expected one of \
|
||||
`OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`";
|
||||
assert_de_tokens_error::<LevelFilter>(&[level_filter_token("errorx")], msg);
|
||||
}
|
||||
}
|
||||
Vendored
+101
@@ -0,0 +1,101 @@
|
||||
#![allow(dead_code, unused_imports)]
|
||||
|
||||
use log::{debug, error, info, trace, warn, Level, LevelFilter, Log, Metadata, Record};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
struct State {
|
||||
last_log_level: Mutex<Option<Level>>,
|
||||
last_log_location: Mutex<Option<u32>>,
|
||||
}
|
||||
|
||||
struct Logger(Arc<State>);
|
||||
|
||||
impl Log for Logger {
|
||||
fn enabled(&self, _: &Metadata) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
*self.0.last_log_level.lock().unwrap() = Some(record.level());
|
||||
*self.0.last_log_location.lock().unwrap() = record.line();
|
||||
}
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_integration() {
|
||||
// These tests don't really make sense when static
|
||||
// max level filtering is applied
|
||||
#[cfg(not(any(
|
||||
feature = "max_level_off",
|
||||
feature = "max_level_error",
|
||||
feature = "max_level_warn",
|
||||
feature = "max_level_info",
|
||||
feature = "max_level_debug",
|
||||
feature = "max_level_trace",
|
||||
feature = "release_max_level_off",
|
||||
feature = "release_max_level_error",
|
||||
feature = "release_max_level_warn",
|
||||
feature = "release_max_level_info",
|
||||
feature = "release_max_level_debug",
|
||||
feature = "release_max_level_trace",
|
||||
)))]
|
||||
{
|
||||
let me = Arc::new(State {
|
||||
last_log_level: Mutex::new(None),
|
||||
last_log_location: Mutex::new(None),
|
||||
});
|
||||
let a = me.clone();
|
||||
let logger = Logger(me);
|
||||
|
||||
test_filter(&logger, &a, LevelFilter::Off);
|
||||
test_filter(&logger, &a, LevelFilter::Error);
|
||||
test_filter(&logger, &a, LevelFilter::Warn);
|
||||
test_filter(&logger, &a, LevelFilter::Info);
|
||||
test_filter(&logger, &a, LevelFilter::Debug);
|
||||
test_filter(&logger, &a, LevelFilter::Trace);
|
||||
|
||||
test_line_numbers(&logger, &a);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_filter(logger: &dyn Log, a: &State, filter: LevelFilter) {
|
||||
// tests to ensure logs with a level beneath 'max_level' are filtered out
|
||||
log::set_max_level(filter);
|
||||
error!(logger: logger, "");
|
||||
last(a, t(Level::Error, filter));
|
||||
warn!(logger: logger, "");
|
||||
last(a, t(Level::Warn, filter));
|
||||
info!(logger: logger, "");
|
||||
last(a, t(Level::Info, filter));
|
||||
debug!(logger: logger, "");
|
||||
last(a, t(Level::Debug, filter));
|
||||
trace!(logger: logger, "");
|
||||
last(a, t(Level::Trace, filter));
|
||||
|
||||
fn t(lvl: Level, filter: LevelFilter) -> Option<Level> {
|
||||
if lvl <= filter {
|
||||
Some(lvl)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn last(state: &State, expected: Option<Level>) {
|
||||
let lvl = state.last_log_level.lock().unwrap().take();
|
||||
assert_eq!(lvl, expected);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_line_numbers(logger: &dyn Log, state: &State) {
|
||||
log::set_max_level(LevelFilter::Trace);
|
||||
|
||||
info!(logger: logger, ""); // ensure check_line function follows log macro
|
||||
check_log_location(state);
|
||||
|
||||
#[track_caller]
|
||||
fn check_log_location(state: &State) {
|
||||
let location = std::panic::Location::caller().line(); // get function calling location
|
||||
let line_number = state.last_log_location.lock().unwrap().take().unwrap(); // get location of most recent log
|
||||
assert_eq!(line_number, location - 1);
|
||||
}
|
||||
}
|
||||
Vendored
+429
@@ -0,0 +1,429 @@
|
||||
use log::{log, log_enabled, Log, Metadata, Record};
|
||||
|
||||
macro_rules! all_log_macros {
|
||||
($($arg:tt)*) => ({
|
||||
::log::trace!($($arg)*);
|
||||
::log::debug!($($arg)*);
|
||||
::log::info!($($arg)*);
|
||||
::log::warn!($($arg)*);
|
||||
::log::error!($($arg)*);
|
||||
});
|
||||
}
|
||||
|
||||
// Not `Copy`
|
||||
struct Logger;
|
||||
|
||||
impl Log for Logger {
|
||||
fn enabled(&self, _: &Metadata) -> bool {
|
||||
false
|
||||
}
|
||||
fn log(&self, _: &Record) {}
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_args() {
|
||||
let logger = Logger;
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(lvl, "hello");
|
||||
log!(lvl, "hello",);
|
||||
|
||||
log!(target: "my_target", lvl, "hello");
|
||||
log!(target: "my_target", lvl, "hello",);
|
||||
|
||||
log!(logger: logger, lvl, "hello");
|
||||
log!(logger: logger, lvl, "hello",);
|
||||
|
||||
log!(logger: logger, target: "my_target", lvl, "hello");
|
||||
log!(logger: logger, target: "my_target", lvl, "hello",);
|
||||
}
|
||||
|
||||
all_log_macros!("hello");
|
||||
all_log_macros!("hello",);
|
||||
|
||||
all_log_macros!(target: "my_target", "hello");
|
||||
all_log_macros!(target: "my_target", "hello",);
|
||||
|
||||
all_log_macros!(logger: logger, "hello");
|
||||
all_log_macros!(logger: logger, "hello",);
|
||||
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello");
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello",);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn anonymous_args() {
|
||||
for lvl in log::Level::iter() {
|
||||
log!(lvl, "hello {}", "world");
|
||||
log!(lvl, "hello {}", "world",);
|
||||
|
||||
log!(target: "my_target", lvl, "hello {}", "world");
|
||||
log!(target: "my_target", lvl, "hello {}", "world",);
|
||||
|
||||
log!(lvl, "hello {}", "world");
|
||||
log!(lvl, "hello {}", "world",);
|
||||
}
|
||||
|
||||
all_log_macros!("hello {}", "world");
|
||||
all_log_macros!("hello {}", "world",);
|
||||
|
||||
all_log_macros!(target: "my_target", "hello {}", "world");
|
||||
all_log_macros!(target: "my_target", "hello {}", "world",);
|
||||
|
||||
let logger = Logger;
|
||||
|
||||
all_log_macros!(logger: logger, "hello {}", "world");
|
||||
all_log_macros!(logger: logger, "hello {}", "world",);
|
||||
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello {}", "world");
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello {}", "world",);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn named_args() {
|
||||
for lvl in log::Level::iter() {
|
||||
log!(lvl, "hello {world}", world = "world");
|
||||
log!(lvl, "hello {world}", world = "world",);
|
||||
|
||||
log!(target: "my_target", lvl, "hello {world}", world = "world");
|
||||
log!(target: "my_target", lvl, "hello {world}", world = "world",);
|
||||
|
||||
log!(lvl, "hello {world}", world = "world");
|
||||
log!(lvl, "hello {world}", world = "world",);
|
||||
}
|
||||
|
||||
all_log_macros!("hello {world}", world = "world");
|
||||
all_log_macros!("hello {world}", world = "world",);
|
||||
|
||||
all_log_macros!(target: "my_target", "hello {world}", world = "world");
|
||||
all_log_macros!(target: "my_target", "hello {world}", world = "world",);
|
||||
|
||||
let logger = Logger;
|
||||
|
||||
all_log_macros!(logger: logger, "hello {world}", world = "world");
|
||||
all_log_macros!(logger: logger, "hello {world}", world = "world",);
|
||||
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello {world}", world = "world");
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello {world}", world = "world",);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inlined_args() {
|
||||
let world = "world";
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(lvl, "hello {world}");
|
||||
log!(lvl, "hello {world}",);
|
||||
|
||||
log!(target: "my_target", lvl, "hello {world}");
|
||||
log!(target: "my_target", lvl, "hello {world}",);
|
||||
|
||||
log!(lvl, "hello {world}");
|
||||
log!(lvl, "hello {world}",);
|
||||
}
|
||||
|
||||
all_log_macros!("hello {world}");
|
||||
all_log_macros!("hello {world}",);
|
||||
|
||||
all_log_macros!(target: "my_target", "hello {world}");
|
||||
all_log_macros!(target: "my_target", "hello {world}",);
|
||||
|
||||
let logger = Logger;
|
||||
|
||||
all_log_macros!(logger: logger, "hello {world}");
|
||||
all_log_macros!(logger: logger, "hello {world}",);
|
||||
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello {world}");
|
||||
all_log_macros!(logger: logger, target: "my_target", "hello {world}",);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enabled() {
|
||||
let logger = Logger;
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
let _enabled = log_enabled!(lvl);
|
||||
let _enabled = log_enabled!(target: "my_target", lvl);
|
||||
let _enabled = log_enabled!(logger: logger, target: "my_target", lvl);
|
||||
let _enabled = log_enabled!(logger: logger, lvl);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expr() {
|
||||
let logger = Logger;
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(lvl, "hello");
|
||||
|
||||
log!(logger: logger, lvl, "hello");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_no_args() {
|
||||
let logger = Logger;
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
|
||||
log!(logger: logger, target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
log!(logger: logger, lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
}
|
||||
|
||||
all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
|
||||
all_log_macros!(logger: logger, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
all_log_macros!(logger: logger, target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_expr_args() {
|
||||
let logger = Logger;
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(target: "my_target", lvl, cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
|
||||
log!(lvl, target = "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
log!(lvl, cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
|
||||
log!(logger: logger, target: "my_target", lvl, cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
|
||||
log!(logger: logger, lvl, target = "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
log!(logger: logger, lvl, cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
}
|
||||
|
||||
all_log_macros!(target: "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
all_log_macros!(target = "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
all_log_macros!(cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
|
||||
all_log_macros!(logger: logger, target: "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
all_log_macros!(logger: logger, target = "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
all_log_macros!(logger: logger, cat_math = { let mut x = 0; x += 1; x + 1 }; "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_anonymous_args() {
|
||||
let logger = Logger;
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
log!(lvl, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
|
||||
log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
|
||||
log!(logger: logger, target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
log!(logger: logger, lvl, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
|
||||
log!(logger: logger, lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
}
|
||||
|
||||
all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
|
||||
all_log_macros!(logger: logger, target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
all_log_macros!(logger: logger, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
all_log_macros!(logger: logger, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_named_args() {
|
||||
let logger = Logger;
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
log!(lvl, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
|
||||
log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
|
||||
log!(logger: logger, target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
log!(logger: logger, lvl, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
|
||||
log!(logger: logger, lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
}
|
||||
|
||||
all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
|
||||
all_log_macros!(logger: logger, target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
all_log_macros!(logger: logger, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
all_log_macros!(logger: logger, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_ident() {
|
||||
let cat_1 = "chashu";
|
||||
let cat_2 = "nori";
|
||||
|
||||
all_log_macros!(cat_1, cat_2:%, cat_count = 2; "hello {world}", world = "world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_expr_context() {
|
||||
match "chashu" {
|
||||
cat_1 => {
|
||||
log::info!(target: "target", cat_1 = cat_1, cat_2 = "nori"; "hello {}", "cats");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn implicit_named_args() {
|
||||
let world = "world";
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(lvl, "hello {world}");
|
||||
log!(lvl, "hello {world}",);
|
||||
|
||||
log!(target: "my_target", lvl, "hello {world}");
|
||||
log!(target: "my_target", lvl, "hello {world}",);
|
||||
|
||||
log!(lvl, "hello {world}");
|
||||
log!(lvl, "hello {world}",);
|
||||
}
|
||||
|
||||
all_log_macros!("hello {world}");
|
||||
all_log_macros!("hello {world}",);
|
||||
|
||||
all_log_macros!(target: "my_target", "hello {world}");
|
||||
all_log_macros!(target: "my_target", "hello {world}",);
|
||||
|
||||
#[cfg(feature = "kv")]
|
||||
all_log_macros!(target = "my_target"; "hello {world}");
|
||||
#[cfg(feature = "kv")]
|
||||
all_log_macros!(target = "my_target"; "hello {world}",);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_implicit_named_args() {
|
||||
let world = "world";
|
||||
|
||||
for lvl in log::Level::iter() {
|
||||
log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}");
|
||||
|
||||
log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}");
|
||||
}
|
||||
|
||||
all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}");
|
||||
all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}");
|
||||
all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_string_keys() {
|
||||
for lvl in log::Level::iter() {
|
||||
log!(target: "my_target", lvl, "also dogs" = "Fílos", "key/that-can't/be/an/ident" = "hi"; "hello {world}", world = "world");
|
||||
}
|
||||
|
||||
all_log_macros!(target: "my_target", "also dogs" = "Fílos", "key/that-can't/be/an/ident" = "hi"; "hello {world}", world = "world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_common_value_types() {
|
||||
all_log_macros!(
|
||||
u8 = 42u8,
|
||||
u16 = 42u16,
|
||||
u32 = 42u32,
|
||||
u64 = 42u64,
|
||||
u128 = 42u128,
|
||||
i8 = -42i8,
|
||||
i16 = -42i16,
|
||||
i32 = -42i32,
|
||||
i64 = -42i64,
|
||||
i128 = -42i128,
|
||||
f32 = 4.2f32,
|
||||
f64 = -4.2f64,
|
||||
bool = true,
|
||||
str = "string";
|
||||
"hello world"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_debug() {
|
||||
all_log_macros!(
|
||||
a:? = 42,
|
||||
b:debug = 42;
|
||||
"hello world"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv")]
|
||||
fn kv_display() {
|
||||
all_log_macros!(
|
||||
a:% = 42,
|
||||
b:display = 42;
|
||||
"hello world"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv_std")]
|
||||
fn kv_error() {
|
||||
all_log_macros!(
|
||||
a:err = std::io::Error::new(std::io::ErrorKind::Other, "an error");
|
||||
"hello world"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv_sval")]
|
||||
fn kv_sval() {
|
||||
all_log_macros!(
|
||||
a:sval = 42;
|
||||
"hello world"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv_serde")]
|
||||
fn kv_serde() {
|
||||
all_log_macros!(
|
||||
a:serde = 42;
|
||||
"hello world"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logger_short_lived() {
|
||||
all_log_macros!(logger: Logger, "hello");
|
||||
all_log_macros!(logger: &Logger, "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn logger_expr() {
|
||||
all_log_macros!(logger: {
|
||||
let logger = Logger;
|
||||
logger
|
||||
}, "hello");
|
||||
}
|
||||
|
||||
/// Some and None (from Option) are used in the macros.
|
||||
#[derive(Debug)]
|
||||
enum Type {
|
||||
Some,
|
||||
None,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regression_issue_494() {
|
||||
use self::Type::*;
|
||||
all_log_macros!("some message: {:?}, {:?}", None, Some);
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
[assign]
|
||||
Reference in new issue
Block a user