hanami / utils

Ruby core extentions and class utilities for Hanami

Home Page:http://hanamirb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal: inject tags to logger instance

davydovanton opened this issue · comments

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?

I like the idea.

I like too, what do you think something more explicit?

Hanami.logger.tagged(uuid: uuid)

@AlfonsoUceda yep, good idea 👍

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?

Not actionable right now.