[NO-ISSUE] Add column

This commit is contained in:
woozu-shin 2023-10-10 19:27:51 +09:00
parent 8d078ebb10
commit f4ffd2ec4e
4 changed files with 46 additions and 38 deletions

View File

@ -1,8 +1,7 @@
## `LoggingTestAPIController.java` ## `LoggingTestAPIController.java`
### logging test - get w/ body ### logging test - get w/ body
```shell ```shell
curl -X GET 'http://localhost:20090/api/v1/loggingTest/getWithBody' \ curl -X GET 'http://localhost:20090/api/v1/loggingTest/getWithBody' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
@ -15,19 +14,19 @@ curl -X GET 'http://localhost:20090/api/v1/loggingTest/getWithBody' \
``` ```
### logging test - get w/ param ### logging test - get w/ param
```shell ```shell
curl http://localhost:20090/api/v1/loggingTest/get?p1=v1&p2=v2 curl http://localhost:20090/api/v1/loggingTest/get?p1=v1&p2=v2
``` ```
### logging test - post w/o body, w/ error ### logging test - post w/o body, w/ error
```shell ```shell
curl -X POST 'http://localhost:20090/api/v1/loggingTest/postWithBody' curl -X POST 'http://localhost:20090/api/v1/loggingTest/postWithBody'
``` ```
### logging test - post w/ body ### logging test - post w/ body
```shell ```shell
curl -X POST 'http://localhost:20090/api/v1/loggingTest/postWithBody' \ curl -X POST 'http://localhost:20090/api/v1/loggingTest/postWithBody' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
@ -38,63 +37,68 @@ curl -X POST 'http://localhost:20090/api/v1/loggingTest/postWithBody' \
}' }'
``` ```
# Appendix # Appendix
## schema.sql for other dbms ## schema.sql for other dbms
### mysql ### mysql
```mysql ```mysql
create table request_log create table request_log
( (
id bigint auto_increment primary key, id bigint auto_increment primary key,
http_method varchar(255), application_name varchar(64),
uri varchar(255), http_method varchar(255),
query_string varchar(2047), uri varchar(255),
content_type varchar(255), query_string varchar(2047),
body mediumtext, content_type varchar(255),
requested_at timestamp(6), body mediumtext,
trace_id varchar(40), requested_at timestamp(6),
created_at timestamp(6), trace_id varchar(40),
created_at timestamp(6),
primary key (id) primary key (id)
); );
create table response_log create table response_log
( (
id bigint auto_increment primary key, id bigint auto_increment primary key,
http_status integer, application_name varchar(64),
content_type varchar(255), http_status integer,
body mediumtext, content_type varchar(255),
responded_at timestamp(6), body mediumtext,
trace_id varchar(40), responded_at timestamp(6),
created_at timestamp(6), trace_id varchar(40),
created_at timestamp(6),
primary key (id) primary key (id)
); );
``` ```
### postgresql ### postgresql
```postgresql ```postgresql
create table request_log create table request_log
( (
id bigint generated by default as identity primary key, id bigint generated by default as identity primary key,
http_method varchar(255), application_name varchar(64),
uri varchar(255), http_method varchar(255),
query_string varchar(255), uri varchar(255),
content_type varchar(255), query_string varchar(255),
body text, content_type varchar(255),
requested_at timestamp(6) with time zone, body text,
trace_id varchar(40), requested_at timestamp(6) with time zone,
created_at timestamp(6) with time zone trace_id varchar(40),
created_at timestamp(6) with time zone
); );
create table response_log create table response_log
( (
id bigint generated by default as identity primary key, id bigint generated by default as identity primary key,
http_status integer, application_name varchar(64),
content_type varchar(255), http_status integer,
body text, content_type varchar(255),
responded_at timestamp(6) with time zone, body text,
trace_id varchar(40), responded_at timestamp(6) with time zone,
created_at timestamp(6) with time zone trace_id varchar(40),
created_at timestamp(6) with time zone
); );
``` ```

View File

@ -37,6 +37,7 @@ public class LoggingInterceptor implements HandlerInterceptor {
.body(getBodyIfAvailable(request)) .body(getBodyIfAvailable(request))
.requestedAt(Instant.now()) .requestedAt(Instant.now())
.traceId(MDC.get("traceId")) .traceId(MDC.get("traceId"))
.applicationName("myoa-engineering-logging-sample")
.build(); .build();
loggingRequest(requestLog); loggingRequest(requestLog);
logPersistenceService.save(requestLog); logPersistenceService.save(requestLog);
@ -82,6 +83,7 @@ public class LoggingInterceptor implements HandlerInterceptor {
.body(getBodyIfAvailable(response)) .body(getBodyIfAvailable(response))
.respondedAt(Instant.now()) .respondedAt(Instant.now())
.traceId(MDC.get("traceId")) .traceId(MDC.get("traceId"))
.applicationName("myoa-engineering-logging-sample")
.build(); .build();
loggingResponse(responseLog); loggingResponse(responseLog);
logPersistenceService.save(responseLog); logPersistenceService.save(responseLog);

View File

@ -18,6 +18,7 @@ public class RequestLog extends Auditable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
private String applicationName;
private String httpMethod; private String httpMethod;
private String uri; private String uri;
private String queryString; private String queryString;

View File

@ -18,6 +18,7 @@ public class ResponseLog extends Auditable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
private String applicationName;
private Integer httpStatus; private Integer httpStatus;
private String contentType; private String contentType;
private String body; private String body;