logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aidan Delaney <ai...@phoric.eu>
Subject RE: Initializing log4j in a library
Date Wed, 18 Jul 2012 18:05:12 GMT
On Wed, 2012-07-18 at 12:27 -0400, Tim Watts wrote:
On Wed, 2012-07-18 at 16:00 +0100, Aidan Delaney wrote:
> > >From what I can see, it's best to create a ProjectLogger with a
> > static initialiser
> >=20
> > public class ProjectLogger {
> >   static {
> >     Logger logger =3D Logger.getLogger(ProjectLogger.class.getName());
> >     BasicConfigurator.configure();
> >   }
> It's a bit insane. :-)  The easiest thing is to put a log4j.xml or
> log4j.properties file in the classpath and you're good to go.
>         http://logging.apache.org/log4j/1.2/manual.html#Default_Initialization_Procedure
> I've read, and re-read, and tried all the examples.  However, I seem to be missing how
I can create a Logger without -- at some stage -- using a configurator.

So I can use a BasicConfigurator, or take your suggestion, an use a log4j.properties and a

As a minimal working example, should the following work?
import org.apache.log4j.Logger;

public class MyApp {
    static Logger logger = Logger.getLogger(MyApp.class.getName());

    public static void main(String[] args) {
        logger.info("Entering application.");

        logger.info("Exiting application.");
>From my understanding of the documentation, it shouldn't.  In which case, as I have no
mainline in my application, I still think I need to provide some central place where the Basic/PropertyConfigurator
configures the root log4j logger.


To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message