Reputation: 9400
I setup my Java EE 6 application taking as a starting point the log4j quickstart in Jboss 7.1.
My key pom.xml additions are:
<dependencyManagement>
<dependencies>
<!-- Define Log4j dependency and its version -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
...
</dependencies>
</dependencyManagement>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>
Version is 1.2.16.
Now I can do:
private static final Logger logger = Logger.getLogger(MacchinarioController.class);
and use logger as expected. Good!
I have no log4j.xml nor .properties files.
Now I want Hibernate to print in console all SQL statements being executed, including parameters values.
I created this log4j.xml and put it in src/main/resources source folder:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="info"/>
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} [%t] %-5p %c{1} - %m%n"/>
</layout>
</appender>
<appender name="rolling-file" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="Program-Name.log"/>
<param name="MaxFileSize" value="1000KB"/>
<param name="MaxBackupIndex" value="4"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %l - %m%n"/>
</layout>
</appender>
<logger name="org.hibernate">
<level value="ALL" />
</logger>
<root>
<priority value ="debug" />
<appender-ref ref="console" />
<appender-ref ref="rolling-file" />
</root>
</log4j:configuration>
But nothing shows up, where am I doing wrong?
Upvotes: 2
Views: 3463
Reputation: 17760
Are you using the jboss-deployment-structure.xml to exclude the servers version of log4j?
If you're starting an application from scratch I definitely wouldn't choose log4j. I am biased to JBoss Logging, but JBoss Logging, slf4j or logback are far better than log4j.
By default JBoss AS 7 uses JBoss Logging with the JBoss Log Manager. Though really you would/could just use JBoss Logging as it will work with any of log manager.
If you do want to use log4j, don't use the log4j configuration. Add the logger/category to the logging subsystem to see the results you are looking for.
All that said, in the next release of JBoss AS 7 your log4j configuration would be found and would just work for you the way you expect it to. The changes have been pushed to the upstream.
Upvotes: 2