@@ -46,8 +46,7 @@ module Severity
46
46
47
47
# @return [IO] the IO object being logged to
48
48
# @since 0.8.2
49
- def io ; @logdev end
50
- def io = ( pipe ) @logdev = pipe end
49
+ attr_accessor :io
51
50
52
51
# @return [Boolean] whether backtraces should be shown (by default
53
52
# this is on).
@@ -70,13 +69,16 @@ def show_progress
70
69
end
71
70
attr_writer :show_progress
72
71
72
+ # @!group Constructor Methods
73
+
73
74
# The logger instance
74
75
# @return [Logger] the logger instance
75
76
def self . instance ( pipe = STDOUT )
76
77
@logger ||= new ( pipe )
77
78
end
78
79
79
80
# Creates a new logger
81
+ # @private
80
82
def initialize ( pipe , *args )
81
83
self . io = pipe
82
84
self . show_backtraces = true
@@ -94,12 +96,15 @@ def initialize(pipe, *args)
94
96
# Logs a message with the $1 severity level.
95
97
# @param message [String] the message to log
96
98
# @see #log
99
+ # @return [void]
97
100
# @private
98
101
def self . create_log_method ( name )
99
102
severity = Severity . const_get ( name . to_s . upcase )
100
103
define_method ( name ) { |message | log ( severity , message ) }
101
104
end
102
105
106
+ # @!group Logging Methods
107
+
103
108
create_log_method :info
104
109
create_log_method :error
105
110
create_log_method :fatal
@@ -123,22 +128,27 @@ def log(severity, message)
123
128
puts "[#{ SEVERITIES [ severity ] . to_s . downcase } ]: #{ message } "
124
129
end
125
130
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
128
134
#
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
137
145
yield
138
146
ensure
139
- clear_progress
147
+ self . level = old_level
140
148
end
141
149
150
+ # @!group Utility Printing Methods
151
+
142
152
# Displays a progress indicator for a given message. This progress report
143
153
# is only displayed on TTY displays, otherwise the message is passed to
144
154
# the +nontty_log+ level.
@@ -210,32 +220,36 @@ def backtrace(exc, level_meth = :error)
210
220
exc . backtrace [ 0 ..5 ] . map { |x | "\n \t #{ x } " } . join + "\n " )
211
221
end
212
222
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
+
213
243
# Warns that the Ruby environment does not support continuations. Applies
214
244
# to JRuby, Rubinius and MacRuby. This warning will only display once
215
245
# per Ruby process.
216
246
#
217
247
# @deprecated Continuations are no longer needed by YARD 0.8.0+.
218
248
# @return [void]
249
+ # @private
219
250
def warn_no_continuations
220
251
end
221
252
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
-
239
253
private
240
254
241
255
def clear_line
0 commit comments