Sha256: 06374600c131bd69c034f74e5cbf071c76fee951ab5a9cbdea1b9357eaab7e12

Contents?: true

Size: 632 Bytes

Versions: 6

Compression:

Stored size: 632 Bytes

Contents

require 'logger'

module Guignol
  module Logger
    def logger
      @logger ||= ::Logger.new(logger_file).tap do |logger|
        logger.progname = 'guignol'
        logger.formatter = Formatter.new
      end
    end


    private

    class Formatter < ::Logger::Formatter
      Format = "[%s] %s: %s\n"

      def call(severity, time, progname, msg)
        Format % [time.strftime('%F %T'), severity, msg2str(msg)]
      end
    end


    def logger_file
      return File.open(ENV['GUIGNOL_LOG'] ,'a') if ENV['GUIGNOL_LOG']
      $stdout.tty? ? $stdout : File.open('/dev/null','w')
    end

    Guignol.extend(self)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
guignol-0.3.16 lib/guignol/logger.rb
guignol-0.3.15 lib/guignol/logger.rb
guignol-0.3.14 lib/guignol/logger.rb
guignol-0.3.13 lib/guignol/logger.rb
guignol-0.3.12 lib/guignol/logger.rb
guignol-0.3.10 lib/guignol/logger.rb