mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
WW-4492 Add support for Log4J2 as a struts and xwork logging backend
- Use new log4j2 in blank and rest showcase app - Migrate to newer jetty plugin version
This commit is contained in:
+15
-3
@@ -48,8 +48,14 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -64,7 +70,7 @@
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>8.1.7.v20120910</version>
|
||||
<version>8.1.16.v20140903</version>
|
||||
<configuration>
|
||||
<stopKey>CTRL+C</stopKey>
|
||||
<stopPort>8999</stopPort>
|
||||
@@ -72,6 +78,12 @@
|
||||
<scanTargets>
|
||||
<scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget>
|
||||
</scanTargets>
|
||||
<systemProperties>
|
||||
<systemProperty>
|
||||
<name>xwork.loggerFactory</name>
|
||||
<value>com.opensymphony.xwork2.util.logging.log4j2.Log4j2LoggerFactory</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#
|
||||
# Log4J Settings for log4j 1.2.x (via jakarta-commons-logging)
|
||||
#
|
||||
# The five logging levels used by Log are (in order):
|
||||
#
|
||||
# 1. DEBUG (the least serious)
|
||||
# 2. INFO
|
||||
# 3. WARN
|
||||
# 4. ERROR
|
||||
# 5. FATAL (the most serious)
|
||||
|
||||
|
||||
# Set root logger level to WARN and append to stdout
|
||||
log4j.rootLogger=INFO, stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
|
||||
# Pattern to output the caller's file name and line number.
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n
|
||||
|
||||
# Print only messages of level ERROR or above in the package noModule.
|
||||
log4j.logger.noModule=FATAL
|
||||
|
||||
log4j.logger.com.opensymphony.xwork2=DEBUG
|
||||
log4j.logger.org.apache.struts2=DEBUG
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration>
|
||||
<Appenders>
|
||||
<Console name="STDOUT" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="com.opensymphony.xwork2" level="debug"/>
|
||||
<Logger name="org.apache.struts2" level="debug"/>
|
||||
<Root level="warn">
|
||||
<AppenderRef ref="STDOUT"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -63,7 +63,7 @@
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>8.1.7.v20120910</version>
|
||||
<version>8.1.16.v20140903</version>
|
||||
<configuration>
|
||||
<stopKey>CTRL+C</stopKey>
|
||||
<stopPort>8999</stopPort>
|
||||
|
||||
+13
-19
@@ -48,10 +48,18 @@
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-config-browser-plugin</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@@ -96,22 +104,17 @@
|
||||
<target>1.5</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>8.1.7.v20120910</version>
|
||||
<version>8.1.16.v20140903</version>
|
||||
<configuration>
|
||||
<stopKey>CTRL+C</stopKey>
|
||||
<stopPort>8999</stopPort>
|
||||
<systemProperties>
|
||||
<systemProperty>
|
||||
<name>log4j.configuration</name>
|
||||
<value>file:${basedir}/src/main/resources/log4j.properties</value>
|
||||
</systemProperty>
|
||||
<systemProperty>
|
||||
<name>slf4j</name>
|
||||
<value>false</value>
|
||||
<name>xwork.loggerFactory</name>
|
||||
<value>com.opensymphony.xwork2.util.logging.log4j2.Log4j2LoggerFactory</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
<scanIntervalSeconds>10</scanIntervalSeconds>
|
||||
@@ -121,16 +124,7 @@
|
||||
<descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor>
|
||||
</webAppConfig>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.demo.rest.example;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
public class Order {
|
||||
String id;
|
||||
String clientName;
|
||||
@@ -33,41 +37,39 @@ public class Order {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + amount;
|
||||
result = prime * result
|
||||
+ ((clientName == null) ? 0 : clientName.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
return result;
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
Order rhs = (Order) obj;
|
||||
return new EqualsBuilder()
|
||||
.append(this.id, rhs.id)
|
||||
.append(this.clientName, rhs.clientName)
|
||||
.append(this.amount, rhs.amount)
|
||||
.isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
final Order other = (Order) obj;
|
||||
if (amount != other.amount)
|
||||
return false;
|
||||
if (clientName == null) {
|
||||
if (other.clientName != null)
|
||||
return false;
|
||||
} else if (!clientName.equals(other.clientName))
|
||||
return false;
|
||||
if (id == null) {
|
||||
if (other.id != null)
|
||||
return false;
|
||||
} else if (!id.equals(other.id))
|
||||
return false;
|
||||
return true;
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder()
|
||||
.append(id)
|
||||
.append(clientName)
|
||||
.append(amount)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", id)
|
||||
.append("clientName", clientName)
|
||||
.append("amount", amount)
|
||||
.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.demo.rest.example;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.rest.DefaultHttpHeaders;
|
||||
import org.apache.struts2.rest.HttpHeaders;
|
||||
import org.apache.struts2.convention.annotation.Results;
|
||||
@@ -15,7 +17,9 @@ import com.opensymphony.xwork2.ValidationAwareSupport;
|
||||
@Result(name="success", type="redirectAction", params = {"actionName" , "orders"})
|
||||
})
|
||||
public class OrdersController extends ValidationAwareSupport implements ModelDriven<Object>, Validateable{
|
||||
|
||||
|
||||
private static final Logger log = LogManager.getLogger(OrdersController.class);
|
||||
|
||||
private Order model = new Order();
|
||||
private String id;
|
||||
private Collection<Order> list;
|
||||
@@ -51,6 +55,7 @@ public class OrdersController extends ValidationAwareSupport implements ModelDri
|
||||
|
||||
// DELETE /orders/1
|
||||
public String destroy() {
|
||||
log.debug("Delete order with id: {}", id);
|
||||
ordersService.remove(id);
|
||||
addActionMessage("Order removed successfully");
|
||||
return "success";
|
||||
@@ -58,6 +63,7 @@ public class OrdersController extends ValidationAwareSupport implements ModelDri
|
||||
|
||||
// POST /orders
|
||||
public HttpHeaders create() {
|
||||
log.debug("Create new order {}", model);
|
||||
ordersService.save(model);
|
||||
addActionMessage("New order created successfully");
|
||||
return new DefaultHttpHeaders("success")
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#
|
||||
# Log4J Settings for log4j 1.2.x (via jakarta-commons-logging)
|
||||
#
|
||||
# The five logging levels used by Log are (in order):
|
||||
#
|
||||
# 1. DEBUG (the least serious)
|
||||
# 2. INFO
|
||||
# 3. WARN
|
||||
# 4. ERROR
|
||||
# 5. FATAL (the most serious)
|
||||
|
||||
|
||||
# Set root logger level to WARN and append to stdout
|
||||
log4j.rootLogger=INFO, stdout
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target=System.out
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
|
||||
# Pattern to output the caller's file name and line number.
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n
|
||||
|
||||
# Print only messages of level ERROR or above in the package noModule.
|
||||
log4j.logger.noModule=FATAL
|
||||
|
||||
log4j.logger.com.opensymphony.xwork2=DEBUG
|
||||
log4j.logger.org.apache.struts2=DEBUG
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration>
|
||||
<Appenders>
|
||||
<Console name="STDOUT" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="com.opensymphony.xwork2" level="info"/>
|
||||
<Logger name="org.apache.struts2" level="info"/>
|
||||
<Logger name="org.demo.rest" level="debug"/>
|
||||
<Root level="warn">
|
||||
<AppenderRef ref="STDOUT"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -184,7 +184,7 @@
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>8.1.7.v20120910</version>
|
||||
<version>8.1.16.v20140903</version>
|
||||
<configuration>
|
||||
<stopKey>CTRL+C</stopKey>
|
||||
<stopPort>8999</stopPort>
|
||||
|
||||
Reference in New Issue
Block a user