lib/ztk/logger.rb in ztk-1.1.0 vs lib/ztk/logger.rb in ztk-1.1.1

- old
+ new

@@ -104,15 +104,16 @@ # entry with. # @yieldreturn [String] The block should return the desired log message. def add(severity, message=nil, progname=nil, shift=0, &block) return if (@level > severity) - msg = (block && block.call) - (msg.nil? || msg.strip.empty?) and return - @hostname ||= %x(hostname -s).chomp.strip - called_by = "#{@hostname}:#{parse_caller(caller[1+shift])}" - message = [message, progname, msg].flatten.compact.join(": ") - message = "%19s.%06d|%05d|%5s|%60s%s\n" % [Time.now.utc.strftime("%Y-%m-%d|%H:%M:%S"), Time.now.utc.usec, Process.pid, SEVERITIES[severity], called_by, message] + message = block.call if message.nil? && block_given? + return if message.nil? + + called_by = parse_caller(caller[1+shift]) + + message = [message, progname].flatten.compact.join(": ") + message = "%19s.%06d|%05d|%5s|%s%s\n" % [Time.now.utc.strftime("%Y-%m-%d|%H:%M:%S"), Time.now.utc.usec, Process.pid, SEVERITIES[severity], called_by, message] @logdev.write(message) @logdev.respond_to?(:flush) and @logdev.flush true