diff --git a/adapta/logs/__init__.py b/adapta/logs/__init__.py index 5fb365b8..624d83cd 100644 --- a/adapta/logs/__init__.py +++ b/adapta/logs/__init__.py @@ -18,3 +18,4 @@ from adapta.logs._base import SemanticLogger from adapta.logs._async_logger import create_async_logger +from adapta.logs._logger_interface import LoggerInterface diff --git a/adapta/logs/_internal_logger.py b/adapta/logs/_internal_logger.py index d4821f75..8e743495 100644 --- a/adapta/logs/_internal_logger.py +++ b/adapta/logs/_internal_logger.py @@ -18,12 +18,14 @@ import logging +from abc import ABC from typing import Optional, Dict from adapta.logs._internal import MetadataLogger +from adapta.logs._logger_interface import LoggerInterface -class _InternalLogger: +class _InternalLogger(LoggerInterface, ABC): def __init__( self, fixed_template: Optional[Dict[str, Dict[str, str]]] = None, diff --git a/adapta/logs/_logger_interface.py b/adapta/logs/_logger_interface.py new file mode 100644 index 00000000..d3a78d9b --- /dev/null +++ b/adapta/logs/_logger_interface.py @@ -0,0 +1,62 @@ +""" + Marker interface for logging API +""" +from abc import ABC, abstractmethod +from typing import Optional, Dict + + +# Copyright (c) 2023-2024. ECCO Sneaks & Data +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +class LoggerInterface(ABC): + """ + Abstract logger interface, enables interchangeability between sync/async loggers + """ + + @abstractmethod + def info(self, template: str, tags: Optional[Dict[str, str]] = None, **kwargs): + """ + Logs a message on INFO level + """ + + @abstractmethod + def warning( + self, template: str, exception: Optional[BaseException] = None, tags: Optional[Dict[str, str]] = None, **kwargs + ): + """ + Logs a message on WARN level + """ + + @abstractmethod + def error( + self, template: str, exception: Optional[BaseException] = None, tags: Optional[Dict[str, str]] = None, **kwargs + ): + """ + Logs a message on ERROR level + """ + + @abstractmethod + def debug( + self, + template: str, + exception: Optional[BaseException] = None, + diagnostics: Optional[str] = None, + tags: Optional[Dict[str, str]] = None, + **kwargs + ): + """ + Logs a message on DEBUG level + """