I am using slf4j with log4j, and for some reason all the logs are showing except the logs that I write in my code - Spring logs, Hibernate logs, you name it logs are showing and in the level configured in log4j.properties. My logs however, are not showing.
Maven dependencies: log4j log4j 1.2.17 test
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j.version}</version>
<scope>test</scope>
</dependency>
When running with -Dlog4j.debug
I see that my log4j.propertes file is being used
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@11a5ee7c.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@11a5ee7c class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@11a5ee7c.
log4j: Using URL [ile:/C:/x/y/myProject/target/test-classes/log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL file:/C:/x/y/myProject/target/test-classes/log4j.properties
And I'm using the following log code:
private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);
LOG.warn("Very informative message");
My log4j.properties file:
# Define the root logger to the system property "hbase.root.logger".
log4j.rootLogger=DEBUG, console
# Logging Threshold
log4j.threshhold=ALL
#
# console appender
# Add "console" to rootLogger above if you want to use this
#
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %-5p [%t] %C{2}(%L): %m%n
Adding a specific line for my logger doesn't help as well
log4j.logger.com.my.path=DEBUG, console
And I can see that it is being recognized:
Parsing for [com.my.path] with value=[DEBUG, console].
log4j: Level token is [DEBUG].
log4j: Category com.my.path set to DEBUG
But still nothing is being logged.
log4j.appender.console=DEBUG,org.apache.log4j.ConsoleAppender
– Ankur Singhallog4j:ERROR Could not instantiate appender named "console".
– apineslog4j.appender.console.target=System.out
– Ankur Singhal