Sha256: 385b3bb4413c71f7679313c5ea727f89fa85376d85a3e7667870467950906f85

Contents?: true

Size: 663 Bytes

Versions: 2

Compression:

Stored size: 663 Bytes

Contents

require "logger"

module Adapter::RsLogger

  class LogFormatter < ::Logger::Formatter

    def call(severity, time, progname, msg)
      "#{format_datetime(time)}[TID:#{$$}] [Rs232::#{severity}]: #{msg}\n"
    end


    private

    def format_datetime(time)
      if @datetime_format.nil?
        time.strftime("%Y-%m-%d %H:%M:%S.") << "%06d " % time.usec
      else
        time.strftime(@datetime_format)
      end
    end

  end

  def logger
    @logger ||= begin
      logger = ::Logger.new( ENV["LOG"]||$stdout )
      logger.level = ENV["DEBUG"].to_i
      logger.formatter= LogFormatter.new
      logger
    end
  end
  
  module_function :logger

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rs_232-2.0.5 features/support/adapter/rs_logger.rb
rs_232-2.0.4 features/support/adapter/rs_logger.rb