Module: Faktory::Logging
- Defined in:
- lib/faktory/logging.rb
Defined Under Namespace
Classes: Pretty, WithoutTimestamp
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.initialize_logger(log_target = STDOUT) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/faktory/logging.rb', line 48
def self.initialize_logger(log_target = STDOUT)
oldlogger = defined?(@logger) ? @logger : nil
@logger = Logger.new(log_target)
@logger.level = Logger::INFO
@logger.formatter = log_target.tty? ? Pretty.new : WithoutTimestamp.new
oldlogger.close if oldlogger && !$TESTING @logger
end
|
.job_hash_context(job_hash) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/faktory/logging.rb', line 29
def self.job_hash_context(job_hash)
klass = job_hash.dig('custom', 'wrapped') || job_hash["jobtype"]
"#{klass} JID-#{job_hash['jid']}"
end
|
.logger ⇒ Object
60
61
62
|
# File 'lib/faktory/logging.rb', line 60
def self.logger
defined?(@logger) ? @logger : initialize_logger
end
|
.logger=(log) ⇒ Object
64
65
66
|
# File 'lib/faktory/logging.rb', line 64
def self.logger=(log)
@logger = (log ? log : Logger.new(File::NULL))
end
|
.with_context(msg) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/faktory/logging.rb', line 40
def self.with_context(msg)
Thread.current[:faktory_context] ||= []
Thread.current[:faktory_context] << msg
yield
ensure
Thread.current[:faktory_context].pop
end
|
.with_job_hash_context(job_hash, &block) ⇒ Object
36
37
38
|
# File 'lib/faktory/logging.rb', line 36
def self.with_job_hash_context(job_hash, &block)
with_context(job_hash_context(job_hash), &block)
end
|