class Lorekeeper::FastLogger::LogDevice

Very fast class to write to a log file.

Public Class Methods

new(file) click to toggle source
# File lib/lorekeeper/fast_logger.rb, line 91
def initialize(file)
  @iodevice = to_iodevice(file)
  @iomutex = LogDeviceMutex.new
end

Public Instance Methods

write(message) click to toggle source
# File lib/lorekeeper/fast_logger.rb, line 96
def write(message)
  return unless @iodevice

  @iomutex.synchronize do
    @iodevice.write(message)
  end
end

Private Instance Methods

create_logfile(filename) click to toggle source
# File lib/lorekeeper/fast_logger.rb, line 125
def create_logfile(filename)
  File.open(filename, (File::WRONLY | File::APPEND | File::CREAT))
rescue Errno::EEXIST
  open_logfile(filename)
end
open_logfile(filename) click to toggle source
# File lib/lorekeeper/fast_logger.rb, line 119
def open_logfile(filename)
  File.open(filename, (File::WRONLY | File::APPEND))
rescue Errno::ENOENT
  create_logfile(filename)
end
to_iodevice(file) click to toggle source
# File lib/lorekeeper/fast_logger.rb, line 106
def to_iodevice(file)
  return nil unless file

  iodevice = if file.respond_to?(:write) && file.respond_to?(:close)
    file
  else
    open_logfile(file)
  end

  iodevice.sync = true if iodevice.respond_to?(:sync=)
  iodevice
end