ColdFusion ORM Book

Getting started with LogBox and ColdBox

I've been working on a ColdBox 3 site and decided to give in the in-built logging (with LogBox) a go. I thought I'd do a quick blog post to demonstrate how to use it as I found the docs a little bit confusing. LogBox can be used standalone, whereas when you use it with ColdBox a lot of the work is done for you.

By default ColdBox is configured with logging enabled and outputs to the console. Here's my Coldbox.cfc just to prove that I'm not cheating!

n a m e =s"escsaichoinnEgndKHeaynd"l eerx t e n d=s =&"qcuooltd;bo&xq.usoyts;t,e
m. i n tmeirscseipntgoTre"m
dle r = &/qu*o t;I&NqTuEoRtC;E,P
/ /--Er--r-o-r--/-E-x-c-e-p-t-i-o-n- -H-a-n-d-l--i-n-g--
--- - - -e-xc-ep-t-i-o-n-H-a-n-d-l-e-r- - - - =* &quo/t
u o t;,
/ * *
o n I n*v aIl iadmE vceanltl e d a t = t&hqeuo to;n&Rqeuquoets;t,
Ca p t ur ec uistnotmeErrcreoprtTiemonp lpaotien t
= *&qu/ot
&q u ovto;i,d
f u n c
t i o n on/Req/uAepsptlCiacpattuiroen( Arsepqeucitrse
d a n y heavnednlte,r Craecqhuiinrge d s t r u c=t ifnatlsee,r
ce p t D aetvae n)t
Ca c hin{g
= vfaarl sre
c = arg}ume;n
ts . e
v e nt./get/CLoalyleocutti Soent(t)i;n
vlaar yopurtcS e=t tairnggusm e=n ts.{ev
en t .g e tdCeoflaluelcttLiaoyno(u tp r= iv&aqtueo=tt;Lrauyeo u);t
. M ain}.cf


//Register interceptors as an array, we need order
interceptors = [


In my handler all I have to do is call the logger object.

wetlhciosm.emMaepspsiangges [= "&q/uointt;eWreclecpotmoer st"o] C=o lCdOBLoDx!B&OqXu_otA;P>P_
T_ P A T
H & " inter<ceptcfsetors /event."s;e


<!------------------------------------------- PRIVATE EVENTS ------------------------------------------>


Sure enough in my console I can see this:

ti[olno caadlhdotsotb aCsFk9e.t0(1 ]r:eINqFuO isreidm pelveelnotg g)i
ng . hand{ler
s . G e nvearra lr cE v=e nat rHgaunmdelnetrs .Ceavlelnetd. gEexttCroalIlnecfto:i o


Pretty sweet, huh. We can also output some extra information.

 lo<(&!q-u-o-t ;lEavyeonutt sH/aLnadyloeurt .CMaalilend.c&fqmu o-t-;-, {>ti
me=Now(<), crfc=oructput}>)


<cfset< hrtcm.lwel>co
meMessage = "Welcome to< hCeoaldd>Bo

<ti<tle>cfsetC oelvdebnotx .csaecthViinegw (e&xqaumoptl;eGeneral/index")><
/ t itle><

----------------------------<-b-o-d-y- P>RI
VATE EVENTS -------------<-p--->-L-a-y-o-u-t- -R-e--n-de-re-d-:- -#-N-o-w-(-)-#-->


<p>Basket Item

The output is:

<!--- views/General/in

There are also different types of messages I can use:

t;c ohmipnotn=e&nqtu oetx;tMeyn dmsa=i"n ceovlednbto&xq.usoyts;te>m.i
er c e p tor"
rg u mpernotp enratmye =n&aqmueo=t;ev"esnets&sqiuoonts;t orreaqgueir"ed= &iqnujeoctt;=true"&cqoulodtb;ox>:p
lu g i n:Ses<sioncfsetStor avgaer" rc;
= e v
en t .getC/ol*l eIcNtTiEoRnCE(P)TION>
<--!------- -t-e-l-l- -t-h-e- -L-o-g-B-o-x- i-n-s-t-a-n-c-e- -t-o- -l-o-g- -a-n- -i-n-f-o- -m--e--s-s-a g*e --/-


/ **
< *cfset I laomg .cianlfloe(d& qbuyo tt;hEev eornyRtehqiunegs tOCKa&pqtuureo ti;n)ter>c
ep t i o n
< *cfset/
og . wvaorind( &fquunoctt;iWoant cohn Roeuqtu!e&sqtuCoatp;t)ur

re qu i r ed any <evencfsett, r elqougi.reerdr osrt(r&uqcuto ti;nTtoeor cleaptteD&aqtuao t);


var r<c = cfsetargu mleongt.sf.aetvaeln(t&.qgueottC;o*l*lKeAcBtOiOoOnM(*)*;&
qu o t ; )

/ /
s i m p le way t<o cocfsetntro lr cc.awcehlicngo mbeaMseesds aogne n=u m&bqeuro to;fW eiltceommse itno tChoel dbBaosxk!e&tq
uo t ; rc
a s k
et i t e
ms = sessio<nstocfsetrage tVie"wb(a&sqkueotti;tGeemnse"ral, 0/ )i;n
de x &quo}t;)




