Skip to content

Commit

Permalink
Change logging
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-pimenta-DME committed Nov 17, 2023
1 parent f14edd4 commit e851fcc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./config.ini /code/config.ini
COPY ./app /code/app
COPY ./um-identity-api.log /code/um-identity-api.log
RUN chmod 666 /code/um-identity-api.log
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8080"]
43 changes: 37 additions & 6 deletions app/log.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
import logging

from logging.config import dictConfig
from pydantic import BaseModel

from app.configuration import config



class LogConfig(BaseModel):
"""Logging configuration to be set for the server"""

LOGGER_NAME: str = "mycoolapp"
LOG_FORMAT: str = "%(levelprefix)s | %(asctime)s | %(message)s"
level = config.get("App", "logging_level")
if not level:
level = 'INFO'
LOG_LEVEL: str = level.upper()

# Logging config
version = 1
disable_existing_loggers = False
formatters = {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": LOG_FORMAT,
"datefmt": "%Y-%m-%d %H:%M:%S",
},
}
handlers = {
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
}
loggers = {
LOGGER_NAME: {"handlers": ["default"], "level": LOG_LEVEL},
}

def get_logging_level():
level = config.get("App", "logging_level")
if not level:
Expand All @@ -22,9 +57,5 @@ def get_logging_level():
return logging.NOTSET


logger = logging.getLogger('um-identity-api')
logging_level = get_logging_level()
logger.setLevel(logging_level)
fh = logging.FileHandler('um-identity-api.log')
fh.setLevel(logging_level)
logger.addHandler(fh)
dictConfig(LogConfig().model_dump())
logger = logging.getLogger("um-identity-api")
Empty file removed um-identity-api.log
Empty file.

0 comments on commit e851fcc

Please sign in to comment.