Create a gist now

Instantly share code, notes, and snippets.

Embed
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"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
# in development.rb
require "custom_logger"
# in controller files
CUSTOM_LOGGER.info("info from custom logger")
CUSTOM_LOGGER.debug("debug from custom logger")
CUSTOM_LOGGER.error("error from custom logger")
@buoyant

This comment has been minimized.

Show comment
Hide comment
@buoyant

buoyant Dec 31, 2012

thanks helped me a lot.

buoyant commented Dec 31, 2012

thanks helped me a lot.

@johnsogg

This comment has been minimized.

Show comment
Hide comment
@johnsogg

johnsogg Oct 27, 2014

Very useful!

Very useful!

@KarineValenca

This comment has been minimized.

Show comment
Hide comment
@KarineValenca

KarineValenca May 17, 2015

Thanks <3

Thanks <3

@McGeekiest

This comment has been minimized.

Show comment
Hide comment
@McGeekiest

McGeekiest Jul 5, 2015

Brilliant. Thank you.

Brilliant. Thank you.

@vishwas-webonise

This comment has been minimized.

Show comment
Hide comment
@vishwas-webonise

vishwas-webonise Aug 9, 2015

Sweet & Simple, Very helpful, thank u :)

Sweet & Simple, Very helpful, thank u :)

@loray513

This comment has been minimized.

Show comment
Hide comment
@loray513

loray513 Aug 13, 2015

Thanks

Thanks

@lnaia

This comment has been minimized.

Show comment
Hide comment
@lnaia

lnaia Oct 5, 2015

cheers!

lnaia commented Oct 5, 2015

cheers!

@tommydunn

This comment has been minimized.

Show comment
Hide comment
@tommydunn

tommydunn Nov 19, 2015

awesome. thanks!

awesome. thanks!

@glasses618

This comment has been minimized.

Show comment
Hide comment
@glasses618

glasses618 May 4, 2016

Thanks a lot! It's helpful!

Thanks a lot! It's helpful!

@chabgood

This comment has been minimized.

Show comment
Hide comment
@chabgood

chabgood Oct 19, 2016

👍

👍

@RanjitReddy

This comment has been minimized.

Show comment
Hide comment
@RanjitReddy

RanjitReddy Nov 16, 2016

Awesome .... Thnx a lot !!!

Awesome .... Thnx a lot !!!

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