Sha256: 2d2a5151cd97871a8dc9900115651f98ae8a1d40577a12ca2c59a938bb3dd57d

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require 'ostruct'
require 'ns-options'
require 'logging'

module Logsly

  class NullOutput < OpenStruct
    def to_appender(*args); nil; end
    def to_layout(*args);   nil; end
  end

  class BaseOutput

    attr_reader :build

    def initialize(&build)
      @build = build || Proc.new {}
    end

    def to_appender(*args)
      self.instance_exec(*args, &@build)
      self.colors_obj.run_build(*args)
      self
    end

    def to_layout(data)
      Logging.layouts.pattern(data.to_pattern_opts)
    end

    def to_appender(*args)
      raise NotImplementedError
    end

  end

  class BaseOutputData
    include NsOptions::Proxy
    option :pattern, String, :default => '%m\n'
    option :colors,  String

    def initialize(*args, &build)
      @args = args
      self.instance_exec(*@args, &build)
    end

    def to_pattern_opts
      Hash.new.tap do |opts|
        opts[:pattern] = self.pattern if self.pattern

        if scheme_name = colors_obj.to_scheme(*@args)
          opts[:color_scheme] = scheme_name
        end
      end
    end

    protected

    def colors_obj
      Logsly.colors(self.colors)
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
logsly-1.1.0 lib/logsly/base_output.rb
logsly-1.0.2 lib/logsly/base_output.rb
logsly-1.0.1 lib/logsly/base_output.rb
logsly-1.0.0 lib/logsly/base_output.rb
logsly-1.0.0.rc1 lib/logsly/base_output.rb