Class: Madeleine::Logger

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(directory_name, log_factory) ⇒ Logger

Returns a new instance of Logger.



319
320
321
322
323
324
325
# File 'lib/madeleine.rb', line 319

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



357
358
359
360
361
# File 'lib/madeleine.rb', line 357

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

#ensure_directory_existsObject



327
328
329
330
331
# File 'lib/madeleine.rb', line 327

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

#internal_store(command) ⇒ Object



350
351
352
353
354
355
# File 'lib/madeleine.rb', line 350

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

#resetObject



333
334
335
336
# File 'lib/madeleine.rb', line 333

def reset
  close
  delete_log_files
end

#store(command) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
# File 'lib/madeleine.rb', line 338

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