SLF4J Logging for my classes

4 views
Skip to first unread message

aw

unread,
Oct 22, 2009, 2:23:16 PM10/22/09
to Lift
I am using SLF4J logging, but I am not sure if I am doing it the
"right" way...

I have pointed Lift to use SLF4J, and I call the enable routine and
have updated dependencies. All of that seems fine.

My question is around, how do my classes best use it... For example,
I am generally doing something like:

import org.slf4j.{Logger, LoggerFactory}
class Foo {
private val LOGGER = LoggerFactory.getLogger(getClass)
...
}

Is this what one would expect? Or is there a "Lift Way" that
obsoletes the above?

Jeppe Nejsum Madsen

unread,
Oct 22, 2009, 3:46:53 PM10/22/09
to lif...@googlegroups.com
aw <ant...@whitford.com> writes:

I suggest using Lift's Logger (it can be configured to use slf4j,
search the archives for details). It has the nice feature that the log
message is lazily evaluated, so you don't have to litter your code with

if(log.isDebugEnabled) log.debug(...)

Also, I create a trait:

trait Logging {
val log = LogBoot.loggerByName(this.getClass.getName)
}

This makes it easy to have logging in a class:

class myclass extends MyParent with Logging {
log.debug("logggin stuff")
}

/Jeppe

aw

unread,
Oct 23, 2009, 6:25:23 PM10/23/09
to Lift
Sure, I could create a trait as you suggested... But, this sounds
like a common problem -- does this not already exist? I see
discussions about adding it to Scala, but I don't think it exists.
And Lift already has a logging infrastructure (i.e. LogBoot as you
suggest). Does it not make sense to add this trait to lift-util or
lift-common? (I just want to avoid recreating the wheel.)
Reply all
Reply to author
Forward
0 new messages