logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arwen Pond <ap...@book.com>
Subject RE: Set the log level based on command line args
Date Wed, 06 Aug 2014 18:49:31 GMT
This is what I have tried:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%-5p [%t]: %m%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="debug" level="debug">
            <AppenderRef ref="Console"/>
        </Logger>

        <Logger name="verbose" level="info">
            <AppenderRef ref="Console"/>
        </Logger>

        <Logger name="normal" level="warn">
            <AppenderRef ref="Console"/>
        </Logger>
    </Loggers>
</Configuration>

Then I call this:
Logger logger = LogManager.getLogger("verbose");
logger.info("Hello World");

But I see duplicated lines in the output.
INFO  [main]: Hello World
11:36:18.191 [main] INFO  verbose - Hello World

What am I doing wrong?

Thanks,
Arwen

-----Original Message-----
From: Arwen Pond 
Sent: Wednesday, August 06, 2014 10:42 AM
To: log4j-user@logging.apache.org
Subject: Set the log level based on command line args

I am investigating migrating from log4j 1 to log4j 2.  A pattern that I have in many of my
applications is setting the log level based on command line arguments.  So if the -v (verbose)
option is passed I set the log level to Info.  The default is set to warn.
    if (line.hasOption("v"))
    {
      logger.setLevel(Level.INFO);
    }

    if (line.hasOption("d"))
    {
      logger.setLevel(Level.DEBUG);
    }

In the world of log4j 2, what is the recommended way to accomplish this?

Thanks,
Arwen



This electronic mail message contains information that (a) is or may be CONFIDENTIAL, PROPRIETARY
IN NATURE, OR OTHERWISE PROTECTED BY LAW FROM DISCLOSURE, and (b) is intended only for the
use of the addressee(s) named herein.  If you are not an intended recipient, please contact
the sender immediately and take the steps necessary to delete the message completely from
your computer system.

Not Intended as a Substitute for a Writing: Notwithstanding the Uniform Electronic Transaction
Act or any other law of similar effect, absent an express statement to the contrary, this
e-mail message, its contents, and any attachments hereto are not intended to represent an
offer or acceptance to enter into a contract and are not otherwise intended to bind this sender,
barnesandnoble.com llc, barnesandnoble.com inc. or any other person or entity.

This electronic mail message contains information that (a) is or 
may be CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE 
PROTECTED 
BY LAW FROM DISCLOSURE, and (b) is intended only for the use of 
the addressee(s) named herein.  If you are not an intended 
recipient, please contact the sender immediately and take the 
steps necessary to delete the message completely from your 
computer system.

Not Intended as a Substitute for a Writing: Notwithstanding the 
Uniform Electronic Transaction Act or any other law of similar 
effect, absent an express statement to the contrary, this e-mail 
message, its contents, and any attachments hereto are not 
intended 
to represent an offer or acceptance to enter into a contract and 
are not otherwise intended to bind this sender, 
barnesandnoble.com 
llc, barnesandnoble.com inc. or any other person or entity.

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


Mime
View raw message