Class: YARD::Logger
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Logger
|
|
Instance Chain:
self,
Logger
|
|
Inherits: |
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.
Constant Summary
-
PROGRESS_INDICATORS =
The list of characters displayed beside the progress bar to indicate "movement".
%w(⣷ ⣯ ⣟ ⡿ ⢿ ⣻ ⣽ ⣾)
Class Method Summary
-
.instance(pipe = STDOUT) ⇒ Logger
The logger instance.
-
.new(pipe, *args) ⇒ Logger
constructor
Creates a new logger.
Instance Attribute Summary
Instance Method Summary
-
#<<(msg = '')
Alias for #print.
-
#backtrace(exc, level_meth = :error) ⇒ void
Prints the backtrace
exc
to the logger as error data. -
#capture(msg, nontty_log = :debug) { ... } ⇒ void
Captures the duration of a block of code for benchmark analysis.
-
#clear_progress ⇒ void
Clears the progress indicator in the TTY display.
-
#debug(*args)
Changes the debug level to DEBUG if $DEBUG is set and writes a debugging message.
-
#enter_level(new_level = level) { ... }
Sets the logger level for the duration of the block.
-
#print(msg = '') ⇒ void
(also: #<<)
Displays an unformatted line to the logger output stream.
-
#progress(msg, nontty_log = :debug) ⇒ void
Displays a progress indicator for a given message.
-
#puts(msg = '') ⇒ void
Displays an unformatted line to the logger output stream, adding a newline.
-
#warn(*args)
Remembers when a warning occurs and writes a warning message.
-
#warn_no_continuations ⇒ void
deprecated
Deprecated.
Continuations are no longer needed by
::YARD
0.8.0+. -
#add(*args)
private
Override this internal
Logger
method to clear line. - #clear_line private
-
#format_log(sev, _time, _prog, msg)
private
Log format (from
Logger
implementation). - #print_no_newline private
Constructor Details
.new(pipe, *args) ⇒ Logger
Creates a new logger
# File 'lib/yard/logging.rb', line 43
def initialize(pipe, *args) super(pipe, *args) self.io = pipe self.show_backtraces = true self.show_progress = false self.level = WARN self.formatter = method(:format_log) self.warned = false @progress_indicator = 0 @mutex = Mutex.new @progress_msg = nil @progress_last_update = Time.now end
Class Method Details
.instance(pipe = STDOUT) ⇒ Logger
The logger instance
# File 'lib/yard/logging.rb', line 38
def self.instance(pipe = STDOUT) @logger ||= new(pipe) end
Instance Attribute Details
#io ⇒ IO
(rw)
# File 'lib/yard/logging.rb', line 17
def io; @logdev end
#io=(pipe) (rw)
[ GitHub ]# File 'lib/yard/logging.rb', line 18
def io=(pipe) @logdev = pipe end
#show_backtraces ⇒ Boolean
(rw)
# File 'lib/yard/logging.rb', line 22
def show_backtraces; @show_backtraces || level == DEBUG end
#show_backtraces=(value) (rw)
[ GitHub ]# File 'lib/yard/logging.rb', line 23
attr_writer :show_backtraces
#show_progress ⇒ Boolean
(rw)
# File 'lib/yard/logging.rb', line 27
def show_progress return false if YARD.ruby18? # threading is too ineffective for progress support return false if YARD.windows? # windows has poor ANSI 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
#show_progress=(value) (rw)
[ GitHub ]# File 'lib/yard/logging.rb', line 34
attr_writer :show_progress
#warned (rw)
[ GitHub ]# File 'lib/yard/logging.rb', line 69
attr_accessor :warned
Instance Method Details
#<<(msg = '')
Alias for #print.
# File 'lib/yard/logging.rb', line 147
alias << print
#add(*args) (private)
Override this internal Logger
method to clear line
# File 'lib/yard/logging.rb', line 190
def add(*args) clear_line super(*args) end
#backtrace(exc, level_meth = :error) ⇒ void
This method returns an undefined value.
Prints the backtrace exc
to the logger as error data.
# File 'lib/yard/logging.rb', line 154
def backtrace(exc, level_meth = :error) return unless show_backtraces send(level_meth, "#{exc.class.class_name}: #{exc.}") send(level_meth, "Stack trace:" + exc.backtrace[0..5].map {|x| "\n\t#{x}" }.join + "\n") end
#capture(msg, nontty_log = :debug) { ... } ⇒ void
Implement capture storage for reporting of benchmarks
This method returns an undefined value.
Captures the duration of a block of code for benchmark analysis. Also calls #progress on the message to display it to the user.
# File 'lib/yard/logging.rb', line 80
def capture(msg, nontty_log = :debug) progress(msg, nontty_log) yield ensure clear_progress end
#clear_line (private)
[ GitHub ]# File 'lib/yard/logging.rb', line 195
def clear_line return unless @progress_msg print_no_newline("\e[2K\r") end
#clear_progress ⇒ void
This method returns an undefined value.
Clears the progress indicator in the TTY display.
# File 'lib/yard/logging.rb', line 121
def clear_progress return unless show_progress print_no_newline("\e[?25h\e[2K") @progress_msg = nil end
#debug(*args)
Changes the debug level to DEBUG if $DEBUG is set and writes a debugging message.
# File 'lib/yard/logging.rb', line 59
def debug(*args) self.level = DEBUG if $DEBUG super end
#enter_level(new_level = level) { ... }
Sets the logger level for the duration of the block
# File 'lib/yard/logging.rb', line 179
def enter_level(new_level = level) old_level = level self.level = new_level yield ensure self.level = old_level end
#format_log(sev, _time, _prog, msg) (private)
Log format (from Logger
implementation). Used by Logger
internally
# File 'lib/yard/logging.rb', line 201
def format_log(sev, _time, _prog, msg) "[#{sev.downcase}]: #{msg}\n" end
#print(msg = '') ⇒ void
Also known as: #<<
This method returns an undefined value.
Displays an unformatted line to the logger output stream.
# File 'lib/yard/logging.rb', line 143
def print(msg = '') clear_line print_no_newline(msg) end
#print_no_newline (private)
[ GitHub ]# File 'lib/yard/logging.rb', line 136
alias print_no_newline <<
#progress(msg, nontty_log = :debug) ⇒ void
This method returns an undefined value.
Displays a progress indicator for a given message. This progress report
is only displayed on TTY displays, otherwise the message is passed to
the nontty_log
level.
# File 'lib/yard/logging.rb', line 96
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
#puts(msg = '') ⇒ void
This method returns an undefined value.
Displays an unformatted line to the logger output stream, adding a newline.
# File 'lib/yard/logging.rb', line 132
def puts(msg = '') print("#{msg}\n") end
#warn(*args)
Remembers when a warning occurs and writes a warning message.
# File 'lib/yard/logging.rb', line 65
def warn(*args) self.warned = true super end
#warn_no_continuations ⇒ void
Continuations are no longer needed by ::YARD
0.8.0+.
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.
# File 'lib/yard/logging.rb', line 167
def warn_no_continuations end