Skip to content

Commit

Permalink
ID-4579: Document what part of class LogbackValve, in Logback for Tom…
Browse files Browse the repository at this point in the history
…cat, we have modified. (#123)
  • Loading branch information
oyri authored Sep 26, 2024
1 parent 148d15d commit fb0a3fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See [idporten-access-log-spring-boot-3-starter/src/main/resources/logback-access

To build and run the application you need:

* JDK 11
* JDK 17
* Maven

## Build library
Expand All @@ -25,6 +25,8 @@ mvn clean install
## Usage
The library can be imported through maven with (see latest version under [releases](https://github.com/felleslosninger/idporten-access-log-spring-boot-starter/releases)):
### Spring Boot 2:
Warning: This version is not maintained anymore, use Spring Boot 3 version instead.

```xml
<dependency>
<groupId>no.idporten.logging</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock;

//import org.apache.catalina.Lifecycle;

// Find code here https://repo1.maven.org/maven2/ch/qos/logback/access/tomcat/2.0.3/
// This class replaces ch.qos.logback.access.tomcat.LogbackValve
// This class is checked and conforms to version 2.0.3 of LogbackValve above.
//
// And it is not a very much better idea to override this class because of all the instance variables,
// especially hard with 'aai'. Causes you to include most of this anyway.
//
// Search for 'ID-porten' in this class to find custom code which makes it easier to upgrade to new version from Logback
// when our custom code is clearly marked.
/**
* This class is an implementation of tomcat's Valve interface, by extending
* ValveBase.
Expand Down Expand Up @@ -99,6 +107,8 @@ public class LogbackValve extends ValveBase

private ScheduledExecutorService scheduledExecutorService;


// ID-porten code start
private boolean filterStaticResources = true;
public void setFilterStaticResources(boolean filterStaticResources) {
this.filterStaticResources = filterStaticResources;
Expand All @@ -108,7 +118,7 @@ public void setFilterStaticResources(boolean filterStaticResources) {
public void setFilterPaths(List<String> filterPaths) {
this.filterPaths = filterPaths;
}

// ID-porten code end

public LogbackValve() {
putObject(CoreConstants.EVALUATOR_MAP, new HashMap<String, EventEvaluator<?>>());
Expand Down Expand Up @@ -256,6 +266,7 @@ public void invoke(Request request, Response response) throws IOException, Servl

getNext().invoke(request, response);

// ID-porten code start
if (response.getStatus() < 400) { // only filter out successful requests
if (filterStaticResources) {
Object handlerObject = request.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
Expand All @@ -273,6 +284,7 @@ public void invoke(Request request, Response response) throws IOException, Servl
}
}
}
// ID-porten code end

TomcatServerAdapter adapter = new TomcatServerAdapter(request, response);
IAccessEvent accessEvent = new AccessEvent(this, request, response, adapter);
Expand Down

0 comments on commit fb0a3fa

Please sign in to comment.