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