Closed aviks closed 4 years ago
Hi @kmsquire any thoughts on this?
@aviks, sorry I never reviewed this. Are you still interested in pursuing it?
I think the idea seems pretty reasonable. However, I would implement it by specializing the individual logging functions (info
, debug
, err
, etc.) to each have this behavior when passed an Exception
. So your example would simply look like:
julia> try
1 % 0
catch e
Logging.err(e)
end
29-Dec 11:48:17:ERROR:root:integer division error
in rem at /Users/aviks/dev/julia/julia3/usr/lib/julia/sys.dylib
Yeah, that would have been a better API, this is ugly. Unfortunately, in Julia, exception objects don't seem to carry their backtraces with them. Backtraces can only be generated at a point in code, and so the Logging.catch_err
function is useful only when called within a catch block. I wanted to signal that fact in the code, and hence a separate function. If we do Logging.err(e)
, then calling that method of err
will again be effective only when called within a catch_block, but the function name or signature does not make that explicit. That seems like a recipe for misunderstanding, I thought.
With this change, we get the following output. Haven't exported the function yet, happy to take naming suggestions.