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

How to get log level in dynamic metadata? #569

Open
yulius-take2 opened this issue May 20, 2022 · 1 comment
Open

How to get log level in dynamic metadata? #569

yulius-take2 opened this issue May 20, 2022 · 1 comment

Comments

@yulius-take2
Copy link

I would like to add a stack trace to the metadata only if lager:error() is called. I'm trying to use the dynamic metadata but since the function has zero arguments, I can't tell what level the current log is called with.

https://github.com/erlang-lager/lager#setting-dynamic-metadata-at-compile-time

Is there a function I can call to see what the current log level is or is there a better hook to be called in the same process that lager:error() is called in?

@yulius-take2 yulius-take2 changed the title How to get log level in dynamic metadata How to get log level in dynamic metadata? May 20, 2022
@jadeallenx
Copy link
Member

jadeallenx commented May 20, 2022

It is way easier to do something like this from your own custom lager backend. Presumably you are capturing a stack trace from a call site. If so, you can ship it using lager:md/1, then in your backend, you can inspect lager_msg:severity(Message) and if it's higher than error, you can pull the stack trace from the metadata and inject it into the message to be emitted by lager.

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