Sha256: a40d69e402ce0853bb0b55c312ee3a5ca8d07a6dcca5980cf783b45c1a5c2611

Contents?: true

Size: 741 Bytes

Versions: 14

Compression:

Stored size: 741 Bytes

Contents

module BmcDaemonLib
  class LoggerFormatter

    def self.call severity, datetime, progname, payload
      # Build common values
      timestamp = datetime.strftime(LOG_HEADER_TIME)

      # Build header
      header = sprintf LOG_HEADER_FORMAT,
        timestamp,
        Process.pid,
        severity,
        progname

      # If we have a bunch of lines, prefix them and send them together
      return payload.map do |line|
        "#{header}#{trimmed(line)}\n"
      end.join if payload.is_a?(Array)

      # Otherwise, just prefix the only line
      return "#{header}#{trimmed(payload)}\n"
    end

  protected

    def self.trimmed line
      line.to_s.rstrip[0..LOG_MESSAGE_TRIM].force_encoding(Encoding::UTF_8)
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bmc-daemon-lib-0.3.18 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.16 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.14 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.12 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.10 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.8 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.6 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.4 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.3 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.2 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.1 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.3.0 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.2.0 lib/bmc-daemon-lib/logger_formatter.rb
bmc-daemon-lib-0.1.2 lib/bmc-daemon-lib/logger_formatter.rb