mirror of
https://gitee.com/openharmony/third_party_rust_log
synced 2024-11-22 23:29:49 +00:00
Merge pull request #486 from Thomasdezeeuw/issue#484
Support static string as key value
This commit is contained in:
commit
863c4612c2
@ -30,14 +30,14 @@
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! log {
|
||||
// log!(target: "my_target", Level::Info; key1 = 42, key2 = true; "a {} event", "log");
|
||||
(target: $target:expr, $lvl:expr, $($key:ident = $value:expr),+; $($arg:tt)+) => ({
|
||||
(target: $target:expr, $lvl:expr, $($key:tt = $value:expr),+; $($arg:tt)+) => ({
|
||||
let lvl = $lvl;
|
||||
if lvl <= $crate::STATIC_MAX_LEVEL && lvl <= $crate::max_level() {
|
||||
$crate::__private_api_log(
|
||||
__log_format_args!($($arg)+),
|
||||
lvl,
|
||||
&($target, __log_module_path!(), __log_file!(), __log_line!()),
|
||||
Some(&[$((__log_stringify!($key), &$value)),+])
|
||||
Some(&[$((__log_key!($key), &$value)),+])
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -268,8 +268,13 @@ macro_rules! __log_line {
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __log_stringify {
|
||||
($($args:tt)*) => {
|
||||
macro_rules! __log_key {
|
||||
// key1 = 42
|
||||
($($args:ident)*) => {
|
||||
stringify!($($args)*)
|
||||
};
|
||||
// "key1" = 42
|
||||
($($args:expr)*) => {
|
||||
$($args)*
|
||||
};
|
||||
}
|
||||
|
@ -205,3 +205,13 @@ fn kv_implicit_named_args() {
|
||||
all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "kv_unstable")]
|
||||
fn kv_string_keys() {
|
||||
for lvl in log::Level::iter() {
|
||||
log!(target: "my_target", lvl, "also dogs" = "Fílos", "key/that-can't/be/an/ident" = "hi"; "hello {world}", world = "world");
|
||||
}
|
||||
|
||||
all_log_macros!(target: "my_target", "also dogs" = "Fílos", "key/that-can't/be/an/ident" = "hi"; "hello {world}", world = "world");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user