-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to junit 5 + JerseyLogbackFilter
- Loading branch information
Showing
7 changed files
with
65 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.coreoz.jersey; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.turbo.TurboFilter; | ||
import ch.qos.logback.core.spi.FilterReply; | ||
import org.glassfish.jersey.server.internal.LocalizationMessages; | ||
import org.slf4j.Marker; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Change the log level of Jersey logs in case of problem when writing HTTP responses. | ||
* Indeed, it is not an application error, these errors do not concern the application, | ||
* and no application solution can be provided. | ||
* | ||
* To avoid raising an alert, these error logs are rewritten as warning logs. | ||
* | ||
* This code should be removed once https://github.com/eclipse-ee4j/jersey/issues/4420#issuecomment-1332087576 | ||
* is accepted. | ||
*/ | ||
public class JerseyLogbackFilter extends TurboFilter { | ||
@Override | ||
public FilterReply decide(Marker marker, ch.qos.logback.classic.Logger logger, Level level, String format, Object[] params, Throwable t) { | ||
if (level == Level.ERROR | ||
&& "org.glassfish.jersey.server.ServerRuntime$Responder".equals(logger.getName()) | ||
&& (LocalizationMessages.ERROR_WRITING_RESPONSE_ENTITY().equals(format) | ||
|| LocalizationMessages.ERROR_COMMITTING_OUTPUT_STREAM().equals(format) | ||
|| LocalizationMessages.ERROR_WRITING_RESPONSE_ENTITY_CHUNK().equals(format) | ||
|| LocalizationMessages.ERROR_CLOSING_COMMIT_OUTPUT_STREAM().equals(format) | ||
)) { | ||
Object[] paramsWithThrowable = params; | ||
if (t != null) { | ||
if (params != null) { | ||
paramsWithThrowable = Arrays.copyOf(params, params.length + 1); | ||
paramsWithThrowable[params.length] = t; | ||
} else { | ||
paramsWithThrowable = new Object[] { t }; | ||
} | ||
} | ||
// rewrite error log as warning log | ||
logger.warn(marker, format, paramsWithThrowable); | ||
return FilterReply.DENY; | ||
} | ||
return FilterReply.NEUTRAL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<turboFilter class="com.coreoz.jersey.JerseyLogbackFilter" /> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="com.coreoz" level="DEBUG"/> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 7 additions & 11 deletions
18
src/test/java/com/coreoz/integration/SampleIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters