Class: YARD::Logger
- Inherits:
-
Logger
- Object
- Logger
- YARD::Logger
- 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
- - (Object) show_backtraces Returns the value of attribute show_backtraces.
Class Method Summary
- + (Logger) instance(pipe = STDERR) The logger instance.
Instance Method Summary
- - (Object) backtrace(exc)
- - (Object) debug(*args) Changes the debug level to DEBUG if $DEBUG is set and writes a debugging message.
- - (Object) enter_level(new_level = level, &block) { ... } Sets the logger level for the duration of the block.
- - (Object) format_log(sev, time, prog, msg) Log format (from Logger implementation).
- - (Logger) initialize(*args) constructor Creates a new logger.
Constructor Details
- (Logger) initialize(*args)
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
- (Object) show_backtraces
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
+ (Logger) instance(pipe = STDERR)
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
- (Object) backtrace(exc)
30 31 32 33 34 35 |
# File 'lib/yard/logging.rb', line 30 def backtrace(exc) return unless show_backtraces error "#{exc.class.class_name}: #{exc.}" 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.
25 26 27 28 |
# File 'lib/yard/logging.rb', line 25 def debug(*args) self.level = DEBUG if $DEBUG super end |
- (Object) enter_level(new_level = level, &block) { ... }
Sets the logger level for the duration of the block
46 47 48 49 50 |
# File 'lib/yard/logging.rb', line 46 def enter_level(new_level = level, &block) old_level, self.level = level, new_level yield self.level = old_level end |
- (Object) format_log(sev, time, prog, msg)
Log format (from Logger implementation)
53 54 55 |
# File 'lib/yard/logging.rb', line 53 def format_log(sev, time, prog, msg) "[#{sev.downcase}]: #{msg}\n" end |