Class: Madeleine::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/madeleine.rb

Overview

:nodoc:

Direct Known Subclasses

Clock::TimeOptimizingLogger

Instance Method Summary collapse

Constructor Details

#initialize(directory_name, log_factory) ⇒ Logger

Returns a new instance of Logger.



309
310
311
312
313
314
315
# File 'lib/madeleine.rb', line 309

def initialize(directory_name, log_factory)
  @directory_name = directory_name
  @log_factory = log_factory
  @log = nil
  @pending_tick = nil
  ensure_directory_exists
end

Instance Method Details

#closeObject



347
348
349
350
351
# File 'lib/madeleine.rb', line 347

def close
  return if @log.nil?
  @log.close
  @log = nil
end

#ensure_directory_existsObject



317
318
319
320
321
# File 'lib/madeleine.rb', line 317

def ensure_directory_exists
  if ! File.exist?(@directory_name)
    FileUtils.mkpath(@directory_name)
  end
end

#internal_store(command) ⇒ Object



340
341
342
343
344
345
# File 'lib/madeleine.rb', line 340

def internal_store(command)
  if @log.nil?
    open_new_log
  end
  @log.store(command)
end

#resetObject



323
324
325
326
# File 'lib/madeleine.rb', line 323

def reset
  close
  delete_log_files
end

#store(command) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
# File 'lib/madeleine.rb', line 328

def store(command)
  if command.kind_of?(Madeleine::Clock::Tick)
    @pending_tick = command
  else
    if @pending_tick
      internal_store(@pending_tick)
      @pending_tick = nil
    end
    internal_store(command)
  end
end