lib/syslogger.rb in syslogger-1.6.2 vs lib/syslogger.rb in syslogger-1.6.3

- old
+ new

@@ -2,11 +2,13 @@ require 'logger' require 'thread' class Syslogger - VERSION = "1.6.2" + VERSION = "1.6.3" + + MUTEX = Mutex.new attr_reader :level, :ident, :options, :facility, :max_octets attr_accessor :formatter MAPPING = { @@ -45,11 +47,10 @@ def initialize(ident = $0, options = Syslog::LOG_PID | Syslog::LOG_CONS, facility = nil) @ident = ident @options = options || (Syslog::LOG_PID | Syslog::LOG_CONS) @facility = facility @level = Logger::INFO - @mutex = Mutex.new @formatter = proc do |severity, datetime, progname, msg| msg end end @@ -88,15 +89,16 @@ def add(severity, message = nil, progname = nil, &block) if message.nil? && block.nil? && !progname.nil? message, progname = progname, nil end progname ||= @ident - - @mutex.synchronize do + mask = Syslog::LOG_UPTO(MAPPING[@level]) + communication = clean(message || block && block.call) + formatted_communication = formatter.call([severity], Time.now, progname, communication) + + MUTEX.synchronize do Syslog.open(progname, @options, @facility) do |s| - s.mask = Syslog::LOG_UPTO(MAPPING[@level]) - communication = clean(message || block && block.call) - formatted_communication = formatter.call([severity], Time.now, progname, communication) + s.mask = mask if self.max_octets buffer = "#{tags_text}" formatted_communication.bytes do |byte| buffer.concat(byte) # if the last byte we added is potentially part of an escape, we'll go ahead and add another byte