Sha256: ff496e9cac2db5295d072e120743076112a4c443799f97ce392dacb0d77b01da

Contents?: true

Size: 682 Bytes

Versions: 2

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

require 'forwardable'

class Lenjador
  module Adapters
    class StdoutAdapter
      extend Forwardable

      attr_reader :logger

      def_delegators :@logger, :debug?, :info?, :warn?, :error?, :fatal?

      def initialize(level, *)
        @logger = Logger.new(STDOUT)
        @logger.level = level
      end

      def log(level, metadata = {})
        message = metadata[:message]
        data = metadata.reject { |key, _value| key == :message }
        log_data = [
          message,
          data.empty? ? nil : Utils.generate_json(data)
        ].compact.join(' ')

        @logger.public_send level, log_data
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lenjador-1.4.0 lib/lenjador/adapters/stdout_adapter.rb
lenjador-1.3.0 lib/lenjador/adapters/stdout_adapter.rb