Adds custom logging functionality to controllers and models in a Rails application.
Add the gem to your gemfile
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
The logging functionality is added to
ActionController::Base. So each class that inherits from either of them is able
to use the logging functionality.