Skip to content

Commit

Permalink
Extract Logger::LogDevice#handle_write_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Oct 9, 2024
1 parent d1d704a commit f904ad2
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions lib/logger/log_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,13 @@ def initialize(log = nil, shift_age: nil, shift_size: nil, shift_period_suffix:
end

def write(message)
begin
handle_write_errors("writing") do
synchronize do
if @shift_age and @dev.respond_to?(:stat)
begin
check_shift_log
rescue *@reraise_write_errors
raise
rescue
warn("log shifting failed. #{$!}")
end
end
begin
@dev.write(message)
rescue *@reraise_write_errors
raise
rescue
warn("log writing failed. #{$!}")
handle_write_errors("shifting") {check_shift_log}
end
handle_write_errors("writing") {@dev.write(message)}
end
rescue *@reraise_write_errors
raise
rescue Exception => ignored
warn("log writing failed. #{ignored}")
end
end

Expand Down Expand Up @@ -121,6 +105,13 @@ def create_logfile(filename)
logdev.sync = true
end
logdev

def handle_write_errors(mesg)
yield
rescue *@reraise_write_errors
raise
rescue
warn("log #{mesg} failed. #{$!}")
end

def add_log_header(file)
Expand Down

0 comments on commit f904ad2

Please sign in to comment.