Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Custom logger file in Rails
# 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
# in development.rb
require "custom_logger"
# in controller files"info from custom logger")
CUSTOM_LOGGER.debug("debug from custom logger")
CUSTOM_LOGGER.error("error from custom logger")

buoyant commented Dec 31, 2012

thanks helped me a lot.

Very useful!

Thanks <3

Brilliant. Thank you.

Sweet & Simple, Very helpful, thank u :)


lnaia commented Oct 5, 2015


awesome. thanks!

Thanks a lot! It's helpful!


Awesome .... Thnx a lot !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment