Skip to content

Commit 838920c

Browse files
authored
Merge pull request #575 from EFanZh/group-target-module-path-and-file
Group `target_module`, `path` and `file` arguments
2 parents cab1088 + 3985711 commit 838920c

3 files changed

Lines changed: 65 additions & 64 deletions

File tree

src/__private_api.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//! WARNING: this is not part of the crate's public API and is subject to change at any time
2+
3+
use crate::{Level, Metadata, Record};
4+
use std::fmt::Arguments;
5+
pub use std::option::Option;
6+
pub use std::{file, format_args, line, module_path, stringify};
7+
8+
#[cfg(not(feature = "kv_unstable"))]
9+
pub fn log(
10+
args: Arguments,
11+
level: Level,
12+
&(target, module_path, file): &(&str, &'static str, &'static str),
13+
line: u32,
14+
kvs: Option<&[(&str, &str)]>,
15+
) {
16+
if kvs.is_some() {
17+
panic!(
18+
"key-value support is experimental and must be enabled using the `kv_unstable` feature"
19+
)
20+
}
21+
22+
crate::logger().log(
23+
&Record::builder()
24+
.args(args)
25+
.level(level)
26+
.target(target)
27+
.module_path_static(Some(module_path))
28+
.file_static(Some(file))
29+
.line(Some(line))
30+
.build(),
31+
);
32+
}
33+
34+
#[cfg(feature = "kv_unstable")]
35+
pub fn log(
36+
args: Arguments,
37+
level: Level,
38+
&(target, module_path, file): &(&str, &'static str, &'static str),
39+
line: u32,
40+
kvs: Option<&[(&str, &dyn crate::kv::ToValue)]>,
41+
) {
42+
crate::logger().log(
43+
&Record::builder()
44+
.args(args)
45+
.level(level)
46+
.target(target)
47+
.module_path_static(Some(module_path))
48+
.file_static(Some(file))
49+
.line(Some(line))
50+
.key_values(&kvs)
51+
.build(),
52+
);
53+
}
54+
55+
pub fn enabled(level: Level, target: &str) -> bool {
56+
crate::logger().enabled(&Metadata::builder().level(level).target(target).build())
57+
}

src/lib.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,65 +1466,7 @@ pub fn logger() -> &'static dyn Log {
14661466

14671467
// WARNING: this is not part of the crate's public API and is subject to change at any time
14681468
#[doc(hidden)]
1469-
#[cfg(not(feature = "kv_unstable"))]
1470-
pub fn __private_api_log(
1471-
args: fmt::Arguments,
1472-
level: Level,
1473-
&(target, module_path, file, line): &(&str, &'static str, &'static str, u32),
1474-
kvs: Option<&[(&str, &str)]>,
1475-
) {
1476-
if kvs.is_some() {
1477-
panic!(
1478-
"key-value support is experimental and must be enabled using the `kv_unstable` feature"
1479-
)
1480-
}
1481-
1482-
logger().log(
1483-
&Record::builder()
1484-
.args(args)
1485-
.level(level)
1486-
.target(target)
1487-
.module_path_static(Some(module_path))
1488-
.file_static(Some(file))
1489-
.line(Some(line))
1490-
.build(),
1491-
);
1492-
}
1493-
1494-
// WARNING: this is not part of the crate's public API and is subject to change at any time
1495-
#[doc(hidden)]
1496-
#[cfg(feature = "kv_unstable")]
1497-
pub fn __private_api_log(
1498-
args: fmt::Arguments,
1499-
level: Level,
1500-
&(target, module_path, file, line): &(&str, &'static str, &'static str, u32),
1501-
kvs: Option<&[(&str, &dyn kv::ToValue)]>,
1502-
) {
1503-
logger().log(
1504-
&Record::builder()
1505-
.args(args)
1506-
.level(level)
1507-
.target(target)
1508-
.module_path_static(Some(module_path))
1509-
.file_static(Some(file))
1510-
.line(Some(line))
1511-
.key_values(&kvs)
1512-
.build(),
1513-
);
1514-
}
1515-
1516-
// WARNING: this is not part of the crate's public API and is subject to change at any time
1517-
#[doc(hidden)]
1518-
pub fn __private_api_enabled(level: Level, target: &str) -> bool {
1519-
logger().enabled(&Metadata::builder().level(level).target(target).build())
1520-
}
1521-
1522-
// WARNING: this is not part of the crate's public API and is subject to change at any time
1523-
#[doc(hidden)]
1524-
pub mod __private_api {
1525-
pub use std::option::Option;
1526-
pub use std::{file, format_args, line, module_path, stringify};
1527-
}
1469+
pub mod __private_api;
15281470

15291471
/// The statically resolved maximum log level.
15301472
///

src/macros.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ macro_rules! log {
3333
(target: $target:expr, $lvl:expr, $($key:tt = $value:expr),+; $($arg:tt)+) => ({
3434
let lvl = $lvl;
3535
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
36-
$crate::__private_api_log(
36+
$crate::__private_api::log(
3737
$crate::__private_api::format_args!($($arg)+),
3838
lvl,
39-
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!(), $crate::__private_api::line!()),
39+
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!()),
40+
$crate::__private_api::line!(),
4041
$crate::__private_api::Option::Some(&[$(($crate::__log_key!($key), &$value)),+])
4142
);
4243
}
@@ -46,10 +47,11 @@ macro_rules! log {
4647
(target: $target:expr, $lvl:expr, $($arg:tt)+) => ({
4748
let lvl = $lvl;
4849
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
49-
$crate::__private_api_log(
50+
$crate::__private_api::log(
5051
$crate::__private_api::format_args!($($arg)+),
5152
lvl,
52-
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!(), $crate::__private_api::line!()),
53+
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!()),
54+
$crate::__private_api::line!(),
5355
$crate::__private_api::Option::None,
5456
);
5557
}
@@ -217,7 +219,7 @@ macro_rules! log_enabled {
217219
let lvl = $lvl;
218220
lvl <= $crate::STATIC_MAX_LEVEL
219221
&& lvl <= $crate::max_level()
220-
&& $crate::__private_api_enabled(lvl, $target)
222+
&& $crate::__private_api::enabled(lvl, $target)
221223
}};
222224
($lvl:expr) => {
223225
$crate::log_enabled!(target: $crate::__private_api::module_path!(), $lvl)

0 commit comments

Comments
 (0)