Sha256: 734c9acb52b7690a0d77a6e3ef838316043d80bf8ac382510eb8ebfe94274b94

Contents?: true

Size: 784 Bytes

Versions: 5

Compression:

Stored size: 784 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

    %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, "[" + ANSI.cyan { "#{worker.class.name}:#{worker.object_id}" } + "] #{message}" )
        else
          logger.send( level, message )
        end
      end

    end

  protected

    attr_reader :logger

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rabbit-wq-1.4.0 lib/rabbit_wq/work_logger.rb
rabbit-wq-1.3.0 lib/rabbit_wq/work_logger.rb
rabbit-wq-1.2.1 lib/rabbit_wq/work_logger.rb
rabbit-wq-1.2.0 lib/rabbit_wq/work_logger.rb
rabbit-wq-1.1.0 lib/rabbit_wq/work_logger.rb