You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Moataz Elmasry <za...@googlemail.com> on 2009/07/15 17:35:29 UTC

slf4j configuration

Hello List

I have aquestion regarding using slf4j, which I have zero experience 
with, in shiro. I've been looking for the configuration file for the 
logger or how is it initialized but couldn't find anything. I supposed 
that log4j is the ,default framework for logging (since there are 
log4j.properties everywhere), and so I set the logging level to INFO (or 
WARN) everywhere, but I still see the TRACE messages. Which 
log4j.properties is the default one?

Best regards
Moataz

Re: slf4j configuration

Posted by Les Hazlewood <lh...@apache.org>.
Hi Moataz,

SLF4J is a logging 'wrapper' API, very similar in concept to
commons-logging.

When using SLF4J at compile time, only slf4j-api.jar is required.  But at
runtime, SLF4J requires a minimum of 2 .jars in your classpath: the
slf4j-api.jar and one of its 'binding' jars.  An SLF4J binding knows how to
translate the slf4j-api calls to an actual logging subsystem implementation
(log4j, jdk logging, logback, etc).  If you want to use log4j, you'll need
at least 3 jars in your classpath:

log4j.jar
slf4j-api.jar
slf4j-log4j12.jar --> SLF4J's binding jar for log4j

If you have these 3, you can have a log4j.properties at the root of your
classpath and log4j will be used as the logging subsystem at runtime without
any problems.

Note that although Apache Shiro and many other open source projects have
moved to slf4j from commons-logging, there are still many projects that
still require the commons-logging API be present at runtime.  The way to
'trick' those 3rd party libs into thinking that commons-logging is
available, but really still go through slf4j, is to also include the
'jcl-over-slf4j.jar' file into any place where commons-logging might have
been used.  This ensures your logging infrastructure for your entire
application is consistent and uses one logging framework.  If you don't do
this, you could see classloading problems in some applications, so it is
highly recommended to ensure this.

If you're using Maven, the best way to determine what library might use
commons-logging is to run a 'mvn dependency:tree' and look at the output.
If you see any dependency (or even nested/transitive dependencies) that list
commons-logging, you'll want to have <exclude> elements for each artifact
you depend on and exclude commons-logging explicitly.  Look at Apache
Shiro's root pom.xml for examples of this and also check out Maven's
exclusion documentation [1] for more details.

Finally, Apache Shiro only has a required dependency on slf4j-api and NOT on
any of slf4j's binding .jars or even log4j - you can choose whatever logging
implementation you want for your own applications.  Any slf4j bindings or
log4j related jars/config you might see referenced in our project pom is
there only for the sample applications to use and have no bearing on Shiro's
requirements.

This has been a very quick summary of SLF4J - naturally, check out their
website [2] for better coverage of these topics.

Cheers,

Les

[1] http://maven.apache.org/pom.html#Exclusions
[2] http://www.slf4j.org

On Wed, Jul 15, 2009 at 11:35 AM, Moataz Elmasry <
zaza1851983ml@googlemail.com> wrote:

> Hello List
>
> I have aquestion regarding using slf4j, which I have zero experience with,
> in shiro. I've been looking for the configuration file for the logger or how
> is it initialized but couldn't find anything. I supposed that log4j is the
> ,default framework for logging (since there are log4j.properties
> everywhere), and so I set the logging level to INFO (or WARN) everywhere,
> but I still see the TRACE messages. Which log4j.properties is the default
> one?
>
> Best regards
> Moataz
>