Cookbook Recipe Request: Configuring Logging with Log4J

75 views
Skip to first unread message

Peter Robinett

unread,
Mar 6, 2013, 7:40:57 AM3/6/13
to lif...@googlegroups.com
Hi all,

I keep burning hours trying to get Log4J setup in my Lift app and I keep getting nowhere. I'd specifically like to only show messages from INFO and above (ie not not Mapper's DEBUG Schemefier messages). I need to use log4j because that's what JavaPNS requires.

Specifically, I had a dependency on "log4j" % "log4j" % "1.2.17" in my build.sbt and placed an appropriately named Log4J configuration file in src/main/resources/props/. I was constantly rereading the wiki and getting nowhere and then found a two year old thread that mentioned also needing a dependency on "org.slf4j" % "slf4j-log4j12" % "1.7.2". This is what I then get:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/peter/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/peter/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Actual binding is of type [ch.qos.logback.classic.selector.DefaultContextSelector]

Of course debug messages are still shown. So, what am I doing wrong? Is there any way to get Logback and Log4J to play together nicely?

Thanks,
Peter

Peter Robinett

unread,
Mar 6, 2013, 7:54:55 AM3/6/13
to lif...@googlegroups.com
Of course right after posting this I noticed Diego's post from yesterday which gives me the immediate solution to my problem: just create a logback.xml file for Lift to pick up. I've placed in in src/test/resources/ and it's working like a charm.

Sorry about that,
Peter

Jeppe Nejsum Madsen

unread,
Mar 6, 2013, 8:17:09 AM3/6/13
to lif...@googlegroups.com
On Wed, Mar 6, 2013 at 1:54 PM, Peter Robinett <pe...@bubblefoundry.com> wrote:
Of course right after posting this I noticed Diego's post from yesterday which gives me the immediate solution to my problem: just create a logback.xml file for Lift to pick up. I've placed in in src/test/resources/ and it's working like a charm.


I'm a little surprised that the wiki instructions doesn't work? If you need log4j it says:

"Add the following dependency


  "org.slf4j" % "slf4j-log4j12" % "1.6.1",
"

While Diego's solution works (for logback), it doesn't use the "Lift way" of configuring which uses the runmode to determine the correct config file to use.

I notice that since this commit: https://github.com/lift/lift_25_sbt/commit/b9779cc17413954b680881557cb6ce79d6e81db9 the sample projects also includes the config file in the non-Lift location

The original problem seems to be caused by including multiiple slf4j bindings, which makes sense since you added log4j and the lift default project includes logback. You need to remove/exclude the logback dependency if you want to use log4j.

/Jeppe

Diego Medina

unread,
Mar 6, 2013, 8:52:38 AM3/6/13
to Lift
>
> While Diego's solution works (for logback), it doesn't use the "Lift way" of
> configuring which uses the runmode to determine the correct config file to
> use.

just a note, ad soon as I have some time, I'll post a sample app where
placing the logback file in props wasn't working any more (not to say
that it should not be moved back, but to find out how to solve the
issue I had)

Thanks


>
> I notice that since this commit:
> https://github.com/lift/lift_25_sbt/commit/b9779cc17413954b680881557cb6ce79d6e81db9
> the sample projects also includes the config file in the non-Lift location
>
> The original problem seems to be caused by including multiiple slf4j
> bindings, which makes sense since you added log4j and the lift default
> project includes logback. You need to remove/exclude the logback dependency
> if you want to use log4j.
>
> /Jeppe
>
> --
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to liftweb+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://fmpwizard.telegr.am

Jeppe Nejsum Madsen

unread,
Mar 6, 2013, 8:57:46 AM3/6/13
to lif...@googlegroups.com
On Wed, Mar 6, 2013 at 2:52 PM, Diego Medina <di...@fmpwizard.com> wrote:
>
> While Diego's solution works (for logback), it doesn't use the "Lift way" of
> configuring which uses the runmode to determine the correct config file to
> use.

just a note, ad soon as I have some time, I'll post a sample app where
placing the logback file in props wasn't working any more (not to say
that it should not be moved back, but to find out how to solve the
issue I had)


Please do. Just tried it with the default  lift_basic app and seems to work so would be nice to figure out why it doesn't work for some  :-)

/Jeppe

Diego Medina

unread,
Mar 6, 2013, 9:01:05 AM3/6/13
to Lift
yes, the short version of my issue was, I added lift shiro to my
project and boom, logfiles could not be read any more :(

Jonathan Schwietert

unread,
Apr 30, 2013, 4:54:37 PM4/30/13
to lif...@googlegroups.com
Has this been resolved by 2.5RC5?

Diego Medina

unread,
Apr 30, 2013, 7:42:36 PM4/30/13
to Lift
this isn;t something we need to fix, it is more along the lines, some
libraries mess with how things work, if you have a problematic
library, then you need to move your log config file to resources/, if
not, you can use Lift's resources/props folder and use the naming
scheme for diff run modes.

Thanks

Diego

Jeppe Nejsum Madsen

unread,
May 1, 2013, 10:25:46 AM5/1/13
to lif...@googlegroups.com

Would be nice though to figure out why it doesn't work :-)

/Jeppe

Reply all
Reply to author
Forward
0 new messages