Sha256: 280ebb775f3ff35aceed288c40561818c40f0eb1f49c6a3aec55017ca42679f6

Contents?: true

Size: 925 Bytes

Versions: 2

Compression:

Stored size: 925 Bytes

Contents

require 'ansi'
require 'yell'

module RabbitWQ
  class WorkLogger

    def initialize( log_level, path )
      @logger = Yell.new do |l|
                  l.level = log_level
                  l.adapter :file, path
                end
    end

    def level=( level )
      # conform to API but do not set log level this way
    end

    %w(
      debug
      error
      fatal
      info
      warn
    ).each do |level|

      define_method level do |*args|
        worker, message = nil, nil
        if args.size > 1
          worker, message = *args
        else
          message = args.first
        end

        if worker
          logger.send( level, "[[PID:" + Rainbow( Process.pid.to_s ).magenta + "]" + Rainbow( "#{worker.class.name}:#{worker.object_id}" ).cyan + "] #{message}" )
        else
          logger.send( level, message )
        end
      end

    end

  protected

    attr_reader :logger

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rabbit-wq-2.3.0 lib/rabbit_wq/work_logger.rb
rabbit-wq-2.2.0 lib/rabbit_wq/work_logger.rb