Sha256: c45b56adf7e160c3b9b9ac96c0509051fd6072487a17ea6e46698ec3b1cc54c8

Contents?: true

Size: 731 Bytes

Versions: 15

Compression:

Stored size: 731 Bytes

Contents

module MotherBrain
  module Logging
    class BasicFormat < Logger::Formatter
      def call(severity, datetime, progname, msg)
        message = msg.to_s

        if match = message.match(/NODE\[.+?\]/)
          format_matched_lines match, message
        else
          "[#{datetime.utc.iso8601}] PID[#{Process.pid}] TID[#{Thread.current.object_id.to_s(36)}] #{severity}: #{message}\n"
        end
      end

      private

      def format_matched_lines(match, message)
        lines = message.lines.to_a

        lines.map! do |line|
          if line.start_with? match.to_s
            line
          else
            "#{match} #{line}"
          end
        end

        lines.join("\n") << "\n"
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
motherbrain-1.5.0 lib/mb/logging/basic_format.rb
motherbrain-1.4.0 lib/mb/logging/basic_format.rb
motherbrain-1.3.0 lib/mb/logging/basic_format.rb
motherbrain-1.2.1 lib/mb/logging/basic_format.rb
motherbrain-1.2.0 lib/mb/logging/basic_format.rb
motherbrain-1.1.3 lib/mb/logging/basic_format.rb
motherbrain-1.1.2 lib/mb/logging/basic_format.rb
motherbrain-1.1.1 lib/mb/logging/basic_format.rb
motherbrain-1.1.0 lib/mb/logging/basic_format.rb
motherbrain-1.0.0 lib/mb/logging/basic_format.rb
motherbrain-0.14.5 lib/mb/logging/basic_format.rb
motherbrain-0.14.4 lib/mb/logging/basic_format.rb
motherbrain-0.14.3 lib/mb/logging/basic_format.rb
motherbrain-0.14.2 lib/mb/logging/basic_format.rb
motherbrain-0.13.1 lib/mb/logging/basic_format.rb