-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #548 from commercetools/log_formatter
add option to customise log formats
- Loading branch information
Showing
10 changed files
with
116 additions
and
16 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
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
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
9 changes: 9 additions & 0 deletions
9
rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/http/ErrorLogFormatter.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,9 @@ | ||
|
||
package io.vrap.rmf.base.client.http; | ||
|
||
import io.vrap.rmf.base.client.ApiHttpRequest; | ||
|
||
@FunctionalInterface | ||
public interface ErrorLogFormatter { | ||
public String format(ApiHttpRequest request, Throwable throwable, long executionTime); | ||
} |
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
23 changes: 23 additions & 0 deletions
23
rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/http/LogFormatter.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,23 @@ | ||
|
||
package io.vrap.rmf.base.client.http; | ||
|
||
import java.util.Optional; | ||
|
||
import io.vrap.rmf.base.client.ApiHttpHeaders; | ||
import io.vrap.rmf.base.client.ApiHttpRequest; | ||
import io.vrap.rmf.base.client.ApiHttpResponse; | ||
|
||
public class LogFormatter { | ||
public static String formatResponse(ApiHttpRequest request, ApiHttpResponse<byte[]> response, long executionTime) { | ||
return String | ||
.format("%s %s %s %s %s %s", request.getMethod().name(), request.getUrl(), response.getStatusCode(), | ||
executionTime, | ||
Optional.ofNullable(response.getHeaders().getFirst(ApiHttpHeaders.SERVER_TIMING)).orElse("-"), | ||
Optional.ofNullable(response.getHeaders().getFirst(ApiHttpHeaders.X_CORRELATION_ID)).orElse("-")) | ||
.trim(); | ||
} | ||
|
||
public static String formatError(ApiHttpRequest request, Throwable throwable, long executionTime) { | ||
return throwable.toString(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
rmf/rmf-java-base/src/main/java/io/vrap/rmf/base/client/http/ResponseLogFormatter.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,10 @@ | ||
|
||
package io.vrap.rmf.base.client.http; | ||
|
||
import io.vrap.rmf.base.client.ApiHttpRequest; | ||
import io.vrap.rmf.base.client.ApiHttpResponse; | ||
|
||
@FunctionalInterface | ||
public interface ResponseLogFormatter { | ||
public String format(ApiHttpRequest request, ApiHttpResponse<byte[]> response, long executionTime); | ||
} |