logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Erskine <michael.ersk...@ketech.com>
Subject RE: Simple log4j setup 1) to System.out.println (or eclipse console) or 2) file and 3) enableable at runtime + without need for log4j.xml ?
Date Wed, 30 Apr 2008 13:37:38 GMT
Rob Davis-5 [mailto:tech@robertjdavis.co.uk] wrote:

> Hi, I'm looking at setting up a simple log4j setup to:
> 1) output logs to System.out.println (or the Eclipse console) when
> developing software
> 2) output to file(s) when the software is used in production
> 3) enableable/disableable at runtime - e.g. via a method

> Is this possible without using a log4j.xml file ?


...or call something like the following perhaps from a static block...

        if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
                new ConsoleAppender(new PatternLayout(
                    "%-5p %d{HH:mm:ss.SSS} %c [%t] %m%n")));

...which is pretty much what BasicConfigurator.configure() does but with a less useful PatternLayout.
I have a class that does this for me and is included in my eclipse JUnit templates.

> Is there a log4j class that I can call methods on directly to set up the
> above three things?

Logger.getRootLogger() is your starting point. Then you can configure individual Appender
instances to your liking.

Michael Erskine.

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

View raw message