Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuhtz committed Jul 16, 2024
1 parent 514b0cc commit 7cc8cea
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi import FastAPI
import uvicorn

from tooling.logger import logger
from tooling.logger_init import logger

from routers.configuration.operations import init_router as init_configuration_router
from routers.database.operations import init_router as init_database_router
Expand Down
3 changes: 1 addition & 2 deletions api/routers/configuration/operations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Configuration operations

# from api.tooling.logger import logger
from api.tooling.logger import logger
from api.tooling.logger_init import logger
from fastapi import APIRouter

from .get import get_config
Expand Down
2 changes: 1 addition & 1 deletion api/routers/configuration/put.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Put Configuration operation

import json
from ...tooling.logger import logger
from ...tooling.logger_init import logger
from fastapi import Request, Response, status, Query
from ..database.redis import check_conf_server

Expand Down
3 changes: 0 additions & 3 deletions api/tooling/logger.py

This file was deleted.

11 changes: 11 additions & 0 deletions api/tooling/logger_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import logging
import sys



class CustomFormatter(logging.Formatter):
"""
logging.Formatter to modify the logging format based on logging level
Expand All @@ -16,6 +18,8 @@ def format(self, record):
self._style._fmt = self.level_formats[record.levelno]
return super().format(record)



class ANSIColors:
"""ANSI escape sequences for colors to use in console text strings
"""
Expand All @@ -28,6 +32,8 @@ class ANSIColors:
cyan = '\036m'
reset = '\033[0m'



# Define custom formats for each severity level
level_formats = {
logging.DEBUG: ANSIColors.green + '%(levelname)s:' + ANSIColors.white + '\t %(asctime)s %(module)s' + ANSIColors.green + ' %(message)s' + ANSIColors.reset,
Expand All @@ -37,6 +43,8 @@ class ANSIColors:
logging.CRITICAL: ANSIColors.bold_red + '%(levelname)s:' + ANSIColors.reset + '\t %(message)s'
}



def logger_init(startup_logging_level: str = 'INFO') -> logging.Logger:
"""
Initialize logging.Logger with custom logging format based on logging severity level.
Expand All @@ -61,3 +69,6 @@ def logger_init(startup_logging_level: str = 'INFO') -> logging.Logger:

return logger



logger = logger_init() # specify 'DEBUG' if early debugging (env) is needed

0 comments on commit 7cc8cea

Please sign in to comment.