Skip to content

Commit fe96b00

Browse files
Merge remote-tracking branch 'upstream/develop' into develop
2 parents bda467c + 26cd799 commit fe96b00

File tree

44 files changed

+2110
-2005
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2110
-2005
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.iml
55
.*
66
target/
7+
jsclient/
78
eclipse-target/
89
**/src/generated/
910
**/tmp/

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "oasp4j-ide"]
55
path = oasp4j-ide
66
url = https://github.com/oasp/oasp4j-ide.git
7+
[submodule "oasp4js"]
8+
path = oasp4j-samples/oasp4j-sample-server/src/main/client
9+
url = https://github.com/oasp/oasp4js.git

oasp4j-modules/oasp4j-logging/pom.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
<groupId>org.codehaus.janino</groupId>
4242
<artifactId>janino</artifactId>
4343
</dependency>
44-
44+
<dependency>
45+
<groupId>org.apache.httpcomponents</groupId>
46+
<artifactId>httpclient</artifactId>
47+
</dependency>
4548
<dependency>
4649
<groupId>io.oasp.java.modules</groupId>
4750
<artifactId>oasp4j-test</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package io.oasp.module.logging.common.impl;
2+
3+
import java.io.IOException;
4+
import java.util.concurrent.TimeUnit;
5+
6+
import javax.servlet.Filter;
7+
import javax.servlet.FilterChain;
8+
import javax.servlet.FilterConfig;
9+
import javax.servlet.ServletException;
10+
import javax.servlet.ServletRequest;
11+
import javax.servlet.ServletResponse;
12+
import javax.servlet.http.HttpServletRequest;
13+
import javax.servlet.http.HttpServletResponse;
14+
15+
import org.apache.http.HttpStatus;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
19+
/**
20+
*
21+
* Request logging filter that measures the execution time of a request.
22+
*
23+
* @author trippl
24+
* @since 1.5.0
25+
*/
26+
public class PerformanceLogFilter implements Filter {
27+
28+
private static final Logger LOG = LoggerFactory.getLogger(PerformanceLogFilter.class);
29+
30+
/**
31+
* Optional filter to only measure execution time of requests that match the filter.
32+
*/
33+
private String urlFilter;
34+
35+
/**
36+
* The constructor.
37+
*/
38+
public PerformanceLogFilter() {
39+
40+
super();
41+
}
42+
43+
@Override
44+
public void init(FilterConfig config) throws ServletException {
45+
46+
this.urlFilter = null;
47+
}
48+
49+
@Override
50+
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
51+
ServletException {
52+
53+
long startTime;
54+
String path = ((HttpServletRequest) request).getServletPath();
55+
String url = ((HttpServletRequest) request).getRequestURL().toString();
56+
57+
if (this.urlFilter == null || path.matches(this.urlFilter)) {
58+
startTime = System.nanoTime();
59+
try {
60+
chain.doFilter(request, response);
61+
logPerformance(response, startTime, url, null);
62+
} catch (Throwable error) {
63+
logPerformance(response, startTime, url, error);
64+
}
65+
} else {
66+
chain.doFilter(request, response);
67+
}
68+
}
69+
70+
/**
71+
* Logs the request URL, execution time and {@link HttpStatus}. In case of an error also logs class name and error
72+
* message.
73+
*
74+
* @param response - the {@link ServletResponse}
75+
* @param startTime - start time of the {@link #doFilter(ServletRequest, ServletResponse, FilterChain)} function
76+
* @param url - requested URL
77+
* @param error - error thrown by the requested servlet, {@code null} if execution did not cause an error
78+
*/
79+
private void logPerformance(ServletResponse response, long startTime, String url, Throwable error) {
80+
81+
long endTime, duration;
82+
int statusCode = ((HttpServletResponse) response).getStatus();
83+
endTime = System.nanoTime();
84+
duration = TimeUnit.MILLISECONDS.convert(endTime - startTime, TimeUnit.NANOSECONDS);
85+
86+
String errorClass = "";
87+
String errorMessage = "";
88+
if (error != null) {
89+
statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR;
90+
errorClass = error.getClass().getName();
91+
errorMessage = error.getMessage();
92+
}
93+
String message =
94+
createMessage(url, Long.toString(duration), Integer.toString(statusCode), errorClass, errorMessage);
95+
LOG.info(message);
96+
}
97+
98+
/**
99+
* Returns a {@link String} representing the log message, which contains the given arguments separated by ';'
100+
*
101+
* @param args - the arguments for the log message
102+
* @return a {@link String} representing the log message
103+
*/
104+
private String createMessage(String... args) {
105+
106+
return String.join(";", args);
107+
}
108+
109+
@Override
110+
public void destroy() {
111+
112+
// nothing to do...
113+
}
114+
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<included>
3+
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
5+
<pattern>${logPattern}</pattern>
6+
</encoder>
7+
</appender>
8+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<included>
3+
<appender name="DEBUG_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
4+
<File>${logPath}/${debugLogFile}.log</File>
5+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
6+
<fileNamePattern>${logPath}/${debugLogFile}_${rollingPattern}${rollingSuffix}.log</fileNamePattern>
7+
<maxHistory>${rollingAppenderMaxHistory}</maxHistory>
8+
</rollingPolicy>
9+
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
10+
<layout class="io.oasp.module.logging.common.impl.SingleLinePatternLayout">
11+
<pattern>${logPattern}</pattern>
12+
</layout>
13+
</encoder>
14+
</appender>
15+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<included>
3+
<appender name="INFO_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
4+
<File>${logPath}/${infoLogFile}.log</File>
5+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
6+
<level>INFO</level>
7+
</filter>
8+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
9+
<fileNamePattern>${logPath}/${infoLogFile}_${rollingPattern}${rollingSuffix}.log</fileNamePattern>
10+
<maxHistory>${rollingAppenderMaxHistory}</maxHistory>
11+
</rollingPolicy>
12+
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
13+
<layout class="io.oasp.module.logging.common.impl.SingleLinePatternLayout">
14+
<pattern>${logPattern}</pattern>
15+
</layout>
16+
</encoder>
17+
</appender>
18+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<included>
3+
<appender name="ERROR_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
4+
<File>${logPath}/${errorLogFile}.log</File>
5+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
6+
<level>WARN</level>
7+
</filter>
8+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
9+
<fileNamePattern>${logPath}/${errorLogFile}_${rollingPattern}${rollingSuffix}.log</fileNamePattern>
10+
<maxHistory>${rollingAppenderMaxHistory}</maxHistory>
11+
</rollingPolicy>
12+
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
13+
<layout class="io.oasp.module.logging.common.impl.SingleLinePatternLayout">
14+
<pattern>${logPattern}</pattern>
15+
</layout>
16+
</encoder>
17+
</appender>
18+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<included>
3+
<include resource="io/oasp/logging/logback/appender-file-warn.xml" />
4+
<include resource="io/oasp/logging/logback/appender-file-info.xml" />
5+
<include resource="io/oasp/logging/logback/appender-file-debug.xml" />
6+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<included>
3+
<include resource="io/oasp/logging/logback/appender-file-warn.xml" />
4+
<include resource="io/oasp/logging/logback/appender-file-info.xml" />
5+
</included>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
logPattern=[D: %d{ISO8601}] [P: %-5p] [C: %X{correlationId}] [T: %t] [L: %c] - [M: %m] %n
2+
rollingAppenderMaxHistory=240
3+
rollingPattern=%d{yyyy-MM-dd_HH}
4+
rollingSuffix=00
5+
logPath=logs
6+
errorLogFile=error_log_${HOSTNAME}_${appname}
7+
infoLogFile=info_log_${HOSTNAME}_${appname}
8+
debugLogFile=debug_log_${HOSTNAME}_${appname}

0 commit comments

Comments
 (0)