Module: Backburner::Logger

Included in:
Worker
Defined in:
lib/backburner/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Loads in instance and class levels



6
7
8
# File 'lib/backburner/logger.rb', line 6

def self.included(base)
  base.extend self
end

Instance Method Details

#job_started_atObject

Returns true if the job logging started



26
27
28
# File 'lib/backburner/logger.rb', line 26

def job_started_at
  Thread.current[:job_started_at]
end

#log_error(msg) ⇒ Object

Print an error to stderr

Examples:

log_error("Task failed!")


44
45
46
# File 'lib/backburner/logger.rb', line 44

def log_error(msg)
  logger ? logger.error(msg) : $stderr.puts(msg)
end

#log_info(msg) ⇒ Object

Print a message to stdout

Examples:

log_info("Working on task")


35
36
37
# File 'lib/backburner/logger.rb', line 35

def log_info(msg)
  logger ? logger.info(msg) : puts(msg)
end

#log_job_begin(name, args) ⇒ Object

Print out when a job is about to begin



11
12
13
14
# File 'lib/backburner/logger.rb', line 11

def log_job_begin(name, args)
  log_info "Work job #{name} with #{args.inspect}"
  Thread.current[:job_started_at] = Time.now
end

#log_job_end(name, message = nil) ⇒ Object

Print out when a job completed If message is nil, job is considered complete



18
19
20
21
22
23
# File 'lib/backburner/logger.rb', line 18

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

#loggerObject

Return logger if specified



49
50
51
# File 'lib/backburner/logger.rb', line 49

def logger
  Backburner.configuration.logger
end