Skip to content

Commit f69e3cb

Browse files
authored
feat(logging): add support for structured logging (#56)
adds interfaces for structured logging
1 parent 5c989eb commit f69e3cb

13 files changed

Lines changed: 187 additions & 207 deletions

README.md

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,83 @@
11
# APIMatic JAVA Core Library Interfaces
2+
23
[![Maven Central][maven-badge]][maven-url]
34
[![Tests][test-badge]][test-url]
45
[![Lint Code][lint-badge]][lint-url]
56
[![Maintainability][maintainability-url]][code-climate-url]
67
[![Licence][license-badge]][license-url]
8+
79
## Introduction
8-
This project contains the abstract layer for APIMatic's core library and Apimatic's JAVA SDK.
10+
11+
This project contains the abstract layer for APIMatic's core library and Apimatic's JAVA SDK.
912

1013
## Prerequisites
14+
1115
* The JRE flavor requires `JDK 1.8`.
16+
1217
## Install the maven package
18+
1319
Core Interfaces's Maven group ID is `io.apimatic`, and its artifact ID is `core-interfaces`.
1420

1521
## Interfaces
16-
| Name | Description |
17-
|-------------------------------------------------------------------------|--------------------------------------------------------------------|
18-
| [`Context`](./src/main/java/io/apimatic/coreinterfaces/http/Context.java) | To save both Request and Response after the completion of response |
19-
| [`Callback`](./src/main/java/io/apimatic/coreinterfaces/http/Callback.java) | To perform action before Request and after the completion of response |
20-
| [`HttpClient`](./src/main/java/io/apimatic/coreinterfaces/http/HttpClient.java) | To provide abstraction to execute API call in HttpClient |
21-
| [`HttpHeaders`](./src/main/java/io/apimatic/coreinterfaces/http/HttpHeaders.java) | To save additional information about the request and response |
22-
| [`ClientConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/ClientConfiguration.java) | To hold the default configurations for HttpClient |
23-
| [`Authentication`](./src/main/java/io/apimatic/coreinterfaces/authentication/Authentication.java) | To Provide abstraction for all Authentications |
24-
| [`Request`](./src/main/java/io/apimatic/coreinterfaces/http/request/Request.java) | To create and manage HTTP Requests |
25-
| [`Multipart`](./src/main/java/io/apimatic/coreinterfaces/http/request/Multipart.java) | To wrap byteArray and headers to be sent as part of a multipart request |
26-
| [`MultipartFile`](./src/main/java/io/apimatic/coreinterfaces/http/request/MultipartFile.java) | To wrap file and headers to be sent as part of a multipart request |
27-
| [`CoreEndpointConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/CoreEndpointConfiguration.java) | To Provide endpoint level configuration |
28-
| [`Response`](./src/main/java/io/apimatic/coreinterfaces/http/response/Response.java) | To get the properties from the instance of Response |
29-
| [`DynamicType`](./src/main/java/io/apimatic/coreinterfaces/http/response/DynamicType.java) | To get the properties from the instance of Dynamic Response Type |
30-
| [`ApiResponseType`](./src/main/java/io/apimatic/coreinterfaces/http/response/ApiResponseType.java) | To get the properties from the instance of ApiResponseType |
31-
| [`CompatibilityFactory`](./src/main/java/io/apimatic/coreinterfaces/compatibility\CompatibilityFactory.java) | Holds required converter methods to create SDK classes |
32-
| [`CoreFileWrapper`](./src/main/java/io/apimatic/coreinterfaces/type/CoreFileWrapper.java) | To wrap file and contentType to be sent as part of a HTTP request. |
33-
| [`HttpApiException`](./src/main/java/io/apimatic/coreinterfaces/type/HttpApiException.java) | Default interface for all the exception models in SDK |
34-
| [`ApiLogger`](./src/main/java/io/apimatic/coreinterfaces/logger/ApiLogger.java) | To log the useful information or errors |
35-
| [`ReadonlyLogging`](./src/main/java/io/apimatic/coreinterfaces/logger/ReadonlyLogging.java) | To hold logging configuration |
36-
| [`Deserializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Deserializer.java) | Functional interface to apply the deserialization function |
37-
| [`ExceptionCreator`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ExceptionCreator.java) | Functional interface to create the SDK exception |
38-
| [`Serializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Serializer.java) | Functional interface to apply the serialization function |
39-
| [`ContextInitializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ContextInitializer.java) | Functional Interface to apply the context initialization function for the response models |
22+
23+
| Name | Description |
24+
|-------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
25+
| [`Context`](./src/main/java/io/apimatic/coreinterfaces/http/Context.java) | To save both Request and Response after the completion of response |
26+
| [`Callback`](./src/main/java/io/apimatic/coreinterfaces/http/Callback.java) | To perform action before Request and after the completion of response |
27+
| [`HttpClient`](./src/main/java/io/apimatic/coreinterfaces/http/HttpClient.java) | To provide abstraction to execute API call in HttpClient |
28+
| [`HttpHeaders`](./src/main/java/io/apimatic/coreinterfaces/http/HttpHeaders.java) | To save additional information about the request and response |
29+
| [`ClientConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/ClientConfiguration.java) | To hold the default configurations for HttpClient |
30+
| [`Authentication`](./src/main/java/io/apimatic/coreinterfaces/authentication/Authentication.java) | To Provide abstraction for all Authentications |
31+
| [`Request`](./src/main/java/io/apimatic/coreinterfaces/http/request/Request.java) | To create and manage HTTP Requests |
32+
| [`Multipart`](./src/main/java/io/apimatic/coreinterfaces/http/request/Multipart.java) | To wrap byteArray and headers to be sent as part of a multipart request |
33+
| [`MultipartFile`](./src/main/java/io/apimatic/coreinterfaces/http/request/MultipartFile.java) | To wrap file and headers to be sent as part of a multipart request |
34+
| [`CoreEndpointConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/CoreEndpointConfiguration.java) | To Provide endpoint level configuration |
35+
| [`Response`](./src/main/java/io/apimatic/coreinterfaces/http/response/Response.java) | To get the properties from the instance of Response |
36+
| [`DynamicType`](./src/main/java/io/apimatic/coreinterfaces/http/response/DynamicType.java) | To get the properties from the instance of Dynamic Response Type |
37+
| [`ApiResponseType`](./src/main/java/io/apimatic/coreinterfaces/http/response/ApiResponseType.java) | To get the properties from the instance of ApiResponseType |
38+
| [`CompatibilityFactory`](./src/main/java/io/apimatic/coreinterfaces/compatibility/CompatibilityFactory.java) | Holds required converter methods to create SDK classes |
39+
| [`CoreFileWrapper`](./src/main/java/io/apimatic/coreinterfaces/type/CoreFileWrapper.java) | To wrap file and contentType to be sent as part of a HTTP request. |
40+
| [`HttpApiException`](./src/main/java/io/apimatic/coreinterfaces/type/HttpApiException.java) | Default interface for all the exception models in SDK |
41+
| [`ApiLogger`](./src/main/java/io/apimatic/coreinterfaces/logger/ApiLogger.java) | Interface for Loggin Api Calls. |
42+
| [`Logger`](./src/main/java/io/apimatic/coreinterfaces/logger/Logger.java) | Interface for logging at different levels. |
43+
| [`LoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/LoggingConfiguration.java) | To hold logging configuration |
44+
| [`HttpLoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/HttpLoggingConfiguration.java) | To hold configuration for http logging |
45+
| [`RequestLoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/RequestLoggingConfiguration.java) | To hold Request configuration for logging |
46+
| [`ResponseLoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/ResponseLoggingConfiguration.java) | To hold Response configuration for logging |
47+
| [`Deserializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Deserializer.java) | Functional interface to apply the deserialization function |
48+
| [`ExceptionCreator`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ExceptionCreator.java) | Functional interface to create the SDK exception |
49+
| [`Serializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Serializer.java) | Functional interface to apply the serialization function |
50+
| [`ContextInitializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ContextInitializer.java) | Functional Interface to apply the context initialization function for the response models |
4051

4152
## Enumerations
42-
| Name | Description |
43-
|-------------------------------------------------------------------------------|-----------------------------------------------------------------|
44-
| [`Method`](./src/main/java/io/apimatic/coreinterfaces/http/Method.java) | Enumeration for all possible types of requests |
45-
| [`HttpMethodType`](./src/main/java/io/apimatic/coreinterfaces/http/HttpMethodType.java) | HTTP methods enumeration. |
46-
| [`RetryOption`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/RetryOption.java) | Enumeration for RetryingOption of each API call |
47-
| [`ArraySerializationFormat`](./src/main/java/io/apimatic/coreinterfaces/http/request/ArraySerializationFormat.java) | Enumeration for all ArraySerialization formats |
48-
| [`MutliPartRequestType`](./src/main/java/io/apimatic/coreinterfaces/http/request/MutliPartRequestType.java) | Enumeration for multipart request |
49-
| [`ResponseClassType`](./src/main/java/io/apimatic/coreinterfaces/http/request/ResponseClassType.java) | Enumeration for Response class type |
50-
| [`HeaderLoggingPolicyLevel`](./src/main/java/io/apimatic/coreinterfaces/http/HeaderLoggingPolicyLevel.java) | Enumeration of Header Logging ploicy |
51-
| [`LoggingLevel`](./src/main/java/io/apimatic/coreinterfaces/http/LoggingLevel.java) | Enumeration of all the possible Logging Level |
52-
| [`LoggingLevelType`](./src/main/java/io/apimatic/coreinterfaces/http/LoggingLevelType.java) | Enumeration of Logging Level |
53+
54+
| Name | Description |
55+
|---------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
56+
| [`Method`](./src/main/java/io/apimatic/coreinterfaces/http/Method.java) | Enumeration for all possible types of requests |
57+
| [`HttpMethodType`](./src/main/java/io/apimatic/coreinterfaces/http/HttpMethodType.java) | HTTP methods enumeration. |
58+
| [`RetryOption`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/RetryOption.java) | Enumeration for RetryingOption of each API call |
59+
| [`ArraySerializationFormat`](./src/main/java/io/apimatic/coreinterfaces/http/request/ArraySerializationFormat.java) | Enumeration for all ArraySerialization formats |
60+
| [`MutliPartRequestType`](./src/main/java/io/apimatic/coreinterfaces/http/request/MutliPartRequestType.java) | Enumeration for multipart request |
61+
| [`ResponseClassType`](./src/main/java/io/apimatic/coreinterfaces/http/request/ResponseClassType.java) | Enumeration for Response class type |
62+
| [`HeaderLoggingPolicyLevel`](./src/main/java/io/apimatic/coreinterfaces/http/HeaderLoggingPolicyLevel.java) | Enumeration of Header Logging ploicy |
5363

5464
[license-badge]: https://img.shields.io/badge/licence-MIT-blue
65+
5566
[license-url]: LICENSE
67+
5668
[maven-badge]: https://img.shields.io/maven-central/v/io.apimatic/core-interfaces?color=green
69+
5770
[maven-url]: https://central.sonatype.dev/artifact/io.apimatic/core-interfaces/0.1.1
71+
5872
[test-badge]: https://github.com/apimatic/core-interfaces-java/actions/workflows/build-and-test.yml/badge.svg
73+
5974
[test-url]: https://github.com/apimatic/core-interfaces-java/actions/workflows/build-and-test.yml
75+
6076
[code-climate-url]: https://codeclimate.com/github/apimatic/core-interfaces-java
77+
6178
[maintainability-url]: https://api.codeclimate.com/v1/badges/71332f9af318d309c3dc/maintainability
79+
6280
[lint-badge]: https://github.com/apimatic/core-interfaces-java/actions/workflows/linter.yml/badge.svg
81+
6382
[lint-url]: https://github.com/apimatic/core-interfaces-java/actions/workflows/linter.yml
6483

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
<artifactId>okhttp</artifactId>
5252
<version>4.10.0</version>
5353
</dependency>
54+
<dependency>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>slf4j-api</artifactId>
57+
<version>2.0.10</version>
58+
</dependency>
5459
</dependencies>
5560

5661
<build>

src/main/java/io/apimatic/coreinterfaces/http/LoggingLevel.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/java/io/apimatic/coreinterfaces/http/LoggingLevelType.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/main/java/io/apimatic/coreinterfaces/http/request/Request.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public interface Request {
3636
*/
3737
String getUrl(ArraySerializationFormat arraySerializationFormat);
3838

39+
/**
40+
* Get the request URL without query parameters
41+
* @return String Url
42+
*/
43+
String getUrl();
44+
3945
/**
4046
* Parameters for the http request.
4147
* @return List of simple entries for form parameters
@@ -60,5 +66,4 @@ public interface Request {
6066
* @return Object body
6167
*/
6268
Object getBody();
63-
6469
}

src/main/java/io/apimatic/coreinterfaces/http/request/configuration/CoreEndpointConfiguration.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.apimatic.coreinterfaces.http.request.configuration;
22

3-
import io.apimatic.coreinterfaces.http.request.ArraySerializationFormat;
4-
53
/**
64
* The configuration for an endpoint.
75
*/
@@ -18,10 +16,4 @@ public interface CoreEndpointConfiguration {
1816
* @return the boolean which tells endpoint has binary response or not
1917
*/
2018
boolean hasBinaryResponse();
21-
22-
/**
23-
* Enumeration for all ArraySerialization formats
24-
* @return the array serialization format
25-
*/
26-
ArraySerializationFormat getArraySerializationFormat();
2719
}

src/main/java/io/apimatic/coreinterfaces/logger/ApiLogger.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,12 @@ public interface ApiLogger {
1111
/**
1212
* Log requests.
1313
* @param request HttpRequest to be logged.
14-
* @param url String request URL.
1514
*/
16-
void logRequest(Request request, String url);
17-
18-
/**
19-
* Log requests.
20-
* @param request HttpRequest to be logged.
21-
* @param url String request URL.
22-
* @param additionalMessage Any additional message to be logged.
23-
*/
24-
void logRequest(Request request, String url, String additionalMessage);
25-
26-
/**
27-
* Set error for failed requests.
28-
* @param request HttpRequest that failed.
29-
* @param error Throwable occurred.
30-
*/
31-
void setError(Request request, Throwable error);
15+
void logRequest(Request request);
3216

3317
/**
3418
* Log Responses.
35-
* @param request HttpRequest that completed.
3619
* @param response HttpResponse to be logged.
3720
*/
38-
void logResponse(Request request, Response response);
39-
40-
/**
41-
* Log Responses.
42-
* @param request HttpRequest that completed.
43-
* @param response HttpResponse to be logged.
44-
* @param additionalMessage Any additional message to be logged.
45-
*/
46-
void logResponse(Request request, Response response, String additionalMessage);
47-
21+
void logResponse(Response response);
4822
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.apimatic.coreinterfaces.logger;
2+
3+
import java.util.Map;
4+
5+
import org.slf4j.event.Level;
6+
7+
/**
8+
* Interface representing an object capable of logging messages at different
9+
* levels.
10+
*/
11+
public interface Logger {
12+
13+
/**
14+
* Return instance of the provided slf4j logger instance.
15+
* @return wrapped instance of SLF4J Logger.
16+
*/
17+
org.slf4j.Logger getLogger();
18+
19+
/**
20+
* Logs a message with the specified logging level, format, and arguments.
21+
*
22+
* @param level the logging level of the message
23+
* @param format a format string for the message
24+
* @param arguments arguments referenced by the format string
25+
*/
26+
void log(Level level, String format, Map<String, Object> arguments);
27+
}

0 commit comments

Comments
 (0)