mirror of
https://github.com/rust-lang/log.git
synced 2026-04-22 07:47:06 +00:00
use Location::caller() for file and line info
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
use self::sealed::KVs;
|
||||
use crate::{Level, Metadata, Record};
|
||||
use std::fmt::Arguments;
|
||||
pub use std::{file, format_args, line, module_path, stringify};
|
||||
use std::panic::Location;
|
||||
pub use std::{format_args, module_path, stringify};
|
||||
|
||||
#[cfg(not(feature = "kv"))]
|
||||
pub type Value<'a> = &'a str;
|
||||
@@ -36,8 +37,7 @@ impl<'a> KVs<'a> for () {
|
||||
fn log_impl(
|
||||
args: Arguments,
|
||||
level: Level,
|
||||
&(target, module_path, file): &(&str, &'static str, &'static str),
|
||||
line: u32,
|
||||
&(target, module_path, loc): &(&str, &'static str, &'static Location),
|
||||
kvs: Option<&[(&str, Value)]>,
|
||||
) {
|
||||
#[cfg(not(feature = "kv"))]
|
||||
@@ -52,8 +52,8 @@ fn log_impl(
|
||||
.level(level)
|
||||
.target(target)
|
||||
.module_path_static(Some(module_path))
|
||||
.file_static(Some(file))
|
||||
.line(Some(line));
|
||||
.file_static(Some(loc.file()))
|
||||
.line(Some(loc.line()));
|
||||
|
||||
#[cfg(feature = "kv")]
|
||||
builder.key_values(&kvs);
|
||||
@@ -64,25 +64,23 @@ fn log_impl(
|
||||
pub fn log<'a, K>(
|
||||
args: Arguments,
|
||||
level: Level,
|
||||
target_module_path_and_file: &(&str, &'static str, &'static str),
|
||||
line: u32,
|
||||
target_module_path_and_loc: &(&str, &'static str, &'static Location),
|
||||
kvs: K,
|
||||
) where
|
||||
K: KVs<'a>,
|
||||
{
|
||||
log_impl(
|
||||
args,
|
||||
level,
|
||||
target_module_path_and_file,
|
||||
line,
|
||||
kvs.into_kvs(),
|
||||
)
|
||||
log_impl(args, level, target_module_path_and_loc, kvs.into_kvs())
|
||||
}
|
||||
|
||||
pub fn enabled(level: Level, target: &str) -> bool {
|
||||
crate::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;
|
||||
|
||||
@@ -341,10 +341,6 @@
|
||||
#![warn(missing_docs)]
|
||||
#![deny(missing_debug_implementations, unconditional_recursion)]
|
||||
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
|
||||
// When compiled for the rustc compiler itself we want to make sure that this is
|
||||
// an unstable crate
|
||||
#![cfg_attr(rustbuild, feature(staged_api, rustc_private))]
|
||||
#![cfg_attr(rustbuild, unstable(feature = "rustc_private", issue = "27812"))]
|
||||
|
||||
#[cfg(any(
|
||||
all(feature = "max_level_off", feature = "max_level_error"),
|
||||
|
||||
@@ -36,8 +36,7 @@ macro_rules! log {
|
||||
$crate::__private_api::log::<&_>(
|
||||
$crate::__private_api::format_args!($($arg)+),
|
||||
lvl,
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!()),
|
||||
$crate::__private_api::line!(),
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::loc()),
|
||||
&[$(($crate::__log_key!($key), $crate::__log_value!($key $(:$capture)* = $($value)*))),+]
|
||||
);
|
||||
}
|
||||
@@ -50,8 +49,7 @@ macro_rules! log {
|
||||
$crate::__private_api::log(
|
||||
$crate::__private_api::format_args!($($arg)+),
|
||||
lvl,
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::file!()),
|
||||
$crate::__private_api::line!(),
|
||||
&($target, $crate::__private_api::module_path!(), $crate::__private_api::loc()),
|
||||
(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ edition = "2021"
|
||||
publish = false
|
||||
build = "src/build.rs"
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(lib_build)'] }
|
||||
|
||||
[features]
|
||||
std = ["log/std"]
|
||||
kv = ["log/kv"]
|
||||
|
||||
Reference in New Issue
Block a user