LogMe

Adds custom logging functionality to controllers and models in a Rails application.

Installation

Add the gem to your gemfile

gem 'log_me'

Example usage

class Post < ActiveRecord::Base
  log_me  # turn on the logging functionality for this class

  def an_instance_method
    # ... do something ...
    log "This is a logging message with severity info"
    log "This is a logging message with severity error", :error
  end

  def self.a_class_method
    # since logging is done on class level
    # this isn't a problem
    log "This is a logging message in a class method, as warning", :warning
  end
end

The standard behaviour cares about the naming of the logfile. In the example above the logfile can be found under YourApplication/log/post.log

To alter this behaviour just provide an own name, like so:

class Post < ActiveRecord::Base
    log_me "my_own_logfile_name"

    # ...
end

In this style the logfile can be found under YourApplication/log/my_own_logfile_name.log

Additions

The logging functionality is added to ‘ActiveRecord::Base` and `ActionController::Base`. So each class that inherits from either of them is able to use the logging functionality.

Authors and credits

Author

Robert Neumayr

Original idea:: www.tonyamoyal.com/2009/09/24/specific-logging-for-your-rails-models-the-easy-way/