remote_syslog_logger icon indicating copy to clipboard operation
remote_syslog_logger copied to clipboard

Initializer is using wrong Logger base class

Open uberllama opened this issue 5 years ago • 4 comments
trafficstars

I found that Rails.logger.silence blocks fail when using this gem. The issues seems to be that RemoteSyslogLogger.new instantiates aLogger, when it should be instantiating an ActiveSupport::Logger. Reference: https://stackoverflow.com/a/38361137

uberllama avatar Dec 04 '19 18:12 uberllama

Here's a hacky workaround I've been using:

in config/production.rb

RemoteSyslogLogger::Logger = ActiveSupport::Logger

It works because Logger being used within the RemoteSyslogLogger module here: https://github.com/papertrail/remote_syslog_logger/blob/506bba071f09082106aacd6d3cc3e17423d99dac/lib/remote_syslog_logger.rb#L9

RemoteSyslogLogger::Logger is typically undefined and the name resolves to ::Logger, but my hack defines it.

mikegee avatar Jan 06 '20 02:01 mikegee

Here's a hacky workaround I've been using:

in config/production.rb

RemoteSyslogLogger::Logger = ActiveSupport::Logger

It works because Logger being used within the RemoteSyslogLogger module here:

https://github.com/papertrail/remote_syslog_logger/blob/506bba071f09082106aacd6d3cc3e17423d99dac/lib/remote_syslog_logger.rb#L9

RemoteSyslogLogger::Logger is typically undefined and the name resolves to ::Logger, but my hack defines it.

Thanks Mike! I'll stash this for later. We ended up being able to switch back to the Rails standard logger sending to STDOUT, and having the container do the remote syslogging. One less third party dependency.

uberllama avatar Jan 06 '20 16:01 uberllama

We ended up being able to switch back to the Rails standard logger sending to STDOUT, and having the container do the remote syslogging.

I'm interested in switching to this. Can you write up some details or link to a guide?

mikegee avatar Jan 07 '20 03:01 mikegee

Hey Mike,

I'll try and get up a technical post at some point, but effectively here is what we did at a high level.

  • Created a custom entrypoint sh file that basically takes the output of the script and sends it to syslog. This can be done using something like the following command

exec 1> >(logger -s -t $(basename $0)) 2>&1

  • Configured rsyslog to forward our logs to papertrail. So, installed rsyslog, ensured the webapp user could configure a forward.conf file (environment specific logging destinations), and initialized/started rsyslog as part of the entrypoint script above.

Hope that helps. Feel free to ask more if required.

CtrlDot avatar Jan 07 '20 16:01 CtrlDot