<!------------------------------------------- PRIVATE EVENTS ------------------------------------------>


When I run the event I get the following in my console.

[localhost CF9.01]:INFO simplelogging.handlers.General Everything OK ExtraInfo:
[localhost CF9.01]:WARN simplelogging.handlers.General Watch out! ExtraInfo:
[localhost CF9.01]:ERROR simplelogging.handlers.General Too late ExtraInfo:
[localhost CF9.01]:FATAL simplelogging.handlers.General **KABOOOM** ExtraInfo:

Great now we can categorise logged messages, but logging to console might not suit your needs. Luckily, ColdBox has various different "appenders" which let you choose how you want to display the logged information. Let's configure ColdBox so that the logging information is output to the browser instead by adding a logBox struct to the ColdBox.cfc

/L a yout /Se*t*t
in g s
* I lraeydouucteS etthtei nbgasske t= i{te
ms c o undte
fa u l t*L*ayo/u
= & qvuooitd; Lfauynocutti.oMna irne.mcofvme&fqruoomtb;a
sk e t( r}equir;e
d e v
e n t )/
/ Reg{ist
er i n tvearrc erpct o=r sa ragsu maen natrsr.aeyv,e nwte. gneeteCdo lolredcetiro
n( ) ;i
nt e r c
ep t o r ss e=s s[
io n s t o rag/e./sAeuttvoawri(r e"
ba s k e t ite{ms"c,l assess=s&iqounosttor;acgoel.dgbeotxv.asry(s t"ebma.skienttietrecmespt"o,r s0. A)u t-o w1i r)e;
&q u o t ;
} s
et N e]x;t E v
e n t
( " g ene/ra/l "c o)n;f
i g ure }Log
logBox = {
appenders = {
coldboxTracer = {
root = { levelmax="DEBUG", levelMin="FATAL", appenders="*" }



You'll need to reload the ColdBox framework to pick up the new settings, but when you do you'll see that a new "ColdBox Tracer Messages" section has appeared in the Debugging info in your browser. The super sharp eyed amongest you may have noticed that I set the max logging level to DEBUG. This means that I can make use of the debug status which by default is disabled in ColdBox. To use the debug level simply call:

<cfset log.debug("testing 1,2,3")>

So, we've got some pretty powerful logging going on now, but in production we're not going to want to output to the Console or browser window, instead we want to log to a file so let's add the AsyncRollingFileAppender (Note: Normally, you wouldn't have the ColdboxTracerAppender and the AsyncRollingFileAppender enabled but this is a demo so what the heck!)

L}ayo u t R e n de
red: { ts '}2010-1,2-
11 20: 29 :3 2r'o}ot
B=as ket It{ems: 2
vlieew vreenldemread:x =&{qtus o't20;10D-E12B-U1G1& q2u0o:t2;9,: 3l2e'velM}in
uot;FATAL", appenders="*" }

If we reload the config again and check out the logs folder (ColdBox will create it if doesn't exist) and you'll see a file called MYERRORLOG.log which contains:

ew r
en&dqeuroetd;:S eve{rittys& q'u2o0t1;0,-&1q2u-o1t1; A2p0p:e2n8d:e3r8&'quot};,
"WARN","MYERRORLOG","12/02/2010","14:28:53","simplelogging.handlers.General","Watch out!"
"ERROR","MYERRORLOG","12/02/2010","14:28:53","simplelogging.handlers.General","Too late"

So what happened to the DEBUG and INFO messages? Well, when I configured the AsyncRollingFileAppender I set the max logging level to WARN. Anything lower than this is ignored. This is really cool for choosing which types of message you need to log in production.

Logging is a really powerful tool that tends to be overlooked as it's a pain to set up - but you've got no excuses now!

1 comment

  1. Very useful post, John. Thanks!!

    Comment by Tony Garcia – December 02, 2010

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments


Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)


Recent Posts