mirror of
https://gitee.com/openharmony/third_party_rust_log
synced 2024-11-23 15:50:41 +00:00
Turn __static_max_level() into a const
This commit is contained in:
parent
2462ef5197
commit
3a846a6022
@ -43,6 +43,7 @@ travis-ci = { repository = "rust-lang-nursery/log" }
|
||||
appveyor = { repository = "alexcrichton/log" }
|
||||
|
||||
[dependencies]
|
||||
cfg-if = "0.1.2"
|
||||
serde = { version = "1.0", optional = true, default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
|
69
src/lib.rs
69
src/lib.rs
@ -261,6 +261,9 @@
|
||||
#[cfg(not(feature = "use_std"))]
|
||||
extern crate core as std;
|
||||
|
||||
#[macro_use]
|
||||
extern crate cfg_if;
|
||||
|
||||
use std::cmp;
|
||||
#[cfg(feature = "use_std")]
|
||||
use std::error;
|
||||
@ -1273,40 +1276,40 @@ pub fn log(record: &Record) {
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING
|
||||
// This is not considered part of the crate's public API. It is subject to
|
||||
// change at any time.
|
||||
#[inline(always)]
|
||||
#[doc(hidden)]
|
||||
pub fn __static_max_level() -> LevelFilter {
|
||||
if !cfg!(debug_assertions) {
|
||||
// This is a release build. Check `release_max_level_*` first.
|
||||
if cfg!(feature = "release_max_level_off") {
|
||||
return LevelFilter::Off;
|
||||
} else if cfg!(feature = "release_max_level_error") {
|
||||
return LevelFilter::Error;
|
||||
} else if cfg!(feature = "release_max_level_warn") {
|
||||
return LevelFilter::Warn;
|
||||
} else if cfg!(feature = "release_max_level_info") {
|
||||
return LevelFilter::Info;
|
||||
} else if cfg!(feature = "release_max_level_debug") {
|
||||
return LevelFilter::Debug;
|
||||
} else if cfg!(feature = "release_max_level_trace") {
|
||||
return LevelFilter::Trace;
|
||||
}
|
||||
}
|
||||
if cfg!(feature = "max_level_off") {
|
||||
LevelFilter::Off
|
||||
} else if cfg!(feature = "max_level_error") {
|
||||
LevelFilter::Error
|
||||
} else if cfg!(feature = "max_level_warn") {
|
||||
LevelFilter::Warn
|
||||
} else if cfg!(feature = "max_level_info") {
|
||||
LevelFilter::Info
|
||||
} else if cfg!(feature = "max_level_debug") {
|
||||
LevelFilter::Debug
|
||||
/// The statically resolved maximum log level.
|
||||
///
|
||||
/// See the crate level documentation for information on how to configure this.
|
||||
///
|
||||
/// This value is checked by the log macros, but not by the `log` and `enabled`
|
||||
/// functions. Code that manually calls those functions should compare the level
|
||||
/// against this value.
|
||||
pub const STATIC_MAX_LEVEL: LevelFilter = MAX_LEVEL_INNER;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(all(not(debug_assertions), feature = "release_max_level_off"))] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Off;
|
||||
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_error"))] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Error;
|
||||
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_warn"))] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Warn;
|
||||
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_info"))] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Info;
|
||||
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_debug"))] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Debug;
|
||||
} else if #[cfg(all(not(debug_assertions), feature = "release_max_level_trace"))] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Trace;
|
||||
} else if #[cfg(feature = "max_level_off")] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Off;
|
||||
} else if #[cfg(feature = "max_level_error")] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Error;
|
||||
} else if #[cfg(feature = "max_level_warn")] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Warn;
|
||||
} else if #[cfg(feature = "max_level_info")] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Info;
|
||||
} else if #[cfg(feature = "max_level_debug")] {
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Debug;
|
||||
} else {
|
||||
LevelFilter::Trace
|
||||
const MAX_LEVEL_INNER: LevelFilter = LevelFilter::Trace;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
macro_rules! log {
|
||||
(target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
|
||||
let lvl = $lvl;
|
||||
if lvl <= $crate::__static_max_level() && lvl <= $crate::max_level() {
|
||||
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
|
||||
$crate::log(
|
||||
&$crate::RecordBuilder::new()
|
||||
.args(format_args!($($arg)+))
|
||||
@ -250,7 +250,7 @@ macro_rules! trace {
|
||||
macro_rules! log_enabled {
|
||||
(target: $target:expr, $lvl:expr) => ({
|
||||
let lvl = $lvl;
|
||||
lvl <= $crate::__static_max_level() && lvl <= $crate::max_level() &&
|
||||
lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() &&
|
||||
$crate::enabled(
|
||||
&$crate::MetadataBuilder::new()
|
||||
.level(lvl)
|
||||
|
Loading…
Reference in New Issue
Block a user