Hi - Is there a way to determine the current logging level in code? For example, I would like to do extra work (e.g. maybe record timing information) only if @debug logging is turned on for that module/file. E.g…
if loglevel == Debug # What goes here?
# Do something extra
results = collect_extra_diagnostics()
@debug "Results are $results"
Or in general is doing this a bad idea? Thanks for any help/advice! - Adam
I think you are “supposed” to do something like:
@debug "Results are " results = collect_extra_diagnostics()
and then that code only run if the debug code is executed.
Cool! I didn’t realize that would work! Will try it. Thanks!
To add to this, you can do
# computations #
formatted_result = ...
for complicated debug operations.
Nice! I still don’t have an intuition for when begin & end can be tacked onto the end of a statement. This helps. Thanks - Adam
begin end creates a “block” expression. The “return” of a block is the last statement (
or an explicit not true, see reply). It behaves the same as any other julia expression, except the whole block is one expression (one standard “line”, up to the optional semicolon). You can do, e.g.
x = begin
y = #...
(indenting conventions are a bit weird in these cases, the above is my preferred, but not everyones…)
Unfortunately, this is wrong. If
return appears within a block, it does not
return from the block but from the enclosing function. Using
return inside a block passed to
@debug will not have the desired outcome.