Reputation: 707
I want to use log4j 1.2.9 with spring 4.0.1 and JBOSS 7.1 but every time i get log information on console but the file is created and empty ...
log4j.properties
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\log\\loggingFile.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=INFO, file, stdout
web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Simple test Controller
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
@ManagedBean(name="MyController")
public class MyController {
static final Logger logger = Logger.getLogger(MyController.class);
public String test() {
BasicConfigurator.configure();
logger.debug(LoginController.class);
logger.info("Info.. ");
logger.error("Error..");
logger.fatal("Fatal");
return null;
}}
Upvotes: 0
Views: 959
Reputation: 707
the solution was to add jboss-deployment-structure.xml in /WEB-INF to exclude org.apache.log4j
<jboss-deployment-structure>
<deployment>
dependencies -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Upvotes: 1
Reputation: 8201
As your configurations look fine to me, I believe you have an extra copy of the log4j.jar
in your webapp
.
Moreover, why don't you use the logging subsystem
present in JBoss AS 7.x
? By this subsystem, you can have centralized configuration for all you want to achieve. It will be easier to maintain as well.
For this, just remove log4j.properties
and import log4j
/slf4j
via dependencies and make sure you don't pack your own log4j
/slf4j
jars in your webapp
.
Check out Logging Configuration for JBoss.
Shishir
Upvotes: 0