Skip to content

Commit

Permalink
feat(logging): add support for structured logging (#56)
Browse files Browse the repository at this point in the history
adds interfaces for structured logging
  • Loading branch information
hamzamahmood authored Apr 23, 2024
1 parent 5c989eb commit f69e3cb
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 207 deletions.
91 changes: 55 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,83 @@
# APIMatic JAVA Core Library Interfaces

[![Maven Central][maven-badge]][maven-url]
[![Tests][test-badge]][test-url]
[![Lint Code][lint-badge]][lint-url]
[![Maintainability][maintainability-url]][code-climate-url]
[![Licence][license-badge]][license-url]

## Introduction
This project contains the abstract layer for APIMatic's core library and Apimatic's JAVA SDK.

This project contains the abstract layer for APIMatic's core library and Apimatic's JAVA SDK.

## Prerequisites

* The JRE flavor requires `JDK 1.8`.

## Install the maven package

Core Interfaces's Maven group ID is `io.apimatic`, and its artifact ID is `core-interfaces`.

## Interfaces
| Name | Description |
|-------------------------------------------------------------------------|--------------------------------------------------------------------|
| [`Context`](./src/main/java/io/apimatic/coreinterfaces/http/Context.java) | To save both Request and Response after the completion of response |
| [`Callback`](./src/main/java/io/apimatic/coreinterfaces/http/Callback.java) | To perform action before Request and after the completion of response |
| [`HttpClient`](./src/main/java/io/apimatic/coreinterfaces/http/HttpClient.java) | To provide abstraction to execute API call in HttpClient |
| [`HttpHeaders`](./src/main/java/io/apimatic/coreinterfaces/http/HttpHeaders.java) | To save additional information about the request and response |
| [`ClientConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/ClientConfiguration.java) | To hold the default configurations for HttpClient |
| [`Authentication`](./src/main/java/io/apimatic/coreinterfaces/authentication/Authentication.java) | To Provide abstraction for all Authentications |
| [`Request`](./src/main/java/io/apimatic/coreinterfaces/http/request/Request.java) | To create and manage HTTP Requests |
| [`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 |
| [`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 |
| [`CoreEndpointConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/CoreEndpointConfiguration.java) | To Provide endpoint level configuration |
| [`Response`](./src/main/java/io/apimatic/coreinterfaces/http/response/Response.java) | To get the properties from the instance of Response |
| [`DynamicType`](./src/main/java/io/apimatic/coreinterfaces/http/response/DynamicType.java) | To get the properties from the instance of Dynamic Response Type |
| [`ApiResponseType`](./src/main/java/io/apimatic/coreinterfaces/http/response/ApiResponseType.java) | To get the properties from the instance of ApiResponseType |
| [`CompatibilityFactory`](./src/main/java/io/apimatic/coreinterfaces/compatibility\CompatibilityFactory.java) | Holds required converter methods to create SDK classes |
| [`CoreFileWrapper`](./src/main/java/io/apimatic/coreinterfaces/type/CoreFileWrapper.java) | To wrap file and contentType to be sent as part of a HTTP request. |
| [`HttpApiException`](./src/main/java/io/apimatic/coreinterfaces/type/HttpApiException.java) | Default interface for all the exception models in SDK |
| [`ApiLogger`](./src/main/java/io/apimatic/coreinterfaces/logger/ApiLogger.java) | To log the useful information or errors |
| [`ReadonlyLogging`](./src/main/java/io/apimatic/coreinterfaces/logger/ReadonlyLogging.java) | To hold logging configuration |
| [`Deserializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Deserializer.java) | Functional interface to apply the deserialization function |
| [`ExceptionCreator`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ExceptionCreator.java) | Functional interface to create the SDK exception |
| [`Serializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Serializer.java) | Functional interface to apply the serialization function |
| [`ContextInitializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ContextInitializer.java) | Functional Interface to apply the context initialization function for the response models |

| Name | Description |
|-------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| [`Context`](./src/main/java/io/apimatic/coreinterfaces/http/Context.java) | To save both Request and Response after the completion of response |
| [`Callback`](./src/main/java/io/apimatic/coreinterfaces/http/Callback.java) | To perform action before Request and after the completion of response |
| [`HttpClient`](./src/main/java/io/apimatic/coreinterfaces/http/HttpClient.java) | To provide abstraction to execute API call in HttpClient |
| [`HttpHeaders`](./src/main/java/io/apimatic/coreinterfaces/http/HttpHeaders.java) | To save additional information about the request and response |
| [`ClientConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/ClientConfiguration.java) | To hold the default configurations for HttpClient |
| [`Authentication`](./src/main/java/io/apimatic/coreinterfaces/authentication/Authentication.java) | To Provide abstraction for all Authentications |
| [`Request`](./src/main/java/io/apimatic/coreinterfaces/http/request/Request.java) | To create and manage HTTP Requests |
| [`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 |
| [`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 |
| [`CoreEndpointConfiguration`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/CoreEndpointConfiguration.java) | To Provide endpoint level configuration |
| [`Response`](./src/main/java/io/apimatic/coreinterfaces/http/response/Response.java) | To get the properties from the instance of Response |
| [`DynamicType`](./src/main/java/io/apimatic/coreinterfaces/http/response/DynamicType.java) | To get the properties from the instance of Dynamic Response Type |
| [`ApiResponseType`](./src/main/java/io/apimatic/coreinterfaces/http/response/ApiResponseType.java) | To get the properties from the instance of ApiResponseType |
| [`CompatibilityFactory`](./src/main/java/io/apimatic/coreinterfaces/compatibility/CompatibilityFactory.java) | Holds required converter methods to create SDK classes |
| [`CoreFileWrapper`](./src/main/java/io/apimatic/coreinterfaces/type/CoreFileWrapper.java) | To wrap file and contentType to be sent as part of a HTTP request. |
| [`HttpApiException`](./src/main/java/io/apimatic/coreinterfaces/type/HttpApiException.java) | Default interface for all the exception models in SDK |
| [`ApiLogger`](./src/main/java/io/apimatic/coreinterfaces/logger/ApiLogger.java) | Interface for Loggin Api Calls. |
| [`Logger`](./src/main/java/io/apimatic/coreinterfaces/logger/Logger.java) | Interface for logging at different levels. |
| [`LoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/LoggingConfiguration.java) | To hold logging configuration |
| [`HttpLoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/HttpLoggingConfiguration.java) | To hold configuration for http logging |
| [`RequestLoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/RequestLoggingConfiguration.java) | To hold Request configuration for logging |
| [`ResponseLoggingConfiguration`](./src/main/java/io/apimatic/coreinterfaces/logger/configuration/ResponseLoggingConfiguration.java) | To hold Response configuration for logging |
| [`Deserializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Deserializer.java) | Functional interface to apply the deserialization function |
| [`ExceptionCreator`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ExceptionCreator.java) | Functional interface to create the SDK exception |
| [`Serializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/Serializer.java) | Functional interface to apply the serialization function |
| [`ContextInitializer`](./src/main/java/io/apimatic/coreinterfaces/type/functional/ContextInitializer.java) | Functional Interface to apply the context initialization function for the response models |

## Enumerations
| Name | Description |
|-------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [`Method`](./src/main/java/io/apimatic/coreinterfaces/http/Method.java) | Enumeration for all possible types of requests |
| [`HttpMethodType`](./src/main/java/io/apimatic/coreinterfaces/http/HttpMethodType.java) | HTTP methods enumeration. |
| [`RetryOption`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/RetryOption.java) | Enumeration for RetryingOption of each API call |
| [`ArraySerializationFormat`](./src/main/java/io/apimatic/coreinterfaces/http/request/ArraySerializationFormat.java) | Enumeration for all ArraySerialization formats |
| [`MutliPartRequestType`](./src/main/java/io/apimatic/coreinterfaces/http/request/MutliPartRequestType.java) | Enumeration for multipart request |
| [`ResponseClassType`](./src/main/java/io/apimatic/coreinterfaces/http/request/ResponseClassType.java) | Enumeration for Response class type |
| [`HeaderLoggingPolicyLevel`](./src/main/java/io/apimatic/coreinterfaces/http/HeaderLoggingPolicyLevel.java) | Enumeration of Header Logging ploicy |
| [`LoggingLevel`](./src/main/java/io/apimatic/coreinterfaces/http/LoggingLevel.java) | Enumeration of all the possible Logging Level |
| [`LoggingLevelType`](./src/main/java/io/apimatic/coreinterfaces/http/LoggingLevelType.java) | Enumeration of Logging Level |

| Name | Description |
|---------------------------------------------------------------------------------------------------------------------|-------------------------------------------------|
| [`Method`](./src/main/java/io/apimatic/coreinterfaces/http/Method.java) | Enumeration for all possible types of requests |
| [`HttpMethodType`](./src/main/java/io/apimatic/coreinterfaces/http/HttpMethodType.java) | HTTP methods enumeration. |
| [`RetryOption`](./src/main/java/io/apimatic/coreinterfaces/http/request/configuration/RetryOption.java) | Enumeration for RetryingOption of each API call |
| [`ArraySerializationFormat`](./src/main/java/io/apimatic/coreinterfaces/http/request/ArraySerializationFormat.java) | Enumeration for all ArraySerialization formats |
| [`MutliPartRequestType`](./src/main/java/io/apimatic/coreinterfaces/http/request/MutliPartRequestType.java) | Enumeration for multipart request |
| [`ResponseClassType`](./src/main/java/io/apimatic/coreinterfaces/http/request/ResponseClassType.java) | Enumeration for Response class type |
| [`HeaderLoggingPolicyLevel`](./src/main/java/io/apimatic/coreinterfaces/http/HeaderLoggingPolicyLevel.java) | Enumeration of Header Logging ploicy |

[license-badge]: https://img.shields.io/badge/licence-MIT-blue

[license-url]: LICENSE

[maven-badge]: https://img.shields.io/maven-central/v/io.apimatic/core-interfaces?color=green

[maven-url]: https://central.sonatype.dev/artifact/io.apimatic/core-interfaces/0.1.1

[test-badge]: https://github.com/apimatic/core-interfaces-java/actions/workflows/build-and-test.yml/badge.svg

[test-url]: https://github.com/apimatic/core-interfaces-java/actions/workflows/build-and-test.yml

[code-climate-url]: https://codeclimate.com/github/apimatic/core-interfaces-java

[maintainability-url]: https://api.codeclimate.com/v1/badges/71332f9af318d309c3dc/maintainability

[lint-badge]: https://github.com/apimatic/core-interfaces-java/actions/workflows/linter.yml/badge.svg

[lint-url]: https://github.com/apimatic/core-interfaces-java/actions/workflows/linter.yml

5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.10</version>
</dependency>
</dependencies>

<build>
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/io/apimatic/coreinterfaces/http/LoggingLevel.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public interface Request {
*/
String getUrl(ArraySerializationFormat arraySerializationFormat);

/**
* Get the request URL without query parameters
* @return String Url
*/
String getUrl();

/**
* Parameters for the http request.
* @return List of simple entries for form parameters
Expand All @@ -60,5 +66,4 @@ public interface Request {
* @return Object body
*/
Object getBody();

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.apimatic.coreinterfaces.http.request.configuration;

import io.apimatic.coreinterfaces.http.request.ArraySerializationFormat;

/**
* The configuration for an endpoint.
*/
Expand All @@ -18,10 +16,4 @@ public interface CoreEndpointConfiguration {
* @return the boolean which tells endpoint has binary response or not
*/
boolean hasBinaryResponse();

/**
* Enumeration for all ArraySerialization formats
* @return the array serialization format
*/
ArraySerializationFormat getArraySerializationFormat();
}
30 changes: 2 additions & 28 deletions src/main/java/io/apimatic/coreinterfaces/logger/ApiLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,12 @@ public interface ApiLogger {
/**
* Log requests.
* @param request HttpRequest to be logged.
* @param url String request URL.
*/
void logRequest(Request request, String url);

/**
* Log requests.
* @param request HttpRequest to be logged.
* @param url String request URL.
* @param additionalMessage Any additional message to be logged.
*/
void logRequest(Request request, String url, String additionalMessage);

/**
* Set error for failed requests.
* @param request HttpRequest that failed.
* @param error Throwable occurred.
*/
void setError(Request request, Throwable error);
void logRequest(Request request);

/**
* Log Responses.
* @param request HttpRequest that completed.
* @param response HttpResponse to be logged.
*/
void logResponse(Request request, Response response);

/**
* Log Responses.
* @param request HttpRequest that completed.
* @param response HttpResponse to be logged.
* @param additionalMessage Any additional message to be logged.
*/
void logResponse(Request request, Response response, String additionalMessage);

void logResponse(Response response);
}
27 changes: 27 additions & 0 deletions src/main/java/io/apimatic/coreinterfaces/logger/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.apimatic.coreinterfaces.logger;

import java.util.Map;

import org.slf4j.event.Level;

/**
* Interface representing an object capable of logging messages at different
* levels.
*/
public interface Logger {

/**
* Return instance of the provided slf4j logger instance.
* @return wrapped instance of SLF4J Logger.
*/
org.slf4j.Logger getLogger();

/**
* Logs a message with the specified logging level, format, and arguments.
*
* @param level the logging level of the message
* @param format a format string for the message
* @param arguments arguments referenced by the format string
*/
void log(Level level, String format, Map<String, Object> arguments);
}
Loading

0 comments on commit f69e3cb

Please sign in to comment.