1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Clean up log rotation code

This commit is contained in:
Mike Perham 2014-02-07 14:54:49 -08:00
parent df85a0f729
commit ea153afb87
2 changed files with 12 additions and 19 deletions

View file

@ -1,12 +1,8 @@
2.17.5
HEAD
-----------
- A `USR2` signal will now reopen _all_ logs, using IO#reopen. Thus, instead of creating a new Logger object,
Sidekiq will now just update the existing Logger's file descriptor [#1163].
Like Unicorn, a File object is considered a log file if:
- opened with the `O_APPEND` and `O_WRONLY` flags
- the current open file handle does not match its original open path
- unbuffered (as far as userspace buffering goes, not `O_SYNC`)
2.17.4
-----------

View file

@ -51,9 +51,18 @@ module Sidekiq
# Returns the number of files reopened
def self.reopen_logs
to_reopen = []
nr = 0
ObjectSpace.each_object(File) { |fp| is_log?(fp) and to_reopen << fp }
append_flags = File::WRONLY | File::APPEND
ObjectSpace.each_object(File) do |fp|
begin
if !fp.closed? && fp.stat.file? && fp.sync && (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
to_reopen << fp
end
rescue IOError, Errno::EBADF
end
end
nr = 0
to_reopen.each do |fp|
orig_st = begin
fp.stat
@ -70,7 +79,6 @@ module Sidekiq
begin
File.open(fp.path, 'a') { |tmpfp| fp.reopen(tmpfp) }
fp.sync = true
nr += 1
rescue IOError, Errno::EBADF
# not much we can do...
@ -79,17 +87,6 @@ module Sidekiq
nr
end
def self.is_log?(fp)
append_flags = File::WRONLY | File::APPEND
! fp.closed? &&
fp.stat.file? &&
fp.sync &&
(fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
rescue IOError, Errno::EBADF
false
end
def logger
Sidekiq::Logging.logger
end