1
1
@data Verbosity begin
2
2
None
3
- Edge
4
3
Info
5
4
Warn
6
5
Error
6
+ Level (Int)
7
+ Edge
7
8
All
8
9
Default
9
- Level (Int)
10
- end
11
-
12
-
13
- function message_level (verbose:: AbstractVerbositySpecifier{true} , option, group)
14
- group = getproperty (verbose, group)
15
- opt_level = getproperty (group, option)
16
-
17
- @match opt_level begin
18
- Verbosity. None () => nothing
19
- Verbosity. Info () => Logging. Info
20
- Verbosity. Warn () => Logging. Warn
21
- Verbosity. Error () => Logging. Error
22
- Verbosity. Level (i) => Logging. LogLevel (i)
23
- end
24
- end
25
-
26
- function emit_message (
27
- f:: Function , verbose:: AbstractVerbositySpecifier{true} , option, group, file, line, _module)
28
- level = message_level (verbose, option, group)
29
10
30
- if ! isnothing (level)
31
- message = f ()
32
- Base. @logmsg level message _file= file _line= line _module= _module
33
- end
34
11
end
35
12
36
- function emit_message (message:: String , verbose:: AbstractVerbositySpecifier{true} , option, group, file, line, _module)
37
- level = message_level (verbose, option, group)
38
-
39
- if ! isnothing (level)
40
- Base. @logmsg level message _file= file _line= line _module= _module
41
- end
42
- end
43
-
44
- function emit_message (f, verbose:: AbstractVerbositySpecifier{false} , option, group, file, line, _module)
45
- end
46
-
47
- @doc doc"""
48
- A macro that emits a log message based on the log level specified in the `option` and `group` of the `AbstractVerbositySpecifier` supplied.
49
-
50
- `f_or_message` may be a message String, or a 0-argument function that returns a String.
51
-
52
- ## Usage
53
- To emit a simple string, `@SciMLMessage("message", verbosity, :option, :group)` will emit a log message with the LogLevel specified in `verbosity`, at the appropriate `option` and `group`.
54
-
55
- `@SciMLMessage` can also be used to emit a log message coming from the evaluation of a 0-argument function. This function is resolved in the environment of the macro call.
56
- Therefore it can use variables from the surrounding evironment. This may be useful if the log message writer wishes to carry out some calculations using existing variables
57
- and use them.
58
-
59
- ```julia
60
- x = 10
61
- y = 20
62
-
63
- @SciMLMessage(verbosity, :option, :group) do
64
- z = x + y
65
- "Message is: x + y = \$ z"
66
- end
67
- ```
68
- """
69
- macro SciMLMessage (f_or_message, verb, option, group)
70
- line = __source__. line
71
- file = string (__source__. file)
72
- _module = __module__
73
- return :(emit_message ($ (esc (f_or_message)), $ (esc (verb)), $ toggle, $ group, $ file, $ line, $ _module))
74
- end
75
-
76
-
77
13
# Linear Verbosity
78
14
79
15
mutable struct LinearErrorControlVerbosity
@@ -88,9 +24,9 @@ function LinearErrorControlVerbosity(verbose::Verbosity.Type)
88
24
89
25
Verbosity. Error () => LinearErrorControlVerbosity (fill (Verbosity. Error (), nfields (LinearErrorControlVerbosity))... )
90
26
91
- Verbosity. Default () => LinearErrorControlVerbosity (Verbosity . Info (), Verbosity . Error () )
27
+ Verbosity. Default () => LinearErrorControlVerbosity ()
92
28
93
- Verbosity. Edge () => LinearErrorControlVerbosity (Verbosity . Info (), Verbosity . Warn () )
29
+ Verbosity. Edge () => LinearErrorControlVerbosity ()
94
30
95
31
_ => @error " Not a valid choice for verbosity."
96
32
end
@@ -116,10 +52,9 @@ function LinearPerformanceVerbosity(verbose::Verbosity.Type)
116
52
Verbosity. Error () => LinearPerformanceVerbosity (fill (
117
53
Verbosity. Error (), nfields (LinearPerformanceVerbosity))... )
118
54
119
- Verbosity. Default () => LinearPerformanceVerbosity (
120
- Verbosity. Info (), Verbosity. Error ())
55
+ Verbosity. Default () => LinearPerformanceVerbosity ()
121
56
122
- Verbosity. Edge () => LinearPerformanceVerbosity (Verbosity . Info (), Verbosity . Warn () )
57
+ Verbosity. Edge () => LinearPerformanceVerbosity ()
123
58
124
59
_ => @error " Not a valid choice for verbosity."
125
60
end
@@ -144,10 +79,9 @@ function LinearNumericalVerbosity(verbose::Verbosity.Type)
144
79
Verbosity. Error () => LinearNumericalVerbosity (fill (
145
80
Verbosity. Error (), nfields (LinearNumericalVerbosity))... )
146
81
147
- Verbosity. Default () => LinearNumericalVerbosity (
148
- Verbosity. Info (), Verbosity. Error ())
82
+ Verbosity. Default () => LinearNumericalVerbosity ()
149
83
150
- Verbosity. Edge () => LinearNumericalVerbosity (Verbosity . Info (), Verbosity . Warn () )
84
+ Verbosity. Edge () => LinearNumericalVerbosity ()
151
85
152
86
_ => @error " Not a valid choice for verbosity."
153
87
end
@@ -203,18 +137,17 @@ function NonlinearErrorControlVerbosity(verbose::Verbosity.Type)
203
137
Verbosity. Error () => NonlinearNumericalVerbosity (fill (
204
138
Verbosity. Error (), nfields (NonlinearErrorControlVerbosity))... )
205
139
206
- Verbosity. Default () => NonlinearErrorControlVerbosity (
207
- Verbosity. Info (), Verbosity. Error ())
140
+ Verbosity. Default () => NonlinearErrorControlVerbosity ()
208
141
209
- Verbosity. Edge () => NonlinearErrorControlVerbosity (Verbosity . Info (), Verbosity . Warn () )
142
+ Verbosity. Edge () => NonlinearErrorControlVerbosity ()
210
143
211
144
_ => @error " Not a valid choice for verbosity."
212
145
end
213
146
end
214
147
215
148
mutable struct NonlinearPerformanceVerbosity
216
149
@add_kwonly function NonlinearPerformanceVerbosity ()
217
- NonlinearPerformanceVerbosity ()
150
+ new ()
218
151
end
219
152
220
153
end
@@ -231,11 +164,9 @@ function NonlinearPerformanceVerbosity(verbose::Verbosity.Type)
231
164
Verbosity. Error () => NonlinearPerformanceVerbosity (fill (
232
165
Verbosity. Error (), nfields (NonlinearPerformanceVerbosity))... )
233
166
234
- Verbosity. Default () => NonlinearPerformanceVerbosity (
235
- Verbosity. Info (), Verbosity. Error ())
167
+ Verbosity. Default () => NonlinearPerformanceVerbosity ()
236
168
237
- Verbosity. Edge () => NonlinearPerformanceVerbosity (
238
- Verbosity. Info (), Verbosity. Warn ())
169
+ Verbosity. Edge () => NonlinearPerformanceVerbosity ()
239
170
240
171
_ => @error " Not a valid choice for verbosity."
241
172
end
244
175
245
176
mutable struct NonlinearNumericalVerbosity
246
177
@add_kwonly function NonlinearNumericalVerbosity ()
247
- NonlinearNumericalVerbosity ()
178
+ new ()
248
179
end
249
180
end
250
181
@@ -259,11 +190,9 @@ function NonlinearNumericalVerbosity(verbose::Verbosity.Type)
259
190
Verbosity. Error () => NonlinearNumericalVerbosity (fill (
260
191
Verbosity. Error (), nfields (NonlinearPerformanceVerbosity))... )
261
192
262
- Verbosity. Default () => NonlinearNumericalVerbosity (
263
- Verbosity. Info (), Verbosity. Error ())
193
+ Verbosity. Default () => NonlinearNumericalVerbosity ()
264
194
265
- Verbosity. Edge () => NonlinearNumericalVerbosity (
266
- Verbosity. Info (), Verbosity. Warn ())
195
+ Verbosity. Edge () => NonlinearNumericalVerbosity ()
267
196
268
197
_ => @error " Not a valid choice for verbosity."
269
198
end
@@ -310,7 +239,7 @@ mutable struct ODEErrorControlVerbosity
310
239
init_NaN:: Verbosity.Type
311
240
312
241
@add_kwonly function ODEErrorControlVerbosity (dt_NaN, init_NaN)
313
- ODEErrorControlVerbosity (dt_NaN, init_NaN)
242
+ new (dt_NaN, init_NaN)
314
243
end
315
244
end
316
245
337
266
338
267
mutable struct ODEPerformanceVerbosity
339
268
@add_kwonly function ODEPerformanceVerbosity (dt_NaN, init_NaN)
340
- ODEPerformanceVerbosity (dt_NaN, init_NaN)
269
+ new (dt_NaN, init_NaN)
341
270
end
342
271
end
343
272
@@ -354,15 +283,15 @@ function ODEPerformanceVerbosity(verbose::Verbosity.Type)
354
283
Verbosity. Error () => ODEPerformanceVerbosity (fill (
355
284
Verbosity. Error (), nfields (ODEPerformanceVerbosity))... )
356
285
357
- Verbosity. Default () => ODEPerformanceVerbosity (Verbosity . Warn (), Verbosity . Error () )
286
+ Verbosity. Default () => ODEPerformanceVerbosity ()
358
287
359
288
_ => @error " Not a valid choice for verbosity."
360
289
end
361
290
end
362
291
363
292
mutable struct ODENumericalVerbosity
364
293
@add_kwonly function ODENumericalVerbosity (dt_NaN, init_NaN)
365
- ODEErrorControlVerbosity (dt_NaN, init_NaN)
294
+ new (dt_NaN, init_NaN)
366
295
end
367
296
end
368
297
@@ -379,7 +308,7 @@ function ODENumericalVerbosity(verbose::Verbosity.Type)
379
308
Verbosity. Error () => ODENumericalVerbosity (fill (
380
309
Verbosity. Error (), nfields (ODENumericalVerbosity))... )
381
310
382
- Verbosity. Default () => ODENumericalVerbosity (Verbosity . Warn (), Verbosity . Error () )
311
+ Verbosity. Default () => ODENumericalVerbosity ()
383
312
384
313
_ => @error " Not a valid choice for verbosity."
385
314
end
@@ -458,3 +387,72 @@ function ODEVerbosity(; error_control = Verbosity.Default(), performance = Verbo
458
387
459
388
ODEVerbosity (nonlinear, linear, error_control_verbosity, performance_verbosity, numerical_verbosity)
460
389
end
390
+
391
+
392
+ # Utilities
393
+
394
+ function message_level (verbose:: AbstractVerbositySpecifier{true} , option, group)
395
+ group = getproperty (verbose, group)
396
+ opt_level = getproperty (group, option)
397
+
398
+ @match opt_level begin
399
+ Verbosity. None () => nothing
400
+ Verbosity. Info () => Logging. Info
401
+ Verbosity. Warn () => Logging. Warn
402
+ Verbosity. Error () => Logging. Error
403
+ Verbosity. Level (i) => Logging. LogLevel (i)
404
+ end
405
+ end
406
+
407
+ function emit_message (
408
+ f:: Function , verbose:: AbstractVerbositySpecifier{true} , option, group, file, line, _module)
409
+ level = message_level (verbose, option, group)
410
+
411
+ if ! isnothing (level)
412
+ message = f ()
413
+ Base. @logmsg level message _file= file _line= line _module= _module
414
+ end
415
+ end
416
+
417
+ function emit_message (message:: String , verbose:: AbstractVerbositySpecifier{true} ,
418
+ option, group, file, line, _module)
419
+ level = message_level (verbose, option, group)
420
+
421
+ if ! isnothing (level)
422
+ Base. @logmsg level message _file= file _line= line _module= _module
423
+ end
424
+ end
425
+
426
+ function emit_message (
427
+ f, verbose:: AbstractVerbositySpecifier{false} , option, group, file, line, _module)
428
+ end
429
+
430
+ @doc doc"""
431
+ A macro that emits a log message based on the log level specified in the `option` and `group` of the `AbstractVerbositySpecifier` supplied.
432
+
433
+ `f_or_message` may be a message String, or a 0-argument function that returns a String.
434
+
435
+ ## Usage
436
+ To emit a simple string, `@SciMLMessage("message", verbosity, :option, :group)` will emit a log message with the LogLevel specified in `verbosity`, at the appropriate `option` and `group`.
437
+
438
+ `@SciMLMessage` can also be used to emit a log message coming from the evaluation of a 0-argument function. This function is resolved in the environment of the macro call.
439
+ Therefore it can use variables from the surrounding environment. This may be useful if the log message writer wishes to carry out some calculations using existing variables
440
+ and use them in the log message.
441
+
442
+ ```julia
443
+ x = 10
444
+ y = 20
445
+
446
+ @SciMLMessage(verbosity, :option, :group) do
447
+ z = x + y
448
+ "Message is: x + y = \$ z"
449
+ end
450
+ ```
451
+ """
452
+ macro SciMLMessage (f_or_message, verb, option, group)
453
+ line = __source__. line
454
+ file = string (__source__. file)
455
+ _module = __module__
456
+ return :(emit_message (
457
+ $ (esc (f_or_message)), $ (esc (verb)), $ toggle, $ group, $ file, $ line, $ _module))
458
+ end
0 commit comments