Log4j logging problem
gmgallo Jul 1, 2013 3:00 PMHi guys
I have finally started to use jboss7 (previously I used jboss4 and jboss5) and now I don't know how to use an external file for log4j configuration. In the specific I have a simple ejb project with a starter class that has the following code:
[code]
@Startup
@Singleton
public class Starter {
public static final Logger LOGGER = Logger.getLogger(Starter.class);
@PostConstruct
void init() {
System.out.println("Starting MSH backend");
System.out.println("Configuring properties");
try {
PropertiesManager.loadProperties();
System.out.println("Properties loaded, configuring loggers");
DOMConfigurator.configureAndWatch("/opt/ejb/ejbLog4j.xml"));
System.out.println("Loggers configured");
LOGGER.info("MSH EJB STARTED");
}
catch(IOException e) {
System.out.println("ERROR! Props file not found!");
}
catch(PropertyNotFoundException e) {
System.out.println("ERROR! Logger filename property not found");
}
}
}
[/code]
Simply I use DomConfigurator to read an external log4j configuration file and to configure the logger properly. This is the content of the xml file:
[code]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="mshEjb" class="org.apache.log4j.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Append" value="true"/>
<param name="File" value="/var/opt/msh/msh_ejb.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss.SSS} [%C{1}] - %m%n"/>
</layout>
</appender>
<category name="com.stonesoft.msh.ejb" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="mshEjb"/>
</category>
</log4j:configuration>
[/code]
The problem is that the application creates the log file correctly but nothing is written in it. In the server.log instead I can find both the standard print and the log print. I've tried all the ways I found in internet without luck. Any idea?
Thanks