Class: YARD::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/yard/logging.rb

Overview

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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Logger) initialize(*args)

Creates a new logger



17
18
19
20
21
22
# File 'lib/yard/logging.rb', line 17

def initialize(*args)
  super
  self.show_backtraces = true
  self.level = WARN
  self.formatter = method(:format_log)
end

Instance Attribute Details

- (Object) show_backtraces



8
# File 'lib/yard/logging.rb', line 8

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

Class Method Details

+ (Logger) instance(pipe = STDERR)

The logger instance

Returns:

  • (Logger)

    the logger instance



12
13
14
# File 'lib/yard/logging.rb', line 12

def self.instance(pipe = STDERR)
  @logger ||= new(pipe)
end

Instance Method Details

- (void) backtrace(exc)

This method returns an undefined value.

Prints the backtrace exc to the logger as error data.

Parameters:



35
36
37
38
39
40
# File 'lib/yard/logging.rb', line 35

def backtrace(exc)
  return unless show_backtraces
  error "#{exc.class.class_name}: #{exc.message}"
  error "Stack trace:" +
    exc.backtrace[0..5].map {|x| "\n\t#{x}" }.join + "\n"
end

- (Object) debug(*args)

Changes the debug level to DEBUG if $DEBUG is set and writes a debugging message.



26
27
28
29
# File 'lib/yard/logging.rb', line 26

def debug(*args)
  self.level = DEBUG if $DEBUG
  super
end

- (Object) enter_level(new_level = level) { ... }

Sets the logger level for the duration of the block

Examples:

log.enter_level(Logger::ERROR) do
  YARD.parse_string "def x; end"
end

Parameters:

  • new_level (Fixnum) (defaults to: level)

    the logger level for the duration of the block. values can be found in Ruby's Logger class.

Yields:

  • the block with the logger temporarily set to new_level



64
65
66
67
68
# File 'lib/yard/logging.rb', line 64

def enter_level(new_level = level, &block)
  old_level, self.level = level, new_level
  yield
  self.level = old_level
end

- (void) warn_no_continuations

This method returns an undefined value.

Warns that the Ruby environment does not support continuations. Applies to JRuby, Rubinius and MacRuby. This warning will only display once per Ruby process.



47
48
49
50
51
52
53
# File 'lib/yard/logging.rb', line 47

def warn_no_continuations
  return if CONTINUATIONS_SUPPORTED
  return if $NO_CONTINUATION_WARNING
  $NO_CONTINUATION_WARNING = true
  warn "JRuby/MacRuby/Rubinius do not implement Kernel#callcc and cannot " +
       "load files in order. You must specify the correct order manually."
end