Proposal: inject tags to logger instance
davydovanton opened this issue · comments
Anton Davydov commented
Why?
We have long logger file with 10k lines. And we want to check what happened for specific request/job execution/etc.
How?
We can create simple method #inject
(we can change name) and use it in any places:
Hanami.logger.inject({ ... }) # => new instance of logger
new_logger = Hanami.logger.inject(uuid: uuid)
Hanami.logger.info 'hello' # => 'hello'
new_logger.info 'hello' # => 'uuid="....." hello'
For example, we can inject uuid into logger and use it in in rack:
class LoggerMiddleware
def call(env)
env['logger'] = Hanami.logger.inject(uuid: Secure.uuid)
[...]
end
end
@hanami/core WDYT?
Luca Guidi commented
I like the idea.
Alfonso Uceda commented
I like too, what do you think something more explicit?
Hanami.logger.tagged(uuid: uuid)
Anton Davydov commented
@AlfonsoUceda yep, good idea 👍
Anton Davydov commented
I'll start work on it 👍
@AlfonsoUceda I think it'll be better to use with_context
method, like: Hanami.logger.with_context(uuid: uuid)
. WDYT?
Alfonso Uceda commented
Luca Guidi commented
Not actionable right now.