Welcome! Please see the About page for a little more info on how this works.

0 votes
in tools.logging by
log/info removes quotes from strings making debugging harder than it needs to be.  I found that {:test1 "", :test2 "2"} is logged as {:test1  , :test2 2}.  I see the same issue when I print a map using println.  prn prints the map with the quotes which is better for debugging.

I will make a patch and add it later.

7 Answers

0 votes
by

Comment made by: llsouder

Retested with 0.4.0

user=> (log/info ["test" "1" "" "3"]) Jul 23, 2017 8:22:56 AM user invoke INFO: [test 1 3] user=> (log/info ":one" :one 1 "1") Jul 23, 2017 8:35:30 AM user invoke INFO: :one :one 1 1

Output should be:

INFO: ["test" "1" "" "3"]

and

INFO: [":one" :one 1 "1"]

0 votes
by

Comment made by: llsouder

Replace print-str with prn-str so user can see what will be evaluated. This is useful in debugging programs but I can see how this may mess up human readable info output out there in the wild.

0 votes
by

Comment made by: tangrammer

Hi guys, I could avoid this annoying problem adding overwriting print-method for String type in my app code ... is it a convenient approach?

`
(defmethod clojure.core/print-method String

 [s ^java.io.Writer writer]

(.write writer (str "\"" s "\"")))
`

0 votes
by

Comment made by: ilmoraunio

Attached is an alternative fix to the already proposed TLOG20.patch, where we use pr-str instead. This changeset allows for logged Clojure code to be compiler compliant when copypasted into a REPL (for example). The changeset affects the usage of logp and its derivatives.

This fix is necessary for easier debugging of production problems and, particularly, when a Clojure data entity is too large to do quote insertions manually.

0 votes
by
_Comment made by: ataggart_

Despite the examples given, many real-world log entries contain not only structured data, but also human-readable explanatory text.  As such, switching to always using `pr-str` will emit quotes and escaped characters when _not_ desired, and with no way to work around it (unlike how one can work around the current issue by manually wrapping values with `pr-str`). This kind of breaking change is a no-go.

That said, it may be reasonable to add _new_ macros to handle this common point of friction.

A variant of `logp` is problematic since in the common case of mixing text and data we can’t know for certain which args the user intends to be treated which way.

A variant of `logf` might work, whereby all format args are mapped over `pr-str`, with explanatory text residing in the format string.
0 votes
by
Reference: https://clojure.atlassian.net/browse/TLOG-20 (reported by llsouder)
Welcome to Clojure Q&A, where you can ask questions and receive answers from members of the Clojure community.
...