Sha256: 10b702971d365511eaa04396a1fd6968c212b75375e66a8eca342e8dd832ff4f

Contents?: true

Size: 1.31 KB

Versions: 18

Compression:

Stored size: 1.31 KB

Contents

# -*- encoding: utf-8 -*-

require 'webgen/logger'
require 'webgen/cli/utils'

module Webgen

  module CLI

    # The logger class used by the command line interface.
    class Logger < Webgen::Logger

      attr_accessor :prefix

      # Create a new Logger object for the command line interface.
      def initialize(outdev = $stdout)
        super(outdev)
        @prefix = ''
        outdev.sync = true if outdev.respond_to?(:sync=)
        self.formatter = Proc.new do |severity, timestamp, progname, msg|
          msg = msg.dup
          msg.gsub!(/<.*?>/) {|m| Utils.bold(m)}
          msg.gsub!(/\n/, "\n      ")
          case severity
          when 'INFO'
            msg.sub!(/^\s*\[(?:create|update)\]/) {|m| Utils.bold(Utils.green(m))}
            "%s%-5s %s\n" % [@prefix, severity, msg]
          when 'WARN'
            "%s%s%-5s%s %s\n" % [@prefix, Utils.bold + Utils.yellow, severity, Utils.reset, msg]
          when 'ERROR', 'FATAL'
            "%s%s%-5s%s %s\n" % [@prefix, Utils.bold + Utils.red, severity, Utils.reset, msg]
          when 'DEBUG'
            "%s%-5s%s %s\n" % [@prefix, severity, progname ? " (#{progname})" : '', msg]
          else
            raise ArgumentError, 'Unsupported logger severity level'
          end
        end
        self.level = ::Logger::INFO
      end

    end

  end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
webgen-1.7.3 lib/webgen/cli/logger.rb
webgen-1.7.2 lib/webgen/cli/logger.rb
webgen-1.7.1 lib/webgen/cli/logger.rb
webgen-1.7.0 lib/webgen/cli/logger.rb
webgen-1.6.0 lib/webgen/cli/logger.rb
webgen-1.5.2 lib/webgen/cli/logger.rb
webgen-1.5.1 lib/webgen/cli/logger.rb
webgen-1.5.0 lib/webgen/cli/logger.rb
webgen-1.4.1 lib/webgen/cli/logger.rb
webgen-1.4.0 lib/webgen/cli/logger.rb
webgen-1.3.0 lib/webgen/cli/logger.rb
webgen-1.2.1 lib/webgen/cli/logger.rb
webgen-1.2.0 lib/webgen/cli/logger.rb
webgen-1.1.0 lib/webgen/cli/logger.rb
webgen-1.0.0 lib/webgen/cli/logger.rb
webgen-1.0.0.beta3 lib/webgen/cli/logger.rb
webgen-1.0.0.beta2 lib/webgen/cli/logger.rb
webgen-1.0.0.beta1 lib/webgen/cli/logger.rb