I wanted the output from Timbre to be formatted the way pprint formats output, so I wrote this function:
(defn set-the-current-debugging-level [level-of-debugging]
;; 2013-03-01 - called when the app starts. level-of-debugging should be passed in as a
;; command line argument. If set to 'production', then all debugging and output to the
;; terminal is surpressed. Otherwise, we are in debugging mode, and a lot gets printed
;; to the terminal, mostly via timbre.
;;
;; 2013-03-08 - i love timbre, but i need the objects pretty printed to the terminal.
(timbre/set-config!
[:appenders :my-appender]
{:doc "The i-love-timbre-but-i-need-pretty-print appender"
:min-level :debug
:enabled? true
:async? false
:max-message-per-msecs nil ; No rate limiting
:fn (fn [{:keys [error? prefix message more]}](binding [out %28if error? err out%29]
%28pp/pprint prefix%29
%28pp/pprint message%29
%28pp/pprint more%29))})
(swap! is-this-development-or-production (fn [current-environment-as-string](if %28= level-of-debugging)
"production"
"development")))
(if (= @is-this-development-or-production "production")
(timbre/set-level! :error)
(timbre/set-level! :debug)))
I use Timbre in a lot of functions, running in different threads.
Suddenly, the output I get at the terminal became mangled garbage:
on -data-to-datab"as<eop,t "io ouarnt cvtpaluhu eea =nsd'tt athrehtar teoeafrd 'd>eTlh eetaete-uro<l/do-pssteioans>s"iogns
, eour c pu alnd thoreado usagke losoks l liikeke this:t "his
: ""
< option value='music'>Music"(debug/thread-top))
(debug/thread-top)
)
[" at the[ start o"f ade"lAolulr ki ndcsp</to pttihone> "]s]ta
rt of peu2013-Mar-12 23:03:21 -0400 MacBook-Pro.local DEBUG [kiosks-clojure.core] - in get-options-for-select-box: ["<option v
alue='dance'>Dance" "Theater" "Music" "
All kinds"]
r sainstd- thsreesasdi ouns-adgaet al-o"to2ok0-s1d 3l-iMkaer a-tt1ah2ib sa2:s3 e:[,03 31o:u42412 7-7r00 40000 c "pLua wDarenesdnt crteohs
yr-JeMaaavcdaB ouVosMka"ge 2l2o o#k<-TPhrroe.aldo s clailk eD EtBhUiGs :[ k[i3o1s4k4Ts2h-7rce7la0od0j[uDrees.tcrooryeJ]a"va
VM,05 ,"maiDne]s>t]ro[4y7J"a3i1vna6V0 0Mg0"e t"- 2o2p t#i<oTnhsr-efaodrT -hTsrheerlaedc-t1-1b"ox: 1"9
<Thea[dr[[eDaeds tTrhoryeJa"da[<vToaphrtVeiMoa,nd5- ,1vm1aa,luien=]'>d]a[n4c6e0'21>0D0a0n c"e1"1" 19 #<Thr5e,maadin]> ]\
T[h3r0e8a9d4[0T0h0r e"ad-T1h1r,ead-12" 20 #<Thread Thread[Th
r ead-12,5,main]>][51,3m4a2i7n0]0>0] [3"0894000 "Thread-12""<Tohread- 1230" #< 2Th1 re#<aTd hTrehared aTdh[rTehad[Tread-12,5,main]>][
13400000 "hread-13,5,maiTnh]r>e]a[960000 d"-13q"tp5 2211 8#8<9pT0thi0or5ne-a1 dv1a lTuSehe=rl'teehaceadtt[oerTr'h>rTheeaadte-r1<3/,op5
t,imona>i"n]>
] [960000"0 "q t1p15 2#1<8T8h9r0e0a5d- 1T1h rSeealde[cqtotrp052"18 81910 0#5<-T1h1r Seealde Tchtroera0d,[5q,tpm5a2i1n8]8>9]0[0854-9101
0S0e l"ectqort0p,55,main]>][849000 "qtp52121889080859-01035 -A1c3ce pAtcocre0pt oSer0l ecSteClehcatnCnehalnConnenleCoctnnore@c0t".<oo0r
[email protected] 0:v.a3l00u.e00=0':1m3u"s0i0c0'1>M"usic <1/3o pt# ih" r#e<a
I posted about this on the Clojure mailist, and folks could only suggest that concurrency was the problem, which seems obvious, but not helpful:
https://groups.google.com/forum/?fromgroups=#!topic/clojure/Vd0Px2v8V2I
I would like to use pprint with Timbre. Is this possible? Can you suggest why it causes such problems when called from multiple threads?