Skip to content

Refactor log shifting #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/logger/log_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def lock_shift_log
@dev = open_logfile(@filename)
end
end
true
rescue Errno::ENOENT
# @filename file would not exist right after #rename and before #create_logfile
if retry_limit <= 0
Expand All @@ -205,10 +206,7 @@ def shift_log_age
File.rename("#{@filename}.#{i}", "#{@filename}.#{i+1}")
end
end
@dev.close rescue nil
File.rename("#{@filename}", "#{@filename}.0")
@dev = create_logfile(@filename)
return true
shift_log_file("#{@filename}.0")
end

def shift_log_period(period_end)
Expand All @@ -224,8 +222,12 @@ def shift_log_period(period_end)
break unless FileTest.exist?(age_file)
end
end
shift_log_file(age_file)
end

def shift_log_file(shifted)
@dev.close rescue nil
File.rename("#{@filename}", age_file)
File.rename(@filename, shifted)
@dev = create_logfile(@filename)
return true
end
Expand Down
2 changes: 0 additions & 2 deletions test/logger/test_logdevice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,6 @@ class << Time
end
end

env_tz_works = /linux|darwin|freebsd/ =~ RUBY_PLATFORM # borrow from test/ruby/test_time_tz.rb

def test_shifting_weekly_exist_file
Dir.mktmpdir do |tmpdir|
assert_in_out_err([{"TZ"=>"UTC"}, *%W"-I#{@top_dir} -rlogger -C#{tmpdir} -"], "#{<<-"begin;"}\n#{<<-'end;'}")
Expand Down