class ParallelCucumber::CustomLogger

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/parallel_cucumber/logger.rb, line 5
def initialize(*)
  super
  @mark = 0
  # Don't want to log half-lines.
  @incomplete_line = nil
end

Public Instance Methods

synch() { |self| ... } click to toggle source
# File lib/parallel_cucumber/logger.rb, line 12
def synch
  mutex.synchronize { yield self }
end
update_into(other_logger) click to toggle source
# File lib/parallel_cucumber/logger.rb, line 16
def update_into(other_logger)
  # TODO: This should write the #teamcity block wrapper: update(other_logger, 'qa-w12> precheck') etc.
  @logdev.dev.fsync # Helpful, but inadequate: a child process might still have buffered stuff.
  other_logger.synch do |l|
    l << File.open(@logdev.filename || @logdev.dev.path) do |f|
      begin
        f.seek(@mark)
        lines = f.readlines
        if @incomplete_line && lines.count > 0
          lines[0] = @incomplete_line + lines[0]
          @incomplete_line = nil
        end
        unless lines.last && lines.last.end_with?("\n", "\r")
          @incomplete_line = lines.pop
        end
        lines.join
      ensure
        @mark = f.tell
      end
    end
  end
end

Private Instance Methods

format_message(severity, datetime, progname, msg) click to toggle source
# File lib/parallel_cucumber/logger.rb, line 45
def format_message(severity, datetime, progname, msg)
  if @level == DEBUG
    "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}]\t#{progname}\t#{severity}\t#{msg.gsub(/\s+/, ' ').strip}\n"
  else
    "#{progname}\t#{msg.gsub(/\s+/, ' ').strip}\n"
  end
end
mutex() click to toggle source
# File lib/parallel_cucumber/logger.rb, line 41
def mutex
  @mutex ||= Mutex.new
end