@@ -46,8 +46,7 @@ module Severity
4646
4747 # @return [IO] the IO object being logged to
4848 # @since 0.8.2
49- def io ; @logdev end
50- def io = ( pipe ) @logdev = pipe end
49+ attr_accessor :io
5150
5251 # @return [Boolean] whether backtraces should be shown (by default
5352 # this is on).
@@ -70,13 +69,16 @@ def show_progress
7069 end
7170 attr_writer :show_progress
7271
72+ # @!group Constructor Methods
73+
7374 # The logger instance
7475 # @return [Logger] the logger instance
7576 def self . instance ( pipe = STDOUT )
7677 @logger ||= new ( pipe )
7778 end
7879
7980 # Creates a new logger
81+ # @private
8082 def initialize ( pipe , *args )
8183 self . io = pipe
8284 self . show_backtraces = true
@@ -94,12 +96,15 @@ def initialize(pipe, *args)
9496 # Logs a message with the $1 severity level.
9597 # @param message [String] the message to log
9698 # @see #log
99+ # @return [void]
97100 # @private
98101 def self . create_log_method ( name )
99102 severity = Severity . const_get ( name . to_s . upcase )
100103 define_method ( name ) { |message | log ( severity , message ) }
101104 end
102105
106+ # @!group Logging Methods
107+
103108 create_log_method :info
104109 create_log_method :error
105110 create_log_method :fatal
@@ -123,22 +128,27 @@ def log(severity, message)
123128 puts "[#{ SEVERITIES [ severity ] . to_s . downcase } ]: #{ message } "
124129 end
125130
126- # Captures the duration of a block of code for benchmark analysis. Also
127- # calls {#progress} on the message to display it to the user.
131+ # @!group Level Control Methods
132+
133+ # Sets the logger level for the duration of the block
128134 #
129- # @todo Implement capture storage for reporting of benchmarks
130- # @param [String] msg the message to display
131- # @param [Symbol, nil] nontty_log the level to log as if the output
132- # stream is not a TTY. Use +nil+ for no alternate logging.
133- # @yield a block of arbitrary code to benchmark
134- # @return [void]
135- def capture ( msg , nontty_log = :debug )
136- progress ( msg , nontty_log )
135+ # @example
136+ # log.enter_level(Logger::ERROR) do
137+ # YARD.parse_string "def x; end"
138+ # end
139+ # @param [Fixnum] new_level the logger level for the duration of the block.
140+ # values can be found in Ruby's Logger class.
141+ # @yield the block with the logger temporarily set to +new_level+
142+ def enter_level ( new_level = level )
143+ old_level = level
144+ self . level = new_level
137145 yield
138146 ensure
139- clear_progress
147+ self . level = old_level
140148 end
141149
150+ # @!group Utility Printing Methods
151+
142152 # Displays a progress indicator for a given message. This progress report
143153 # is only displayed on TTY displays, otherwise the message is passed to
144154 # the +nontty_log+ level.
@@ -210,32 +220,36 @@ def backtrace(exc, level_meth = :error)
210220 exc . backtrace [ 0 ..5 ] . map { |x | "\n \t #{ x } " } . join + "\n " )
211221 end
212222
223+ # @!group Benchmarking Methods
224+
225+ # Captures the duration of a block of code for benchmark analysis. Also
226+ # calls {#progress} on the message to display it to the user.
227+ #
228+ # @todo Implement capture storage for reporting of benchmarks
229+ # @param [String] msg the message to display
230+ # @param [Symbol, nil] nontty_log the level to log as if the output
231+ # stream is not a TTY. Use +nil+ for no alternate logging.
232+ # @yield a block of arbitrary code to benchmark
233+ # @return [void]
234+ def capture ( msg , nontty_log = :debug )
235+ progress ( msg , nontty_log )
236+ yield
237+ ensure
238+ clear_progress
239+ end
240+
241+ # @!endgroup
242+
213243 # Warns that the Ruby environment does not support continuations. Applies
214244 # to JRuby, Rubinius and MacRuby. This warning will only display once
215245 # per Ruby process.
216246 #
217247 # @deprecated Continuations are no longer needed by YARD 0.8.0+.
218248 # @return [void]
249+ # @private
219250 def warn_no_continuations
220251 end
221252
222- # Sets the logger level for the duration of the block
223- #
224- # @example
225- # log.enter_level(Logger::ERROR) do
226- # YARD.parse_string "def x; end"
227- # end
228- # @param [Fixnum] new_level the logger level for the duration of the block.
229- # values can be found in Ruby's Logger class.
230- # @yield the block with the logger temporarily set to +new_level+
231- def enter_level ( new_level = level )
232- old_level = level
233- self . level = new_level
234- yield
235- ensure
236- self . level = old_level
237- end
238-
239253 private
240254
241255 def clear_line
0 commit comments