Skip to content

Commit

Permalink
feat(logging): add interfaces for logging feature (#29)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
sufyankhanrao authored May 10, 2024
1 parent c9c22ed commit 8e924ee
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pip install apimatic-core-interfaces
| [`ResponseFactory`](apimatic_core_interfaces/factories/response_factory.py) | To convert the client-adapter response into a custom HTTP response |
| [`Authentication`](apimatic_core_interfaces/types/authentication.py) | To setup methods for the validation and application of the required authentication scheme |
| [`UnionType`](apimatic_core_interfaces/types/union_type.py) | To setup methods for the validation and deserialization of OneOf/AnyOf union types |

| [`Logger`](apimatic_core_interfaces/logger/logger.py) | An interface for the generic logger facade |
| [`ApiLogger`](apimatic_core_interfaces/logger/api_logger.py) | An interface for logging API requests and responses |

## Enumerations
| Name | Description |
Expand Down
3 changes: 2 additions & 1 deletion apimatic_core_interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__all__ = [
'client',
'factories',
'types'
'types',
'logger'
]
4 changes: 4 additions & 0 deletions apimatic_core_interfaces/logger/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__all__=[
"api_logger",
"logger"
]
25 changes: 25 additions & 0 deletions apimatic_core_interfaces/logger/api_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from abc import abstractmethod

class ApiLogger:
"""An interface for logging API requests and responses.
This class should not be instantiated but should be used as a base class
for API Logger classes."""

@abstractmethod
def log_request(self, http_request):
"""Logs the given HTTP request.
Args:
http_request (HttpRequest): The HTTP request to log.
"""
...

@abstractmethod
def log_response(self, http_response):
"""Logs the given HTTP response.
Args:
http_response (HttpRequest): The HTTP request to log.
"""
...
19 changes: 19 additions & 0 deletions apimatic_core_interfaces/logger/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from abc import abstractmethod


class Logger:
"""An interface for the generic logger facade.
This class should not be instantiated but should be used as a base class
for Logger classes."""

@abstractmethod
def log(self, level, message, params):
"""Logs a message with a specified log level and additional parameters.
Args:
level (int): The log level of the message.
message (str): The message to log.
params (dict): Additional parameters to include in the log message.
"""
...
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='apimatic-core-interfaces',
version='0.1.4',
version='0.1.5',
description='An abstract layer of the functionalities provided by apimatic-core-library, requests-client-adapter '
'and APIMatic SDKs.',
long_description=long_description,
Expand Down

0 comments on commit 8e924ee

Please sign in to comment.