class YARD::Logger

Uses the stdlib Logger class in Ruby for all the backend logic.
Handles console logging for info, warnings and errors.

def self.create_log_method(name)

Other tags:
    Private: -

Returns:
  • (void) -

Other tags:
    See: #log -

Parameters:
  • message (String) -- the message to log
def self.create_log_method(name)
  severity = Severity.const_get(name.to_s.upcase)
  define_method(name) { |message| log(severity, message) }
end

def self.instance(pipe = STDOUT)

Returns:
  • (Logger) - the logger instance
def self.instance(pipe = STDOUT)
  @logger ||= new(pipe)
end

def backtrace(exc, level_meth = :error)

Returns:
  • (void) -

Parameters:
  • level_meth (Symbol) -- the level to log backtrace at
  • exc (Array) -- the backtrace list
def backtrace(exc, level_meth = :error)
  return unless show_backtraces
  send(level_meth, "#{exc.class.class_name}: #{exc.message}")
  send(level_meth, "Stack trace:" +
    exc.backtrace[0..5].map {|x| "\n\t#{x}" }.join + "\n")
end

def capture(msg, nontty_log = :debug)

Returns:
  • (void) -

Other tags:
    Yield: - a block of arbitrary code to benchmark

Parameters:
  • nontty_log (Symbol, nil) -- the level to log as if the output
  • msg (String) -- the message to display

Other tags:
    Todo: - Implement capture storage for reporting of benchmarks
def capture(msg, nontty_log = :debug)
  progress(msg, nontty_log)
  yield
ensure
  clear_progress
end

def clear_line

def clear_line
  return unless @progress_msg
  io.write("\e[2K\r")
end

def clear_progress

Other tags:
    Since: - 0.8.2

Returns:
  • (void) -
def clear_progress
  return unless show_progress
  io.write("\e[?25h\e[2K")
  @progress_msg = nil
end

def enter_level(new_level = level)

Other tags:
    Yield: - the block with the logger temporarily set to +new_level+

Parameters:
  • new_level (Fixnum) -- the logger level for the duration of the block.
def enter_level(new_level = level)
  old_level = level
  self.level = new_level
  yield
ensure
  self.level = old_level
end

def initialize(pipe, *args)

Other tags:
    Private: -
def initialize(pipe, *args)
  self.io = pipe
  self.show_backtraces = true
  self.show_progress = false
  self.level = WARN
  self.warned = false
  @progress_indicator = 0
  @mutex = Mutex.new
  @progress_msg = nil
  @progress_last_update = Time.now
end

def log(severity, message)

Parameters:
  • message (String) -- the message to log
  • severity (DEBUG, INFO, WARN, ERROR, FATAL, UNKNOWN) -- the severity level
def log(severity, message)
  self.level = DEBUG if $DEBUG
  return unless severity >= level
  self.warned = true if severity == WARN
  clear_line
  puts "[#{SEVERITIES[severity].to_s.downcase}]: #{message}"
end

def print(msg = '')

Other tags:
    Since: - 0.8.2

Returns:
  • (void) -

Parameters:
  • msg (String) -- the message to display
def print(msg = '')
  clear_line
  io.write(msg)
end

def progress(msg, nontty_log = :debug)

Other tags:
    Since: - 0.8.2

Returns:
  • (void) -

Parameters:
  • nontty_log (Symbol, nil) -- the level to log as if the output
  • msg (String) -- the message to log
def progress(msg, nontty_log = :debug)
  send(nontty_log, msg) if nontty_log
  return unless show_progress
  icon = ""
  if defined?(::Encoding)
    icon = PROGRESS_INDICATORS[@progress_indicator] + " "
  end
  @mutex.synchronize do
    print("\e[2K\e[?25l\e[1m#{icon}#{msg}\e[0m\r")
    @progress_msg = msg
    if Time.now - @progress_last_update > 0.2
      @progress_indicator += 1
      @progress_indicator %= PROGRESS_INDICATORS.size
      @progress_last_update = Time.now
    end
  end
  Thread.new do
    sleep(0.05)
    progress(msg + ".", nil) if @progress_msg == msg
  end
end

def puts(msg = '')

Other tags:
    Since: - 0.8.2

Returns:
  • (void) -

Parameters:
  • msg (String) -- the message to display
def puts(msg = '')
  print("#{msg}\n")
end

def show_backtraces; @show_backtraces || level == DEBUG end

Returns:
  • (Boolean) - whether backtraces should be shown (by default
def show_backtraces; @show_backtraces || level == DEBUG end

def show_progress

Returns:
  • (Boolean) - whether progress indicators should be shown when
def show_progress
  return false if YARD.ruby18? # threading is too ineffective for progress support
  return false unless io.tty? # no TTY support on IO
  return false unless level > INFO # no progress in verbose/debug modes
  @show_progress
end

def warn_no_continuations

Other tags:
    Private: -

Returns:
  • (void) -

Deprecated:
  • Continuations are no longer needed by YARD 0.8.0+.
def warn_no_continuations
end