[前][次][番号順一覧][スレッド一覧]

ruby-changes:32124

From: nobu <ko1@a...>
Date: Sat, 14 Dec 2013 14:43:11 +0900 (JST)
Subject: [ruby-changes:32124] nobu:r44203 (trunk): logger.rb: fix extra log ratation

nobu	2013-12-14 14:43:01 +0900 (Sat, 14 Dec 2013)

  New Revision: 44203

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44203

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/lib/logger.rb
    trunk/test/logger/test_logger.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44202)
+++ ChangeLog	(revision 44203)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 14 14:42:53 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* proc.c (mnew_from_me): method by respond_to_missing? should be
Index: lib/logger.rb
===================================================================
--- lib/logger.rb	(revision 44202)
+++ lib/logger.rb	(revision 44203)
@@ -644,8 +644,7 @@ private https://github.com/ruby/ruby/blob/trunk/lib/logger.rb#L644
         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)
Index: test/logger/test_logger.rb
===================================================================
--- test/logger/test_logger.rb	(revision 44202)
+++ test/logger/test_logger.rb	(revision 44203)
@@ -2,6 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/test/logger/test_logger.rb#L2
 require 'test/unit'
 require 'logger'
 require 'tempfile'
+require 'tmpdir'
 require_relative '../ruby/envutil'
 
 
@@ -542,6 +543,44 @@ class TestLogDevice < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/logger/test_logger.rb#L543
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]