Skip to content

Commit 8e924ee

Browse files
feat(logging): add interfaces for logging feature (#29)
This commit adds interfaces for logging features used for logging the request & response (the implementation will be either NoneSdkLogger or SdkLogger) and also an abstract of logging a particular message that would be implemented by SDK users or the default logger (i.e. ConsoleLogger in our case).
1 parent c9c22ed commit 8e924ee

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pip install apimatic-core-interfaces
2121
| [`ResponseFactory`](apimatic_core_interfaces/factories/response_factory.py) | To convert the client-adapter response into a custom HTTP response |
2222
| [`Authentication`](apimatic_core_interfaces/types/authentication.py) | To setup methods for the validation and application of the required authentication scheme |
2323
| [`UnionType`](apimatic_core_interfaces/types/union_type.py) | To setup methods for the validation and deserialization of OneOf/AnyOf union types |
24-
24+
| [`Logger`](apimatic_core_interfaces/logger/logger.py) | An interface for the generic logger facade |
25+
| [`ApiLogger`](apimatic_core_interfaces/logger/api_logger.py) | An interface for logging API requests and responses |
2526

2627
## Enumerations
2728
| Name | Description |

apimatic_core_interfaces/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
__all__ = [
22
'client',
33
'factories',
4-
'types'
4+
'types',
5+
'logger'
56
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__all__=[
2+
"api_logger",
3+
"logger"
4+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from abc import abstractmethod
2+
3+
class ApiLogger:
4+
"""An interface for logging API requests and responses.
5+
6+
This class should not be instantiated but should be used as a base class
7+
for API Logger classes."""
8+
9+
@abstractmethod
10+
def log_request(self, http_request):
11+
"""Logs the given HTTP request.
12+
13+
Args:
14+
http_request (HttpRequest): The HTTP request to log.
15+
"""
16+
...
17+
18+
@abstractmethod
19+
def log_response(self, http_response):
20+
"""Logs the given HTTP response.
21+
22+
Args:
23+
http_response (HttpRequest): The HTTP request to log.
24+
"""
25+
...
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from abc import abstractmethod
2+
3+
4+
class Logger:
5+
"""An interface for the generic logger facade.
6+
7+
This class should not be instantiated but should be used as a base class
8+
for Logger classes."""
9+
10+
@abstractmethod
11+
def log(self, level, message, params):
12+
"""Logs a message with a specified log level and additional parameters.
13+
14+
Args:
15+
level (int): The log level of the message.
16+
message (str): The message to log.
17+
params (dict): Additional parameters to include in the log message.
18+
"""
19+
...

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='apimatic-core-interfaces',
15-
version='0.1.4',
15+
version='0.1.5',
1616
description='An abstract layer of the functionalities provided by apimatic-core-library, requests-client-adapter '
1717
'and APIMatic SDKs.',
1818
long_description=long_description,

0 commit comments

Comments
 (0)