Skip to content

Instantly share code, notes, and snippets.

@rtomayko
Created November 9, 2009 10:10
Show Gist options
  • Select an option

  • Save rtomayko/229851 to your computer and use it in GitHub Desktop.

Select an option

Save rtomayko/229851 to your computer and use it in GitHub Desktop.
Automatic log config based on existence of log file
# Configure logging based on the existence of the log file. If the
# log file doesn't exist, logging is disable entirely and no log
# file will be created. If the log file does exist, logging is
# enabled and turned up to 11.
#
# Example is from config/environments/test.rb in a Rails app but it
# could easily be adapted to other environments/frameworks.
# Disabling logging in test environments can speed things up a bit.
# In your environment:
# unlink log/test.log - disable logging
# touch log/test.log - enable logging
if File.exist?("#{RAILS_ROOT}/log/test.log")
config.log_level = :debug
else
config.log_level = :error
config.logger = Logger.new(File.open("/dev/null", 'wb'))
end
# BONUS POINTS: make it so that this works in a hot app. e.g.,
# logging is automatically enabled/disabled based on the presence
# of the log file -- and -- newly created files are reopened while
# app is running. You'll need to check whether the file is present
# and has the same inode at semi-frequent intervals somehow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment