Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure tools.logging not logging stacktrace

Tags:

clojure

In the latest version (0.2.4) of tools.logging, when logging with (error some-exception), only the exception message is logged. I depend on having the stack trace printed when an exception is logged. Printing the exception to stderr or stdout is not an option.

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

 (log/error throwable error-message)

What can I do to include the stack traces when logging?

like image 567
Odinodin Avatar asked Sep 28 '12 12:09

Odinodin


1 Answers

The signature of error is:

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

which means that with just 1 param (as in (error some-exception)), the parameter is the message (which in your case is the toString of some-exception).

If you want to log the stacktrace you need a second param message like:

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

or

(error ex ex)
like image 73
DanLebrero Avatar answered Nov 02 '22 02:11

DanLebrero