Sha256: d14f8e924d7a8cc4d2a88b127721f4effc0e102d8457cdfacf44e916d0005941

Contents?: true

Size: 1.22 KB

Versions: 47

Compression:

Stored size: 1.22 KB

Contents

require 'logger'

module Backburner
  module Logger
    # Loads in instance and class levels
    def self.included(base)
      base.extend self
    end

    # Print out when a job is about to begin
    def log_job_begin(name, args)
      log_info "Work job #{name} with #{args.inspect}"
      Thread.current[:job_started_at] = Time.now
    end

    # Print out when a job completed
    # If message is nil, job is considered complete
    def log_job_end(name, message = nil)
      ellapsed = Time.now - job_started_at
      ms = (ellapsed.to_f * 1000).to_i
      action_word = message ? 'Finished' : 'Completed'
      log_info("#{action_word} #{name} in #{ms}ms #{message}")
    end

    # Returns true if the job logging started
    def job_started_at
      Thread.current[:job_started_at]
    end

    # Print a message to stdout
    #
    # @example
    #   log_info("Working on task")
    #
    def log_info(msg)
      logger ? logger.info(msg) : puts(msg)
    end

    # Print an error to stderr
    #
    # @example
    #   log_error("Task failed!")
    #
    def log_error(msg)
      logger ? logger.error(msg) : $stderr.puts(msg)
    end

    # Return logger if specified
    def logger
      Backburner.configuration.logger
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
backburner-allq-1.0.28 lib/backburner/logger.rb
backburner-allq-1.0.27 lib/backburner/logger.rb
backburner-allq-1.0.26 lib/backburner/logger.rb
backburner-allq-1.0.25 lib/backburner/logger.rb
backburner-allq-1.0.24 lib/backburner/logger.rb
backburner-allq-1.0.23 lib/backburner/logger.rb
backburner-allq-1.0.22 lib/backburner/logger.rb
backburner-allq-1.0.21 lib/backburner/logger.rb
backburner-allq-1.0.20 lib/backburner/logger.rb
backburner-allq-1.0.19 lib/backburner/logger.rb
backburner-allq-1.0.18 lib/backburner/logger.rb
backburner-allq-1.0.17 lib/backburner/logger.rb
backburner-allq-1.0.16 lib/backburner/logger.rb
backburner-allq-1.0.14 lib/backburner/logger.rb
backburner-allq-1.0.13 lib/backburner/logger.rb
backburner-allq-1.0.12 lib/backburner/logger.rb
backburner-allq-1.0.11 lib/backburner/logger.rb
backburner-allq-1.0.9 lib/backburner/logger.rb
backburner-allq-1.0.8 lib/backburner/logger.rb
backburner-allq-1.0.7 lib/backburner/logger.rb