"is ruby's stdlib logger class thread-safe?" Code Answer

5

a quick look at logger.rb reveals code such as the following:

def write(message)
  @mutex.synchronize do
    if @shift_age and @dev.respond_to?(:stat)
      begin
        check_shift_log
      rescue
        raise logger::shiftingerror.new("shifting failed. #{$!}")
      end
    end
    @dev.write(message)
  end
end

so while i can't vouch for whether it gets thread-safety correct, i can confirm that it is making a concerted effort to do it right!

p.s. it's often easy to answer questions like this for yourself by reading the code :-)

By IronDuck on May 23 2022

Answers related to “is ruby's stdlib logger class thread-safe?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.