Last active
November 7, 2019 01:24
-
-
Save mgreenly/234e800630e8e3a414a43d302a08c9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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