lib/semantic_logger/formatters/default.rb in semantic_logger-4.2.0 vs lib/semantic_logger/formatters/default.rb in semantic_logger-4.2.1

- old
+ new

@@ -22,15 +22,16 @@ "[#{log.tags.join('] [')}]" if log.tags && !log.tags.empty? end # Named Tags def named_tags - if (named_tags = log.named_tags) && !named_tags.empty? - list = [] - named_tags.each_pair { |name, value| list << "#{name}: #{value}" } - "{#{list.join(', ')}}" - end + named_tags = log.named_tags + return if named_tags.nil? || named_tags.empty? + + list = [] + named_tags.each_pair { |name, value| list << "#{name}: #{value}" } + "{#{list.join(', ')}}" end # Duration def duration "(#{log.duration_human})" if log.duration @@ -46,13 +47,14 @@ "-- #{log.message}" if log.message end # Payload def payload - if pl = log.payload_to_s - "-- #{pl}" - end + pl = log.payload_to_s + return unless pl + + "-- #{pl}" end # Exception def exception "-- Exception: #{log.exception.class}: #{log.exception.message}\n#{log.backtrace_to_s}" if log.exception @@ -65,10 +67,8 @@ self.log = log self.logger = logger [time, level, process_info, tags, named_tags, duration, name, message, payload, exception].compact.join(' ') end - end end end -