简体   繁体   中英

log4j not writing logs

Below is my log4j configuration

 #log4j.additivity.org.apache.qpid=false log4j.rootLogger=DEBUG, console log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.threshold=DEBUG log4j.appender.console.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n log4j.logger.javax.jms=DEBUG log4j.logger.org.apache.qpid=DEBUG log4j.logger.org.apache.qpid.amqp_1_0=DEBUG log4j.logger.org.apache.qpid.amqp_1_0.jms=DEBUG 

and then in code

    String log4jConfigFile = System.getProperty("user.dir") + File.separator + "log4j.properties";
    PropertyConfigurator.configure(log4jConfigFile);
    logger.debug("this is a debug log message");

my debug message this is a debug log message do get printed but the log messages from org.apache.qpid are not getting printed on console

    <dependency>
        <groupId>org.apache.qpid</groupId>
        <artifactId>qpid-amqp-1-0-client-jms</artifactId>
        <version>0.22</version>
    </dependency>

EDIT I am a newbie in java... The logging dependencies I have added. Do I need add some setting somewhere to redirect sl4j logs to log4j??

    <slf4j-version>1.6.6</slf4j-version>
    <log4j-version>1.2.17</log4j-version>

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j-version}</version>
    </dependency>

The (deprecated) qpid-amqp-1-0-client-jms client used java.util.logging , and not log4j. To quote from a mail I sent back in 2014 to the users@qpid.apache.org mailing list:

you can turn it on by setting the Java system property java.util.logging.config.file to point to a file that looks something like this:

 handlers=java.util.logging.FileHandler FRM.level=ALL java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=[%1$tc] %4$s: %5$s%n java.util.logging.FileHandler.level=ALL` # (The output file is placed in the directory # defined by the "user.home" System property.) java.util.logging.FileHandler.pattern=%h/qpid-jms-%u.log` 

When you run the client it should then generate a file called qpid-jms-0.log in your home directory, with output that looks something like:

 [Mon Feb 24 18:45:58 CET 2014] FINE: RECV[/127.0.0.1:5672|0] : SaslMechanisms{saslServerMechanisms=[ANONYMOUS]} 

Note that the logging in this old client is really very minimal and ideally you should instead migrate your code to the supported Qpid JMS client for AMQP 1.0 https://qpid.apache.org/components/jms/index.html which does use slf4j, but uses different configuration syntax for connections and queues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM