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

Ruby logger device #51

Open
joeyfironsrc opened this issue Sep 27, 2016 · 2 comments
Open

Ruby logger device #51

joeyfironsrc opened this issue Sep 27, 2016 · 2 comments

Comments

@joeyfironsrc
Copy link

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?

@csokol
Copy link

csokol commented Dec 30, 2016

+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
Copy link

csokol commented Dec 30, 2016

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.

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