-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
183 additions
and
5 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
38 changes: 38 additions & 0 deletions
38
idporten-access-log-spring-boot-3-starter/src/main/resources/logback-access-req-full.xml
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,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration debug="false"> | ||
<property resource="application.yaml" /> | ||
<property resource="application.yml" /> | ||
<appender name="accessJsonConsoleAppender" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder class="net.logstash.logback.encoder.AccessEventCompositeJsonEncoder"> | ||
|
||
<providers> | ||
<timestamp /> | ||
<pattern> | ||
<pattern> | ||
{ | ||
"@version" : "1", | ||
"@type" : "access", | ||
"logtype": "tomcat-access", | ||
"x_forwarded_for": "%header{X-Forwarded-For}", | ||
"client_host" : "%clientHost", | ||
"remote_user" : "%user", | ||
"request_method" : "%requestMethod", | ||
"request_url" : "%requestURL", | ||
"request_uri" : "%requestURI", | ||
"status_code" : "#asLong{%statusCode}", | ||
"bytes_sent" : "#asLong{%bytesSent}", | ||
"elapsed_time" : "#asLong{%elapsedTime}", | ||
"message" : "%requestURL %statusCode", | ||
"user_agent": "%i{User-Agent}", | ||
"referer": "%header{Referer}", | ||
"fullRequest":"%fullRequest" | ||
} | ||
</pattern> | ||
</pattern> | ||
<provider class="no.idporten.logging.access.AccesslogProvider"/> | ||
</providers> | ||
|
||
</encoder> | ||
</appender> | ||
<appender-ref ref="accessJsonConsoleAppender" /> | ||
</configuration> |
39 changes: 39 additions & 0 deletions
39
...rten-access-log-spring-boot-3-starter/src/main/resources/logback-access-req-resp-full.xml
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration debug="false"> | ||
<property resource="application.yaml" /> | ||
<property resource="application.yml" /> | ||
<appender name="accessJsonConsoleAppender" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder class="net.logstash.logback.encoder.AccessEventCompositeJsonEncoder"> | ||
|
||
<providers> | ||
<timestamp /> | ||
<pattern> | ||
<pattern> | ||
{ | ||
"@version" : "1", | ||
"@type" : "access", | ||
"logtype": "tomcat-access", | ||
"x_forwarded_for": "%header{X-Forwarded-For}", | ||
"client_host" : "%clientHost", | ||
"remote_user" : "%user", | ||
"request_method" : "%requestMethod", | ||
"request_url" : "%requestURL", | ||
"request_uri" : "%requestURI", | ||
"status_code" : "#asLong{%statusCode}", | ||
"bytes_sent" : "#asLong{%bytesSent}", | ||
"elapsed_time" : "#asLong{%elapsedTime}", | ||
"message" : "%requestURL %statusCode", | ||
"user_agent": "%i{User-Agent}", | ||
"referer": "%header{Referer}", | ||
"fullRequest":"%fullRequest", | ||
"fullResponse":"%fullResponse" | ||
} | ||
</pattern> | ||
</pattern> | ||
<provider class="no.idporten.logging.access.AccesslogProvider"/> | ||
</providers> | ||
|
||
</encoder> | ||
</appender> | ||
<appender-ref ref="accessJsonConsoleAppender" /> | ||
</configuration> |
54 changes: 54 additions & 0 deletions
54
...-boot-3-starter/src/test/java/no/idporten/logging/access/AccessLogsConfigurationTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package no.idporten.logging.access; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static no.idporten.logging.access.AccessLogsConfiguration.*; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class AccessLogsConfigurationTest { | ||
@DisplayName("When no configfile or debug configured then use default configfile") | ||
@Test | ||
public void useDefaultConfigFile() { | ||
AccessLogsConfiguration config = new AccessLogsConfiguration(); | ||
String configToUse = config.checkIfDebugFeatureEnabledAndConfigureLogbackfile(DEFAULT_LOGBACK_CONFIG_FILE, null); | ||
assertEquals(DEFAULT_LOGBACK_CONFIG_FILE, configToUse); | ||
} | ||
|
||
@DisplayName("When external configfile is set, but no debug then use external configfile") | ||
@Test | ||
public void useExternalConfigFile() { | ||
AccessLogsConfiguration config = new AccessLogsConfiguration(); | ||
String configToUse = config.checkIfDebugFeatureEnabledAndConfigureLogbackfile("config-so-perfect.xml", null); | ||
assertEquals("config-so-perfect.xml", configToUse); | ||
} | ||
|
||
@DisplayName("When external configfile is set and debug then use external configfile") | ||
@Test | ||
public void useExternalConfigFileWhenDebugSet() { | ||
AccessLogsConfiguration config = new AccessLogsConfiguration(); | ||
String configToUse = config.checkIfDebugFeatureEnabledAndConfigureLogbackfile("config-so-perfect.xml", "request"); | ||
assertEquals("config-so-perfect.xml", configToUse); | ||
} | ||
|
||
@DisplayName("When no external configfile is set and debug is request then use full request file") | ||
@Test | ||
public void useDebugRequestFileWhenDebugSetAndNoExternalConfig() { | ||
AccessLogsConfiguration config = new AccessLogsConfiguration(); | ||
String configToUse = config.checkIfDebugFeatureEnabledAndConfigureLogbackfile(DEFAULT_LOGBACK_CONFIG_FILE, "request"); | ||
assertEquals(LOGBACK_CONFIG_REQ_FULL_FILE, configToUse); | ||
} | ||
|
||
@DisplayName("When no external configfile is set and debug is response then use full response file") | ||
@Test | ||
public void useDebugResponseFileWhenDebugSetAndNoExternalConfig() { | ||
AccessLogsConfiguration config = new AccessLogsConfiguration(); | ||
String configToUse = config.checkIfDebugFeatureEnabledAndConfigureLogbackfile(DEFAULT_LOGBACK_CONFIG_FILE, "response"); | ||
assertEquals(LOGBACK_CONFIG_REQ_RESP_FULL_FILE, configToUse); | ||
} | ||
|
||
|
||
} |