0

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>
harishr
  • 17,807
  • 9
  • 78
  • 125
  • I am quite sure that apache org.apache.qpid use slf4j for logging, have you setup the __slf4j binder__ to use log4j as implementation ? Have you tried to add the for exampes the log4j-slf4j-impl-2.0.jar jar ? – gtosto Oct 17 '17 at 10:02
  • @gtosto added the details you needed as edit.. also I am newbie to java, do I need some other config setting somewhere to redirect sl4j to log4j – harishr Oct 18 '17 at 16:30
  • if you can: I suggest you to use a more recent version of the qpid amqp client that relies on the slf4j. Otherwise like stated by @rob-godfrey you have to configure the built-in java logging framework. See his answer. – gtosto Oct 19 '17 at 14:57

1 Answers1

0

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.

Rob Godfrey
  • 171
  • 1