Module: Backburner::Logger
- Included in:
- Worker
- Defined in:
- lib/backburner/logger.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
Loads in instance and class levels.
Instance Method Summary collapse
-
#job_started_at ⇒ Object
Returns true if the job logging started.
-
#log_error(msg) ⇒ Object
Print an error to stderr.
-
#log_info(msg) ⇒ Object
Print a message to stdout.
-
#log_job_begin(name, args) ⇒ Object
Print out when a job is about to begin.
-
#log_job_end(name, message = nil) ⇒ Object
Print out when a job completed If message is nil, job is considered complete.
-
#logger ⇒ Object
Return logger if specified.
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_at ⇒ Object
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
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
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, = nil) ellapsed = Time.now - job_started_at ms = (ellapsed.to_f * 1000).to_i action_word = ? 'Finished' : 'Completed' log_info("#{action_word} #{name} in #{ms}ms #{}") end |
#logger ⇒ Object
Return logger if specified
49 50 51 |
# File 'lib/backburner/logger.rb', line 49 def logger Backburner.configuration.logger end |