Using my own format function with `log4-clj-format`

Viewed 53

I'm looking at log4-clj-layout to bring a little order to the mess that is logging in Java. I'd like play around a little with a format function of my own, but I'm failing at getting it to work.

Following the instructions on the page above I started with adding the following to my log4j.properties file:

log4j.appender.console.layout=log4_clj_layout.layout.Layout
log4j.appender.console.layout.FormatFn=json-format

That worked beautifully. Then I added a function, log-test.core/my-format and tried to use that for logging:

log4j.appender.console.layout=log4_clj_layout.layout.Layout
log4j.appender.console.layout.FormatFn=log-test.core/my-format

But now all I get is an error when starting:

(log/warn "foo")
Setting format-fn: log-est.core/my-format
log4j:WARN Failed to set property [formatFn] to value "log-test.core/my-format". 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
...

Clearly I'm missing something, but what?

I defined my format function like this (l is an alias for log4-clj-layout.layout):

(defn my-format [event]
  (pr event)
  (l/json-format event))

Any and all help would be much appreciated.

0 Answers
Related