@@ -53,14 +53,6 @@ shouldlog(logger::TerminalLogger, level, _module, group, id) =
53
53
54
54
min_enabled_level (logger:: TerminalLogger ) = logger. min_level
55
55
56
- # Formatting of values in key value pairs
57
- showvalue (io, msg) = show (io, " text/plain" , msg)
58
- function showvalue (io, e:: Tuple{Exception,Any} )
59
- ex,bt = e
60
- showerror (io, ex, bt; backtrace = bt!= nothing )
61
- end
62
- showvalue (io, ex:: Exception ) = showerror (io, ex)
63
-
64
56
function default_logcolor (level)
65
57
level < Info ? :blue :
66
58
level < Warn ? Base. info_color () :
@@ -146,6 +138,35 @@ function format_message(message::AbstractString, prefix_width, io_context)
146
138
msglines
147
139
end
148
140
141
+ # Formatting of values in key value pairs
142
+ showvalue (io, msg) = show (io, " text/plain" , msg)
143
+ function showvalue (io, e:: Tuple{Exception,Any} )
144
+ ex,bt = e
145
+ showerror (io, ex, bt; backtrace = bt!= nothing )
146
+ end
147
+ showvalue (io, ex:: Exception ) = showerror (io, ex)
148
+
149
+ # Generate a text representation of all key value pairs, split into lines with
150
+ # per-line indentation as an integer.
151
+ function format_key_value_pairs (kwargs, io_context)
152
+ msglines = Tuple{Int,String}[]
153
+ valbuf = IOBuffer ()
154
+ dsize = displaysize (io_context)
155
+ rows_per_value = max (1 , dsize[1 ]÷ (length (kwargs)+ 1 ))
156
+ valio = IOContext (valbuf, IOContext (io_context, :displaysize => (rows_per_value,dsize[2 ]- 3 )))
157
+ for (key,val) in kwargs
158
+ showvalue (valio, val)
159
+ vallines = split (String (take! (valbuf)), ' \n ' )
160
+ if length (vallines) == 1
161
+ push! (msglines, (2 ,SubString (" $key = $(vallines[1 ]) " )))
162
+ else
163
+ push! (msglines, (2 ,SubString (" $key =" )))
164
+ append! (msglines, ((3 ,line) for line in vallines))
165
+ end
166
+ end
167
+ msglines
168
+ end
169
+
149
170
function findbar (bartree, id)
150
171
if ! (bartree isa AbstractArray)
151
172
bartree. data. id === id && return bartree
169
190
170
191
const BAR_MESSAGE_ID = gensym (:BAR_MESSAGE_ID )
171
192
172
- function handle_progress (logger, progress)
193
+ function handle_progress (logger, progress, kwargs )
173
194
node = findbar (logger. bartrees, progress. id)
174
195
if node === nothing
175
196
# Don't do anything when it's already done:
@@ -244,39 +265,21 @@ function handle_message(logger::TerminalLogger, level, message, _module, group,
244
265
245
266
progress = asprogress (level, message, _module, group, id, filepath, line; kwargs... )
246
267
if progress != = nothing
247
- handle_progress (logger, progress)
268
+ handle_progress (logger, progress, kwargs )
248
269
return
249
270
end
250
271
251
- substr (s) = SubString (s, 1 , length (s)) # julia 0.6 compat
252
-
253
272
color,prefix,suffix = logger. meta_formatter (level, _module, group, id, filepath, line)
254
273
255
274
# Generate a text representation of the message
256
275
dsize = displaysize (logger. stream)
257
- msglines = format_message (message, textwidth (prefix),
258
- IOContext (logger . stream, :displaysize => (dsize[ 1 ],dsize[ 2 ] - 2 )) )
276
+ context = IOContext (logger . stream, :displaysize => (dsize[ 1 ],dsize[ 2 ] - 2 ))
277
+ msglines = format_message (message, textwidth (prefix), context )
259
278
# Add indentation level
260
279
msglines = [(0 ,l) for l in msglines]
261
- # Generate a text representation of all key value pairs, split into lines.
262
280
if ! isempty (kwargs)
263
- valbuf = IOBuffer ()
264
- rows_per_value = max (1 , dsize[1 ]÷ (length (kwargs)+ 1 ))
265
- valio = IOContext (IOContext (valbuf, logger. stream),
266
- :displaysize => (rows_per_value,dsize[2 ]- 5 ))
267
- if logger. show_limited
268
- valio = IOContext (valio, :limit => true )
269
- end
270
- for (key,val) in kwargs
271
- showvalue (valio, val)
272
- vallines = split (String (take! (valbuf)), ' \n ' )
273
- if length (vallines) == 1
274
- push! (msglines, (2 ,substr (" $key = $(vallines[1 ]) " )))
275
- else
276
- push! (msglines, (2 ,substr (" $key =" )))
277
- append! (msglines, ((3 ,line) for line in vallines))
278
- end
279
- end
281
+ ctx = logger. show_limited ? IOContext (context, :limit => true ) : context
282
+ append! (msglines, format_key_value_pairs (kwargs, ctx))
280
283
end
281
284
282
285
# Format lines as text with appropriate indentation and with a box
@@ -289,7 +292,7 @@ function handle_message(logger::TerminalLogger, level, message, _module, group,
289
292
(isempty (suffix) ? 0 : length (suffix)+ minsuffixpad)
290
293
justify_width = min (logger. right_justify, dsize[2 ])
291
294
if nonpadwidth > justify_width && ! isempty (suffix)
292
- push! (msglines, (0 ,substr (" " )))
295
+ push! (msglines, (0 ,SubString (" " )))
293
296
minsuffixpad = 0
294
297
nonpadwidth = 2 + length (suffix)
295
298
end
0 commit comments