Created
April 22, 2012 04:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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