Conversion from log::kv::Value to Option<Vec<String>> #535

Open
opened 2022-11-22 08:44:38 -06:00 by lcmgh · 2 comments
lcmgh commented 2022-11-22 08:44:38 -06:00 (Migrated from github.com)

Hello!

I am implementing a custom logger that prints a JSON serialized struct. The struct has a field custom_list: Option<Vec<String>> that should be derived from log::kv::Value. However I could not figure out how to convert to Vec<String> from Value? Is that a missing feature or am I overseeing something here?

MyStruct {
   custom_list: Option<Vec<String>>
}

From end users perspective:
info!(custom_list = as_serde!(vec!["a".to_string(), "b".to_string()]); "Test log msg");

Thanks

Hello! I am implementing a custom logger that prints a JSON serialized struct. The struct has a field `custom_list: Option<Vec<String>>` that should be derived from `log::kv::Value`. However I could not figure out how to convert to `Vec<String>` from `Value`? Is that a missing feature or am I overseeing something here? ```rust MyStruct { custom_list: Option<Vec<String>> } ``` From end users perspective: `info!(custom_list = as_serde!(vec!["a".to_string(), "b".to_string()]); "Test log msg");` Thanks
KodrAus commented 2024-01-31 00:56:28 -06:00 (Migrated from github.com)

This is quite a useful thing to be able to do, and is currently a feature gap in log. The underlying library that supports log::kv::Value did just recently get some support for pulling sequences from values: https://docs.rs/value-bag/latest/value_bag/struct.ValueBag.html#method.to_str_seq.

We could try come up with an API that makes sense for log::kv::Value too.

This is quite a useful thing to be able to do, and is currently a feature gap in `log`. The underlying library that supports `log::kv::Value` did just recently get some support for pulling sequences from values: https://docs.rs/value-bag/latest/value_bag/struct.ValueBag.html#method.to_str_seq. We could try come up with an API that makes sense for `log::kv::Value` too.
AlexTMjugador commented 2024-10-29 08:58:32 -05:00 (Migrated from github.com)

For what it's worth, issue #641 inquires about a more generic way to solve this and other similar conversion needs.

For what it's worth, issue #641 inquires about a more generic way to solve this and other similar conversion needs.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log#535
No description provided.