Skip to content

Commit

Permalink
Enable interchangeability between SemanticLogger and AsyncLogger (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
george-zubrienko authored Feb 9, 2024
1 parent 0496879 commit 12b42be
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions adapta/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion adapta/logs/_internal_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
62 changes: 62 additions & 0 deletions adapta/logs/_logger_interface.py
Original file line number Diff line number Diff line change
@@ -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
"""

0 comments on commit 12b42be

Please sign in to comment.