Compare commits

..

No commits in common. "master" and "0.1.1" have entirely different histories.

4 changed files with 42 additions and 58 deletions

View File

@ -12,15 +12,16 @@ communication into one log entry.
## Old bad Logger ## Old bad Logger
All parts are separated from each other: All parts are separeted from each other:
1) Request: 1) Request:
1) request headers - every header is put into separated entry 1) request headers - every header is put into separated entry
2) request body - at separated entry 2) requst body - at separated entry
2) Response: 2) Response:
1) response headers - separately 1) response headers - separately
2) response body - at separated entry as well 2) response body - at separated entry as well
``` ```
2022-07-25 14:12:43.572 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] ---> POST https://example.com/api/v1/login HTTP/1.1 2022-07-25 14:12:43.572 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] ---> POST https://example.com/api/v1/login HTTP/1.1
2022-07-25 14:12:43.573 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] Content-Length: 23 2022-07-25 14:12:43.573 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] Content-Length: 23
2022-07-25 14:12:43.573 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] Content-Type: application/json 2022-07-25 14:12:43.573 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] Content-Type: application/json
@ -46,6 +47,7 @@ All parts are separated from each other:
2022-07-25 14:12:43.901 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] 2022-07-25 14:12:43.901 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login]
2022-07-25 14:12:43.902 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] {"status":{"code":"OK","message":"OK"},"body":{"id":"20826"}} 2022-07-25 14:12:43.902 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] {"status":{"code":"OK","message":"OK"},"body":{"id":"20826"}}
2022-07-25 14:12:43.902 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] <--- END HTTP (61-byte body) 2022-07-25 14:12:43.902 DEBUG 1032530 --- [Executor] feign.Logger : [AuthApi#login] <--- END HTTP (61-byte body)
``` ```
## New Normalized Logger ## New Normalized Logger
@ -53,7 +55,8 @@ All parts are separated from each other:
The whole communication (request and response parts) is combined into one log entry. The whole communication (request and response parts) is combined into one log entry.
``` ```
2022-07-25 14:16:06.217 INFO 1057053 --- [Executor] me.bvn13.openfeign.logger.NormalizedFeignLogger : normalized feign request {AuthApi#login(LoginRequestDto)=[AuthApi#login] }: [
2022-07-25 14:16:06.217 INFO 1057053 --- [Executor] com.pf.profee.api.NormalizedFeignLogger : normalized feign request {AuthApi#login(LoginRequestDto)=[AuthApi#login] }: [
---> POST https://example.com/api/v1/login HTTP/1.1 ---> POST https://example.com/api/v1/login HTTP/1.1
Content-Length: 23 Content-Length: 23
Content-Type: application/json Content-Type: application/json
@ -72,7 +75,7 @@ expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi
feature-policy: accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment *; usb 'none' feature-policy: accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment *; usb 'none'
referrer-policy: strict-origin-when-cross-origin referrer-policy: strict-origin-when-cross-origin
server: cloudflare server: cloudflare
set-cookie: ACCESS_TOKEN=eyJhboft6rzD6Be16dXY5lgQNCzOZNFe4ra_NDIdmXlXi19hlvaQ; Max-Age=1800; Domain=.example.com; Path=/; Secure; SameSite=None set-cookie: QA_JWT_ACCESS_TOKEN=eyJhboft6rzD6Be16dXY5lgQNCzOZNFe4ra_NDIdmXlXi19hlvaQ; Max-Age=1800; Domain=.example.com; Path=/; Secure; SameSite=None
strict-transport-security: max-age=31536000 strict-transport-security: max-age=31536000
x-content-type-options: nosniff x-content-type-options: nosniff
x-frame-options: sameorigin x-frame-options: sameorigin
@ -81,11 +84,12 @@ x-xss-protection: 1; mode=block
{"status":{"code":"OK","message":"OK"},"body":{"id":"20826"}} {"status":{"code":"OK","message":"OK"},"body":{"id":"20826"}}
<--- END HTTP (61-byte body) <--- END HTTP (61-byte body)
] ]
``` ```
# How to use # How to use
In order to use Normalized Logger into the application they must the following. In order to user Normalized Logger into the application they must the following.
## 0) Check the latest version ## 0) Check the latest version
@ -99,17 +103,17 @@ for Maven
<dependency> <dependency>
<groupId>me.bvn13.openfeign.logger</groupId> <groupId>me.bvn13.openfeign.logger</groupId>
<artifactId>feign-normalized-logger</artifactId> <artifactId>feign-normalized-logger</artifactId>
<version>0.1.4</version> <version>0.1.0</version>
</dependency> </dependency>
``` ```
for Gradle for Gradle
```groovy ```groovy
implementation 'me.bvn13.openfeign.logger:feign-normalized-logger:0.1.4' implementation 'me.bvn13.openfeign.logger:feign-normalized-logger:0.1.0'
``` ```
## 2) Create Feign configuration and enable logger + specify FULL logging level ## 2) Create Feign configuration and enable logger
```java ```java
import feign.Logger; import feign.Logger;
@ -121,11 +125,6 @@ public class MyFeignConfig {
return new NormalizedFeignLogger(); return new NormalizedFeignLogger();
} }
@Bean
public Logger.Level logLevel() {
return Logger.Level.FULL;
}
} }
``` ```
@ -138,12 +137,12 @@ public interface AuthApi {
} }
``` ```
### 4) Adjust INFO level for Normalized Logger ### 4) Adjust DEBUG level for Normalized Logger
for Slf4J + Logback for Slf4J + Logback
```yaml ```yaml
logging: logging:
level: level:
me.bvn13.openfeign.logger.NormalizedFeignLogger: INFO me.bvn13.openfeign.logger.NormalizedFeignLogger: DEBUG
``` ```

View File

@ -7,7 +7,7 @@
<groupId>me.bvn13.openfeign.logger</groupId> <groupId>me.bvn13.openfeign.logger</groupId>
<artifactId>feign-normalized-logger</artifactId> <artifactId>feign-normalized-logger</artifactId>
<version>0.1.5-SNAPSHOT</version> <version>0.1.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -1,15 +0,0 @@
#!/bin/bash
./mvnw gitflow:release-start gitflow:release-finish
git push origin master
git push --tags
git push origin develop
read -p "Which version to publish? > " version
git checkout $version
./mvnw deploy -Prelease

View File

@ -95,7 +95,7 @@ public class NormalizedFeignLogger extends feign.Logger {
} }
private void showLogs(String configKey) { private void showLogs(String configKey) {
log.info("Normalized feign request " + methodName.get() + ": [\n" + log.debug("normalized feign request " + methodName.get() + ": [\n" +
collectionToDelimitedString(logsRequest.get().getOrDefault(configKey, Collections.emptyList()), "\n") + collectionToDelimitedString(logsRequest.get().getOrDefault(configKey, Collections.emptyList()), "\n") +
"\n] has response [\n" + "\n] has response [\n" +
collectionToDelimitedString(logsResponse.get().getOrDefault(configKey, Collections.emptyList()), "\n") + collectionToDelimitedString(logsResponse.get().getOrDefault(configKey, Collections.emptyList()), "\n") +