Class: YARD::Logger
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Severity
|
|
Inherits: | Object |
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(⣷ ⣯ ⣟ ⡿ ⢿ ⣻ ⣽ ⣾)
Severity
- Included
Constructor Methods
- .create_log_method(name) Internal use only Internal use only
-
.instance(pipe = STDOUT) ⇒ Logger
The logger instance.
-
.new(pipe, *args) ⇒ Logger
constructor
Internal use only
Internal use only
Creates a new logger.
Logging Methods
-
#debug(message) ⇒ void
Changes the debug level to DEBUG if $DEBUG is set and writes a debugging message.
-
#error(message) ⇒ void
Logs a message with the error severity level.
-
#fatal(message) ⇒ void
Logs a message with the fatal severity level.
-
#info(message) ⇒ void
Logs a message with the info severity level.
-
#log(severity, message)
Logs a message with a given severity.
-
#unknown(message) ⇒ void
Logs a message with the unknown severity level.
-
#warn(message) ⇒ void
Remembers when a warning occurs and writes a warning message.
Level Control Methods
-
#enter_level(new_level = level) { ... }
Sets the logger level for the duration of the block.
Utility Printing Methods
-
#<<(msg = '')
Alias for #print.
-
#backtrace(exc, level_meth = :error) ⇒ void
Prints the backtrace
exc
to the logger as error data. -
#clear_progress ⇒ void
Clears the progress indicator in the TTY display.
-
#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.
Benchmarking Methods
-
#capture(msg, nontty_log = :debug) { ... } ⇒ void
Captures the duration of a block of code for benchmark analysis.
Instance Attribute Summary
Instance Method Summary
-
#warn_no_continuations ⇒ void
deprecated
Internal use only
Internal use only
Deprecated.
Continuations are no longer needed by
::YARD
0.8.0+. - #clear_line private
Class Method Details
.create_log_method(name)
.instance(pipe = STDOUT) ⇒ Logger
The logger instance
# File 'lib/yard/logging.rb', line 76
def self.instance(pipe = STDOUT) @logger ||= new(pipe) end
Instance Attribute Details
#io ⇒ IO
(rw)
# File 'lib/yard/logging.rb', line 49
attr_accessor :io
#level ⇒ DEBUG
, ... (rw)
# File 'lib/yard/logging.rb', line 57
attr_accessor :level
#show_backtraces ⇒ Boolean
(rw)
#show_backtraces=(value) (rw)
[ GitHub ]# File 'lib/yard/logging.rb', line 54
attr_writer :show_backtraces
#show_progress ⇒ Boolean
(rw)
#show_progress=(value) (rw)
[ GitHub ]# File 'lib/yard/logging.rb', line 70
attr_writer :show_progress
#warned ⇒ Boolean
(rw)
# File 'lib/yard/logging.rb', line 60
attr_accessor :warned
Instance Method Details
#<<(msg = '')
Alias for #print.
# File 'lib/yard/logging.rb', line 209
alias << print
#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 216
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 234
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 255
def clear_line return unless @progress_msg io.write("\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 186
def clear_progress return unless show_progress io.write("\e[?25h\e[2K") @progress_msg = nil end
#debug(message) ⇒ void
This method returns an undefined value.
Changes the debug level to DEBUG if $DEBUG is set and writes a debugging message. Logs a message with the debug severity level.
# File 'lib/yard/logging.rb', line 114
create_log_method :debug
#enter_level(new_level = level) { ... }
Sets the logger level for the duration of the block
#error(message) ⇒ void
This method returns an undefined value.
Logs a message with the error severity level.
# File 'lib/yard/logging.rb', line 109
create_log_method :error
#fatal(message) ⇒ void
This method returns an undefined value.
Logs a message with the fatal severity level.
# File 'lib/yard/logging.rb', line 110
create_log_method :fatal
#info(message) ⇒ void
This method returns an undefined value.
Logs a message with the info severity level.
# File 'lib/yard/logging.rb', line 108
create_log_method :info
#log(severity, message)
Logs a message with a given severity
# File 'lib/yard/logging.rb', line 122
def log(severity, ) self.level = DEBUG if $DEBUG return unless severity >= level self.warned = true if severity == WARN clear_line puts "[#{SEVERITIES[severity].to_s.downcase}]: #{}" 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 205
def print(msg = '') clear_line io.write(msg) end
#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 161
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 197
def puts(msg = '') print("#{msg}\n") end
#unknown(message) ⇒ void
This method returns an undefined value.
Logs a message with the unknown severity level.
# File 'lib/yard/logging.rb', line 111
create_log_method :unknown
#warn(message) ⇒ void
This method returns an undefined value.
Remembers when a warning occurs and writes a warning message. Logs a message with the warn severity level.
# File 'lib/yard/logging.rb', line 117
create_log_method :warn
#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 250
def warn_no_continuations end