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.50 lib/backburner/logger.rb
backburner-allq-1.0.49 lib/backburner/logger.rb
backburner-allq-1.0.48 lib/backburner/logger.rb
backburner-1.6.1 lib/backburner/logger.rb
backburner-allq-1.0.47 lib/backburner/logger.rb
backburner-allq-1.0.46 lib/backburner/logger.rb
backburner-allq-1.0.45 lib/backburner/logger.rb
backburner-allq-1.0.44 lib/backburner/logger.rb
backburner-allq-1.0.40 lib/backburner/logger.rb
backburner-allq-1.0.39 lib/backburner/logger.rb
backburner-allq-1.0.38 lib/backburner/logger.rb
backburner-allq-1.0.37 lib/backburner/logger.rb
backburner-allq-1.0.36 lib/backburner/logger.rb
backburner-1.6.0 lib/backburner/logger.rb
backburner-allq-1.0.35 lib/backburner/logger.rb
backburner-allq-1.0.34 lib/backburner/logger.rb
backburner-allq-1.0.33 lib/backburner/logger.rb
backburner-allq-1.0.32 lib/backburner/logger.rb
backburner-allq-1.0.31 lib/backburner/logger.rb
backburner-allq-1.0.29 lib/backburner/logger.rb