Project

General

Profile

Bug #12948

Logger does not rotate even if there is a past file to rotate.

Added by tsukasa.oishi (Tsukasa Oishi) about 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
[ruby-dev:49881]

Description

Logger shift_age is "daily".
"log" file's timestamp is yesterday or earlier.

Logger does not rotate the file.
Ruby version is 2.1 or older, Logger rotates the file.

require 'time'
require 'logger'

File.open("log", "w") {}
File.utime(*[Time.mktime(2016, 1, 1)]*2, "log")
logger = Logger.new("log", "daily")
logger.info "test"
logger.close
p Dir.glob("log*")

Ruby2.2 or newer

["log"]

Ruby2.1 or older

["log.20161115", "log"]

(Today is 2016-11-16)

補足

workerのような、必要に応じて都度起動するrubyスクリプト内で、Loggerをshift_age "monthly" で使用しています。
Rubyのバージョンを2.2系にあげたタイミングでログがローテーションされなくなってしまいました。
Loggerオブジェクトを生成した時刻が、ローテートタイミングを決める基準になっているのが原因です。
頻繁に起動してはすぐに死ぬプロセスだと、プロセスが生きている間にたまたまタイミングがこない限りローテーションされません。


Files

past_log_rotate.patch (8.56 KB) past_log_rotate.patch tsukasa.oishi (Tsukasa Oishi), 11/16/2016 05:52 AM

Associated revisions

Revision f6e77b9d
Added by nobu (Nobuyoshi Nakada) about 3 years ago

logger.rb: fix next rotate time

  • lib/logger.rb (Logger::LogDevice#initialize): calculate next rotate time based on the mtime of the last existing file. [ruby-dev:49881] [Bug #12948]

Author: Tsukasa Oishi tsukasa.oishi@gmail.com

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 56815
Added by nobu (Nobuyoshi Nakada) about 3 years ago

logger.rb: fix next rotate time

  • lib/logger.rb (Logger::LogDevice#initialize): calculate next rotate time based on the mtime of the last existing file. [ruby-dev:49881] [Bug #12948]

Author: Tsukasa Oishi tsukasa.oishi@gmail.com

Revision 56815
Added by nobu (Nobuyoshi Nakada) about 3 years ago

logger.rb: fix next rotate time

  • lib/logger.rb (Logger::LogDevice#initialize): calculate next rotate time based on the mtime of the last existing file. [ruby-dev:49881] [Bug #12948]

Author: Tsukasa Oishi tsukasa.oishi@gmail.com

Revision 56815
Added by nobu (Nobuyoshi Nakada) about 3 years ago

logger.rb: fix next rotate time

  • lib/logger.rb (Logger::LogDevice#initialize): calculate next rotate time based on the mtime of the last existing file. [ruby-dev:49881] [Bug #12948]

Author: Tsukasa Oishi tsukasa.oishi@gmail.com

Revision 56815
Added by nobu (Nobuyoshi Nakada) about 3 years ago

logger.rb: fix next rotate time

  • lib/logger.rb (Logger::LogDevice#initialize): calculate next rotate time based on the mtime of the last existing file. [ruby-dev:49881] [Bug #12948]

Author: Tsukasa Oishi tsukasa.oishi@gmail.com

History

Updated by tsukasa.oishi (Tsukasa Oishi) about 3 years ago

  • ruby -v changed from ruby 2.3.1p112 to ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]

Updated by tsukasa.oishi (Tsukasa Oishi) about 3 years ago

  • Description updated (diff)
#3

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Status changed from Open to Closed

Applied in changeset r56815.


logger.rb: fix next rotate time

  • lib/logger.rb (Logger::LogDevice#initialize): calculate next rotate time based on the mtime of the last existing file. [ruby-dev:49881] [Bug #12948]

Author: Tsukasa Oishi tsukasa.oishi@gmail.com

Also available in: Atom PDF