Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Last active November 7, 2019 01:24
Show Gist options
  • Save mgreenly/234e800630e8e3a414a43d302a08c9d5 to your computer and use it in GitHub Desktop.
Save mgreenly/234e800630e8e3a414a43d302a08c9d5 to your computer and use it in GitHub Desktop.
require 'logger'
# This logger will notice the log has been rotated and reopen it.
# The logrotate options must include 'nocreate'.
class RotatableLogger < Logger
def add(*args)
reopen if @logdev.filename && !File.exist?(@logdev.filename)
super
end
end
logger = RotatableLogger.new('sample.log')
loop do
logger.info Time.now
sleep 0.5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment