Class: CpuInspectCore::LogWriter
- Inherits:
-
Object
- Object
- CpuInspectCore::LogWriter
- Defined in:
- lib/cpu_inspect_core/log_writer.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ LogWriter
constructor
A new instance of LogWriter.
- #write(data) ⇒ Object
Constructor Details
#initialize(config) ⇒ LogWriter
Returns a new instance of LogWriter.
7 8 9 10 11 |
# File 'lib/cpu_inspect_core/log_writer.rb', line 7 def initialize(config) @path = config.log_path @max_bytes = config.log_max_bytes @mutex = Mutex.new end |
Instance Method Details
#write(data) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/cpu_inspect_core/log_writer.rb', line 13 def write(data) line = "#{JSON.generate(data)}\n" @mutex.synchronize do rotate_if_needed File.open(@path, 'a:UTF-8') { |f| f.write(line) } end end |