Skip to content

Instantly share code, notes, and snippets.

@ktkaushik
Created April 22, 2012 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktkaushik/2453949 to your computer and use it in GitHub Desktop.
Save ktkaushik/2453949 to your computer and use it in GitHub Desktop.
Custom Logger in rails 3.2.x. Store logs in different logs based on environment as well, All in one file.
# If you wish to store everything in one logger file then do this.
class CustomLogger
LOGGERFILE = File.join("#{Rails.root}/log/category_clicks_#{Rails.env}_errors.log")
def self.log( message, severity = :info )
@category_click_logger ||= ActiveSupport::BufferedLogger.new( LOGGERFILE )
@model_log.send severity, "[#{Time.now.to_s(:db)}] [#{severity.to_s.capitalize}] #{message}\n"
end
end
#now call this function throughout your rails application like this :
CustomLogger.log( "this message should go in the logger." , :error )
OR
CustomLogger.log "this message should go in the logger." , :error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment