duct

erwinrooijakkers 2020-07-09T09:50:09.219200Z

Is it possible that module.web’s log-error does not log the exception when using clojure.tools.logging? clojure.tools.logging needs exception as first argument to be properly handled (e.g., the Sentry logback appender processing the stracktrace properly to be shown in Sentry) module.web has this handler:

(defn- log-error [logger ex] 
  (logger/log logger :error ::handler-error ex))
https://github.com/duct-framework/module.web/blob/6aa5ccb38280a872d45eaddbfab8e9fa1013ca5a/src/duct/middleware/web.clj#L18 The ClojureLogger is implemented like this:
(defrecord ClojureLogger []
  logger/Logger
  (-log [_ level ns _ _ _ event data]
    (let [level  (if (= level :report) :info level)
          logger (impl/get-logger log/*logger-factory* ns)]
      (cond
        (instance? Throwable event)
        (log/log* logger level event nil)
        (instance? Throwable data)
        (log/log* logger level data (pr-str event)) 
        (nil? data)
        (log/log* logger level nil (pr-str event))
        :else
        (log/log* logger level nil (pr-str event data))))))
So it seems that the log-error moves the exception as the 3th argument, which is an underscore in the implementation and thus event or data argument is not recognized as a throwable and the _ is ignored?

erwinrooijakkers 2020-07-09T09:54:25.219800Z

If this is the case I will create an issue, or do I overlook something?

walterl 2020-07-09T10:24:35.221Z

clojure.tools.logging/log* (note the *) takes a throwable as the third arg, according to its docs: https://clojure.github.io/tools.logging/#clojure.tools.logging/log*, so all seems in order to me

erwinrooijakkers 2020-07-09T11:29:36.221700Z

Thanks for that check 🙂 I referred to the arguments of -log

walterl 2020-07-09T11:38:20.222800Z

Looks like -log is only called by log-form (https://github.com/duct-framework/logger/blob/master/src/duct/logger.clj#L12), which puts the arguments in the right places. Am I missing something?

erwinrooijakkers 2020-07-09T12:52:39.223100Z

Ah log-form great

erwinrooijakkers 2020-07-09T12:55:51.223800Z

If that one is called also for other implementation of Logger then it should insert those two arguments

erwinrooijakkers 2020-07-09T12:56:29.224200Z

namespace and a delayed random/uuid

erwinrooijakkers 2020-07-09T12:56:51.224700Z

(-log [_ level ns _ _ _ event data] is the signature of the ClojureLogger (https://github.com/duct-framework/logger.clojure/blob/master/src/duct/logger/clojure.clj)

erwinrooijakkers 2020-07-09T12:57:21.225200Z

log-form has:

this level ns delay event data

erwinrooijakkers 2020-07-09T12:58:02.225700Z

ClojureLogger has: this level ns _ _ _ event data

erwinrooijakkers 2020-07-09T12:58:17.226100Z

So there seems to be a mismatch in argument count if log-form is used

erwinrooijakkers 2020-07-09T13:11:45.226800Z

Ah you are right

erwinrooijakkers 2020-07-09T13:11:57.227100Z

I missed the file and line

erwinrooijakkers 2020-07-09T13:12:20.227500Z

Okay this means that it fits like this;

erwinrooijakkers 2020-07-09T13:15:40.230Z

log-form:

this level ns file line delay event data
ClojureLogger:
_    level ns _    _    _     event data
So that’s fine

👍 1