How to do logging in Wildfly 8.2.0
hmyth Mar 22, 2015 4:10 AMI am attempting to teach myself basic J2EE web application development using wildlfy (and struts2 and eclipse). This is proving slightly more ambitious than I had hoped! My problem is to get my web application to log a message.
I don't mind which logging framework is used, but right now my only option seems to be to roll my own logging class.
Here is a simple action class, which is working apart from the logging in wildfly.
package com.tutorialspoint.struts2;
import org.apache.log4j.Logger; // But it doesnt matter what framework
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport{
private static Logger logger = org.apache.log4j.Logger.getLogger("application");
public static void main ( String[] args ) {
HelloWorldAction h = new HelloWorldAction();
try {
System.out.println( h.execute() );
} catch (Exception e) {
}
}
public String execute() throws Exception {
logger.info("Inside HelloWorldAction...."); // <------ This the bit that doesnt work
return SUCCESS;
}
}
In my application I have created a WEB-INF/classes/log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<param name="file" value="log4j.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
When I run the class as a standalone application it produces a log file with the log message. When I deploy the WAR file into wildfly the webapp runs (no problems importing log4j, then) but there is no log file produced.
Next attempt was to add the following to the wildfly-8.2.0-Final/standalone/configuration/standalone.xml
<size-rotating-file-handler name="SIZEFILE" autoflush="true">
<level name="INFO"/>
<file relative-to="jboss.server.log.dir" path="application.log"/>
<append value="true"/>
</size-rotating-file-handler>
<logger category="application" use-parent-handlers="false">
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="SIZEFILE"/>
</handlers>
</logger>
When I restart wildfly I get an empty wildfly-8.2.0-Final/standalone/application.log file created.
- so how can I get log4j to work OR
- how can I change my java code to call whatever logging class wildfly uses
- and for that matter how can I just get System.out.println( "Some message" ); to produce some output to the terminal window where I am running stanalone.sh ?