Class: DopCommon::ThreadContextLogger
- Inherits:
-
Object
- Object
- DopCommon::ThreadContextLogger
- Defined in:
- lib/dop_common/thread_context_logger.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
- #create ⇒ Object
- #current_log_file ⇒ Object
-
#initialize(log_path, contexts, all = true) ⇒ ThreadContextLogger
constructor
A new instance of ThreadContextLogger.
- #log_context=(context) ⇒ Object
Constructor Details
#initialize(log_path, contexts, all = true) ⇒ ThreadContextLogger
Returns a new instance of ThreadContextLogger.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dop_common/thread_context_logger.rb', line 11 def initialize(log_path, contexts, all = true) @log_path = log_path @contexts = contexts @all = all @mutex = Mutex.new @loggers = {} @threads = {} FileUtils.mkdir_p(@log_path) create end |
Instance Method Details
#cleanup ⇒ Object
30 31 32 33 34 |
# File 'lib/dop_common/thread_context_logger.rb', line 30 def cleanup @mutex.synchronize do @contexts.each{|context| remove(context)} end end |
#create ⇒ Object
23 24 25 26 27 28 |
# File 'lib/dop_common/thread_context_logger.rb', line 23 def create @mutex.synchronize do add('all') if @all @contexts.each{|context| add(context)} end end |
#current_log_file ⇒ Object
42 43 44 45 |
# File 'lib/dop_common/thread_context_logger.rb', line 42 def current_log_file context = @threads[Thread.current.object_id.to_s] log_file(context) end |
#log_context=(context) ⇒ Object
36 37 38 39 40 |
# File 'lib/dop_common/thread_context_logger.rb', line 36 def log_context=(context) @mutex.synchronize do @threads[Thread.current.object_id.to_s] = context end end |