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.



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

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



359
360
361
362
363
# File 'lib/madeleine.rb', line 359

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

#ensure_directory_existsObject



329
330
331
332
333
# File 'lib/madeleine.rb', line 329

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

#internal_store(command) ⇒ Object



352
353
354
355
356
357
# File 'lib/madeleine.rb', line 352

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

#resetObject



335
336
337
338
# File 'lib/madeleine.rb', line 335

def reset
  close
  delete_log_files
end

#store(command) ⇒ Object



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

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