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

pkg/logger/logkey: new package for log key glossary #986

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

jmank88
Copy link
Collaborator

@jmank88 jmank88 commented Jan 8, 2025

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

@pavel-raykov
Copy link
Contributor

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

@jmank88
Copy link
Collaborator Author

jmank88 commented Jan 9, 2025

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

@pavel-raykov
Copy link
Contributor

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

I see, so are you planning to extract all the possible keys in some kind of automatic way? Or would you just keep adding them here continuously?

@jmank88
Copy link
Collaborator Author

jmank88 commented Jan 9, 2025

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

I see, so are you planning to extract all the possible keys in some kind of automatic way? Or would you just keep adding them here continuously?

We could try to start with some automation, but adding keys manually would be sufficient for most common inconsistencies.

I did consider providing zap field support as well, but I'm not sure how that should work. Even just ChainID is an interesting example. We probably would want to encourage (or even enforce) string based chain IDs, but we don't want to force callers to make a string to pass in, since that is inefficient in cases where the log message does not need to be serialized. We'd rather also accept fmt.Stringer. So zapfield.ChainID("string") isn't flexible enough, we'd want a fmt.Stringer version, and probably int64 too. It wasn't obvious to me how to sort that out in a clean way, so I left it out of scope for now.

@pavel-raykov
Copy link
Contributor

This PR introduces a new package logkey to serve as a glossary of logger keys in order to align common fields.

What is the intended use of the keys from logkey? Is this for labelling with ZAP's zap.String(key, value) construction, or is it for arbitrary string / int constants that can be used for logging in a centralized way?

We don't typically use the zap field API like that, but that would be valid. More often we just call the w variants: Logger.<level>w("<message>", logkey.ChainID, chainID)

I see, so are you planning to extract all the possible keys in some kind of automatic way? Or would you just keep adding them here continuously?

We could try to start with some automation, but adding keys manually would be sufficient for most common inconsistencies.

I did consider providing zap field support as well, but I'm not sure how that should work. Even just ChainID is an interesting example. We probably would want to encourage (or even enforce) string based chain IDs, but we don't want to force callers to make a string to pass in, since that is inefficient in cases where the log message does not need to be serialized. We'd rather also accept fmt.Stringer. So zapfield.ChainID("string") isn't flexible enough, we'd want a fmt.Stringer version, and probably int64 too. It wasn't obvious to me how to sort that out in a clean way, so I left it out of scope for now.

Sound good. Thanks for explaining!

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

Successfully merging this pull request may close these issues.

2 participants