Skip to content

Commit

Permalink
tehepero
Browse files Browse the repository at this point in the history
  • Loading branch information
backpaper0 committed Jun 23, 2024
1 parent ee7165d commit 9b665dd
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 150 deletions.
9 changes: 5 additions & 4 deletions accesslog-standard-output-example/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'
<project
xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'
xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -15,8 +16,8 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<groupId>ch.qos.logback.access</groupId>
<artifactId>tomcat</artifactId>
</dependency>

<dependency>
Expand All @@ -35,4 +36,4 @@
</plugins>
</build>

</project>
</project>
177 changes: 89 additions & 88 deletions custom-logging/pom.xml
Original file line number Diff line number Diff line change
@@ -1,92 +1,93 @@
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'
xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>spring-boot-sandbox-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>custom-logging</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-jdbc</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
</dependency>
<project
xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd'
xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>spring-boot-sandbox-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>custom-logging</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-jdbc</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback.access</groupId>
<artifactId>tomcat</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import java.util.concurrent.TimeUnit;

import ch.qos.logback.access.pattern.AccessConverter;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.access.common.pattern.AccessConverter;
import ch.qos.logback.access.common.spi.IAccessEvent;
import jakarta.servlet.http.HttpServletRequest;

public class ElapsedTimeConverter extends AccessConverter {

public static final String REQUEST_ATTRIBUTE_NAME = ElapsedTimeConverter.class.getName();
public static final String REQUEST_ATTRIBUTE_NAME = ElapsedTimeConverter.class.getName();

@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof Long) {
long totalRoundTripTime = TimeUnit.NANOSECONDS.toMillis((Long) value);
return Long.toString(event.getElapsedTime() - totalRoundTripTime);
}
}
return Long.toString(event.getElapsedTime());
}
@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof Long) {
long totalRoundTripTime = TimeUnit.NANOSECONDS.toMillis((Long) value);
return Long.toString(event.getElapsedTime() - totalRoundTripTime);
}
}
return Long.toString(event.getElapsedTime());
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.example.common.accesslog;

import ch.qos.logback.access.pattern.AccessConverter;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.access.common.pattern.AccessConverter;
import ch.qos.logback.access.common.spi.IAccessEvent;
import jakarta.servlet.http.HttpServletRequest;

public class KeepingNameConverter extends AccessConverter {

static final String REQUEST_ATTRIBUTE_NAME = KeepingNameConverter.class.getName();
static final String REQUEST_ATTRIBUTE_NAME = KeepingNameConverter.class.getName();

@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof String) {
return (String) value;
}
}
return IAccessEvent.NA;
}
@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof String) {
return (String) value;
}
}
return IAccessEvent.NA;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.example.common.accesslog;

import ch.qos.logback.access.pattern.AccessConverter;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.access.common.pattern.AccessConverter;
import ch.qos.logback.access.common.spi.IAccessEvent;
import jakarta.servlet.http.HttpServletRequest;

public class SessionIdConverter extends AccessConverter {

static final String REQUEST_ATTRIBUTE_NAME = SessionIdConverter.class.getName();
static final String REQUEST_ATTRIBUTE_NAME = SessionIdConverter.class.getName();

@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof String) {
return (String) value;
}
}
return IAccessEvent.NA;
}
@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof String) {
return (String) value;
}
}
return IAccessEvent.NA;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.example.common.accesslog;

import ch.qos.logback.access.pattern.AccessConverter;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.access.common.pattern.AccessConverter;
import ch.qos.logback.access.common.spi.IAccessEvent;
import jakarta.servlet.http.HttpServletRequest;

public class UserNameConverter extends AccessConverter {

static final String REQUEST_ATTRIBUTE_NAME = UserNameConverter.class.getName();
static final String REQUEST_ATTRIBUTE_NAME = UserNameConverter.class.getName();

@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof String) {
return (String) value;
}
}
return IAccessEvent.NA;
}
@Override
public String convert(IAccessEvent event) {
HttpServletRequest request = event.getRequest();
if (request != null) {
Object value = request.getAttribute(REQUEST_ATTRIBUTE_NAME);
if (value instanceof String) {
return (String) value;
}
}
return IAccessEvent.NA;
}
}
6 changes: 6 additions & 0 deletions generate-parent-pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func main() {
<mybatis-spring-boot-starter.version>3.0.3</mybatis-spring-boot-starter.version>
<mybatis-generator-maven-plugin.version>1.4.2</mybatis-generator-maven-plugin.version>
<greenmail.version>2.1.0-alpha-2</greenmail.version>
<logback-access.version>2.0.1</logback-access.version>
<argLine>-Duser.language=ja -Duser.country=JP -Duser.timezone=Asia/Tokyo</argLine>
</properties>
<modules>{{range .Dirs}}
Expand Down Expand Up @@ -134,6 +135,11 @@ func main() {
<artifactId>greenmail-junit5</artifactId>
<version>${greenmail.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback.access</groupId>
<artifactId>tomcat</artifactId>
<version>${logback-access.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down
Loading

0 comments on commit 9b665dd

Please sign in to comment.