mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
logger.rb: fix extra log ratation
* lib/logger.rb (lock_shift_log): no need to rotate the log file if it has been rotated by another process. based on the patch by no6v (Nobuhiro IMAI) in [ruby-core:58620]. [Bug #9133] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
742659cb6c
commit
95ed081663
3 changed files with 46 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
Sat Dec 14 14:42:53 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/logger.rb (lock_shift_log): no need to rotate the log file
|
||||
if it has been rotated by another process. based on the patch
|
||||
by no6v (Nobuhiro IMAI) in [ruby-core:58620]. [Bug #9133]
|
||||
|
||||
Sat Dec 14 13:01:45 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* proc.c (mnew_from_me): method by respond_to_missing? should be
|
||||
|
|
|
@ -644,8 +644,7 @@ private
|
|||
begin
|
||||
File.open(@filename, File::WRONLY | File::APPEND) do |lock|
|
||||
lock.flock(File::LOCK_EX) # inter-process locking. will be unlocked at closing file
|
||||
ino = lock.stat.ino
|
||||
if ino == File.stat(@filename).ino
|
||||
if File.identical?(@filename, lock) and File.identical?(lock, @dev)
|
||||
yield # log shifting
|
||||
else
|
||||
# log shifted by another process (i-node before locking and i-node after locking are different)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
require 'test/unit'
|
||||
require 'logger'
|
||||
require 'tempfile'
|
||||
require 'tmpdir'
|
||||
require_relative '../ruby/envutil'
|
||||
|
||||
|
||||
|
@ -542,6 +543,44 @@ class TestLogDevice < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_shifting_size_not_rotate_too_much
|
||||
d(@filename).__send__(:add_log_header, @tempfile)
|
||||
header_size = @tempfile.size
|
||||
message = "*" * 99 + "\n"
|
||||
shift_size = header_size + message.size * 3 - 1
|
||||
opt = {shift_age: 1, shift_size: shift_size}
|
||||
|
||||
Dir.mktmpdir do |tmpdir|
|
||||
begin
|
||||
log = File.join(tmpdir, "log")
|
||||
logdev1 = d(log, opt)
|
||||
logdev2 = d(log, opt)
|
||||
|
||||
assert_file.identical?(log, logdev1.dev)
|
||||
assert_file.identical?(log, logdev2.dev)
|
||||
|
||||
3.times{logdev1.write(message)}
|
||||
assert_file.identical?(log, logdev1.dev)
|
||||
assert_file.identical?(log, logdev2.dev)
|
||||
|
||||
logdev1.write(message)
|
||||
assert_file.identical?(log, logdev1.dev)
|
||||
assert_file.identical?(log + ".0", logdev2.dev)
|
||||
|
||||
logdev2.write(message)
|
||||
assert_file.identical?(log, logdev1.dev)
|
||||
assert_file.identical?(log, logdev2.dev)
|
||||
|
||||
logdev1.write(message)
|
||||
assert_file.identical?(log, logdev1.dev)
|
||||
assert_file.identical?(log, logdev2.dev)
|
||||
ensure
|
||||
logdev1.close if logdev1
|
||||
logdev2.close if logdev2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_children(n, args, src)
|
||||
|
|
Loading…
Reference in a new issue