Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step up DEBUG logging level to avoid too much verbosity #54

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/utils/custom_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@
from src.utils import constants


def setup_logging(name: Optional[str] = None) -> logging.Logger:
class Logger(logging.Logger):
# used to avoid too much verbosity from third-party libraries
DEBUG = logging.DEBUG + 1

def __init__(self, name: str) -> None:
super().__init__(name)

@classmethod
def from_super(cls, super_instance: logging.Logger):
# Create a new instance of Logger
instance = cls(super_instance.name)
# Copy the state from the superclass instance
instance.__dict__.update(super_instance.__dict__)
return instance

def debug(self, msg: str, *args, **kwargs) -> None:
super().log(Logger.DEBUG, msg, *args, **kwargs)


def setup_logging(name: Optional[str] = None) -> Logger:
level = logging.getLevelName(constants.LOG_LEVEL)
if level == logging.DEBUG:
level = Logger.DEBUG

# If the environment variable is set to "True", we are running on Cloud Run
if constants.CLOUD_RUN.lower() == "true":
Expand All @@ -22,4 +43,6 @@ def setup_logging(name: Optional[str] = None) -> logging.Logger:
logging.basicConfig(level=level, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

logging.log(logging.INFO, "Logging initialized, LOG_LEVEL=%s(%d)", constants.LOG_LEVEL, level)
return logging.getLogger(name)

logger = logging.getLogger(name)
return Logger.from_super(logger)
Loading