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

allow log macros to reference a container of kv pairs for logging #11

Open
BruceBrown opened this issue Aug 7, 2021 · 0 comments
Open

Comments

@BruceBrown
Copy link

Feature Request

Summary

I have structs which have fields I'd like to log. So I create a log_context member which holds the kv pairs.
These rarely change, and then only by appending values. The current syntax becomes unwieldy if I use
the field names and values and later refactor the struct and add additional fields I'd like to log.

Motivation

I'm writing server code and would like to efficiently log object information in addition to the normal point in code logging.

Guide-level explanation

Assume a struct has a log_context field consisting of a container of kv pairs and is referenced by something. At some point in the code, you'd like to log some information and include the kv pairs in the log as k=val (tagged data).

info!("some logging state={}", state, something);
or if its easier:
info!("some logging state={}", state, &something);
or if its easier:
info!("some logging state={}", state, Some(something));

or if easier, the log_context field could be an Option<_>

Reference-level explanation

This is another means of specifying kv pairs, and would likely require new macros, e.g., info_kv!(...) or reworking existing macros.

Drawbacks

This could be work that few take advantage of. Although, I suspect once the community starts seeing it in action adoption may occur rapidly.

Rationale and alternatives

The primary alternative is to forgo the macros and build the Record using builder methods, which is at best tedious.

Unresolved Questions

I don't believe this creates unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant