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

Feature request: support logging meta data #16

Open
mpvosseller opened this issue Jun 7, 2020 · 1 comment
Open

Feature request: support logging meta data #16

mpvosseller opened this issue Jun 7, 2020 · 1 comment

Comments

@mpvosseller
Copy link
Contributor

I'd like to log additional information such as ctx.state.user.id. Is this currently possible?

In express-winston I could do this by passing a dynamicMeta option which takes a function and returns the extra meta data to be logged dynamically (at log time). That could work here too I think.

Another option here might be to treat the koa context much like req and res. So add options like ctxKeys, ctxSelect, and ctxUnselect to allow the user to choose which context properties are logged.

Would you accept a PR for one of these approaches?

@mnebuerquo
Copy link

I also would like to see this happen. My preference would be for a dynamicMeta function option. It is more powerful than an array of keys, and the array of keys is too convenient for me. We should all be careful with what we log from a koa context, and writing a function to do it makes it more deliberate.

The dynamicMeta function should get the context as its argument and should be called at the very end of the chain, just before the log message is written, in case properties get added to the context by other middleware.

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

2 participants