Skip to content

Instantly share code, notes, and snippets.

@eric1234
Created October 20, 2010 14:56
Show Gist options
  • Save eric1234/636575 to your computer and use it in GitHub Desktop.
Save eric1234/636575 to your computer and use it in GitHub Desktop.
Logger that writes to logworm
class LogwormLogger < ActiveSupport::BufferedLogger
def initialize(level = DEBUG)
super Logworm::Logger, level
end
end
class Logworm::Logger
def self.write(msg)
table = defined?(Rails) ? "#{Rails.env}_logger" : 'logger'
log table, :msg => msg
end
end
config.logger = LogwormLogger.new config.log_level
@eric1234
Copy link
Author

A first stab at using Logworm to log the Rails logger messages. Completely untested at this point. Just an experiment.

  • We subclass ActiveSupport::BufferedLogger as that is what Rails uses. The question is should we use the standard Ruby Logger instead as we probably really don't need buffering (I think LogWorm does that for us).
  • All BufferedLogger needs is something it can call :write on (usually a file). So we monkey-patch the Logworm::Logger class to have that method and internally call the normal method to log a message. We incorporate the Rails environment in the table name to keep messages distinct. Should we include other info automatically such as the controller, action, etc. What about allowing the application to specify custom info (such as the current logged in user). That additional info might make searching easier later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment