Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::panic::Location to get log location information #599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/__private_api.rs
Expand Up @@ -3,7 +3,7 @@
use self::sealed::KVs;
use crate::{Level, Metadata, Record};
use std::fmt::Arguments;
pub use std::{file, format_args, line, module_path, stringify};
pub use std::{format_args, module_path, stringify};

#[cfg(feature = "kv_unstable")]
pub type Value<'a> = dyn crate::kv::value::ToValue + 'a;
Expand Down Expand Up @@ -34,6 +34,16 @@ impl<'a> KVs<'a> for () {
}
}

#[track_caller]
pub fn file<'a>() -> &'a str {
::std::panic::Location::caller().file()
}

#[track_caller]
pub fn line() -> u32 {
::std::panic::Location::caller().line()
}

// Log implementation.

fn log_impl(
Expand Down
8 changes: 4 additions & 4 deletions src/macros.rs
Expand Up @@ -36,8 +36,8 @@ 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::file()),
$crate::__private_api::line(),
&[$(($crate::__log_key!($key), &$value)),+]
);
}
Expand All @@ -50,8 +50,8 @@ 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::file()),
$crate::__private_api::line(),
(),
);
}
Expand Down