Clojure tools.logging does not register stacktrace

In the latest version (0.2.4) tools.logging, when registering with (error-exception), only an exception message is logged. I rely on printing a stack trace when an exception is thrown. Printing an exception in stderr or stdout is not an option.

As far as I can see in the source , (error ...) makes an exception as the first argument.

(log/error throwable error-message) 

What can I do to enable stack tracing during registration?

+6
source share
1 answer

Error Signature:

 (defmacro error "Error level logging using print-style args." {:arglists '([message & more] [throwable message & more])} [& args] `(logp :error ~@args )) 

which means that with only one parameter (as in (error some-exception) ), the parameter is a message (which in your case is toString some exception).

If you want to register a stack, you will need a second message with a parameter, for example:

 (def ex (RuntimeException. "ex")) (error ex "Something broke!") 

or

 (error ex ex) 
+3
source

Source: https://habr.com/ru/post/926505/


All Articles