Sha256: 75eef26fc6afc7e8a29afd0c0c5fb2e1158ab7abe98b2c1b794146c572caeaaa

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Jekyll
  class Stevenson < ::Logger
    def initialize
      formatter = proc do |_, _, _, msg|
        msg.to_s
      end
      super($stdout, :formatter => formatter)
    end

    def add(severity, message = nil, progname = nil)
      severity ||= UNKNOWN
      @logdev = logdevice(severity)

      if @logdev.nil? || severity < @level
        return true
      end
      progname ||= @progname
      if message.nil?
        if block_given?
          message = yield
        else
          message = progname
          progname = @progname
        end
      end
      @logdev.puts(
        format_message(format_severity(severity), Time.now, progname, message)
      )
      true
    end

    # Log a +WARN+ message
    def warn(progname = nil, &block)
      add(WARN, nil, progname.yellow, &block)
    end

    # Log an +ERROR+ message
    def error(progname = nil, &block)
      add(ERROR, nil, progname.red, &block)
    end

    def close
      # No LogDevice in use
    end

    private

    def logdevice(severity)
      if severity > INFO
        $stderr
      else
        $stdout
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jekyll-3.10.0 lib/jekyll/stevenson.rb
jekyll-3.9.5 lib/jekyll/stevenson.rb
jekyll-3.9.4 lib/jekyll/stevenson.rb