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

#initialize(*args) ⇒ Logger

Creates a new logger



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

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

Instance Attribute Details

#show_backtracesObject

Returns the value of attribute show_backtraces.



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

def show_backtraces
  @show_backtraces
end

Class Method Details

.instance(pipe = STDERR) ⇒ Logger

The logger instance

Returns:

  • (Logger)

    the logger instance



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

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

Instance Method Details

#backtrace(exc) ⇒ void

This method returns an undefined value.

Prints the backtrace exc to the logger as error data.

Parameters:



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

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

#debug(*args) ⇒ Object

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



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

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

#enter_level(new_level = level) { ... } ⇒ Object

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



50
51
52
53
54
# File 'lib/yard/logging.rb', line 50

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