Skip to content

Commit

Permalink
Use std::panic::Location to get log location information
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Woolcock committed Nov 27, 2023
1 parent a78c025 commit d3f2eee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/__private_api.rs
Expand Up @@ -34,6 +34,14 @@ impl<'a> KVs<'a> for () {
}
}

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

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

0 comments on commit d3f2eee

Please sign in to comment.