Sha256: c3a98b4edd50474213863a87ea4c15f65f096eb10b8afc0d592f0afd5d971e3e

Contents?: true

Size: 575 Bytes

Versions: 2

Compression:

Stored size: 575 Bytes

Contents

require 'active_support/json'
require 'syslog'

class StructuredEventLogger::Syslogger

  class MessageExceedsMaximumSize < StructuredEventLogger::Error; end

  attr_accessor :log_level, :max_size

  def initialize(log_level = Syslog::LOG_INFO, max_size = 64 * 1024 - 1)
    @log_level, @max_size = log_level, max_size
  end

  def call(scope, event, hash, record)
    message = ActiveSupport::JSON.encode(record)
    raise MessageExceedsMaximumSize, "Event too big to be submitted to syslog" if message.bytesize > max_size
    Syslog.log(log_level, '%s', message)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
structured-event-logger-0.1.5 lib/structured_event_logger/syslogger.rb
structured-event-logger-0.1.4 lib/structured_event_logger/syslogger.rb