Embed URL


SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Custom logger file in Rails

View custom_logger.rb
1 2 3 4 5 6 7 8 9 10
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
logfile ="#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = # constant accessible anywhere
View custom_logger.rb
1 2
# in development.rb
require "custom_logger"
View custom_logger.rb
1 2 3 4
# in controller files"info from custom logger")
CUSTOM_LOGGER.debug("debug from custom logger")
CUSTOM_LOGGER.error("error from custom logger")

thanks helped me a lot.

Very useful!

Thanks <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.