Fork me on GitHub
#pedestal
<
2021-09-01
>
isak17:09:05

When doing development with io.pedestal.log , is there a way to customize how the data gets formatted, specifically when it gets printed in the REPL console?

souenzzo18:09:35

@isak no, but you can do it via your provider For example, I use lockback and this is my logback.xml (thread)

souenzzo18:09:16

<configuration scan="true"
               scanPeriod="5 seconds">
    <appender name="STDOUT"
              class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{"mm:ss.SSS",UTC} %level %msg%n%replace(%caller{2..3}){'Caller\+[0-9]', ''}</pattern>
        </encoder>
    </appender>
    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
    <logger name="io.pedestal" level="ERROR"/>
    <logger name="org.eclipse" level="ERROR"/>
    <logger name="io.netty" level="INFO"/>
    <logger name="com.amazonaws" level="INFO"/>
    <logger name="datomic" level="ERROR"/>
</configuration>
Using this %caller{2..3} makes #cursive understand that line as a stacktrace line, then it turns it into a clickable link

👀 2
souenzzo18:09:54

You can also parse/pprint values, but you will need to write a custom appender (in the case of logback) It may bring complexities to compile your project.

souenzzo18:09:12

also, take a look at tap> and "REBL" things, like #reveal and others libs. It may solve your problem in another way

isak18:09:46

@U2J4FRT2T Ok nice, I'm also using logback and cursive. So is the pattern able to call arbitrary code?

souenzzo18:09:26

you will need to write a custom appender

isak18:09:57

Yea for tap> I found that really nice to use with cursive. I just added this and it works great for me:

;; Add puget printer for taps
  (require '[puget.printer])
  (let [print-taps-fn
        (fn [x]
          (puget.printer/with-options
            {:width 40 :map-coll-separator :line}
            (puget.printer/cprint x)))]
    (add-tap print-taps-fn))

isak18:09:52

Ok I may try to write a custom appender that uses puget for the console. Thanks for the help @U2J4FRT2T