gelf-rb icon indicating copy to clipboard operation
gelf-rb copied to clipboard

Ruby logger device

Open joeyfironsrc opened this issue 8 years ago • 2 comments

When using this gem I was surprised for example that formatter does nothing. Wouldn't it be better if I could do something like this: gelf_logger = GELF::Logger.new(graylog_host, graylog_port, 'LAN', defaults) logger = ::Logger.new(gelf_logger)

Was there any reason not to do it this way?

joeyfironsrc avatar Sep 27 '16 08:09 joeyfironsrc

+1 on that. I'm going through the same issue. That's bad because you can't compose gelf logger other formatters such as ActiveSupport::TaggedLogging::Formatter.

I'll try to monkey patch here and see how it goes.

csokol avatar Dec 30 '16 15:12 csokol

I was able to integrate with the following patch:

  class GELF::Logger
    alias_method :original_add, :add
    def add(level, message = nil, progname = nil)
      if message.nil?
        if block_given?
          message = yield
        else
          message = progname
          progname = default_options['facility']
        end
      end

      original_add(level, formatter.call(level, nil, progname, message), progname)
    end
  end

That's obviously ugly, but it works. I'll open a PR with an slightly better solution.

csokol avatar Dec 30 '16 15:12 csokol