Skip to content

Commit

Permalink
Use stdout for logging instead of file
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed Feb 27, 2024
1 parent 52f1575 commit 722138c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ TAG := 3.3
APP_NAME := basegun
REG := ghcr.io
ORG := datalab-mi
UVICORN_LOG_LEVEL := # info, debug, trace

export

Expand Down
17 changes: 3 additions & 14 deletions backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import sys
import logging
import os
import time
from datetime import datetime
from logging.handlers import TimedRotatingFileHandler
from contextlib import asynccontextmanager
from typing import Union
from uuid import uuid4
Expand All @@ -30,28 +30,17 @@

CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))


def setup_logs(log_dir: str) -> logging.Logger:
"""Setups environment for logs
Args:
log_dir (str): folder for log storage
logging.Logger: logger object
"""
print(">>> Reload logs config")
# clear previous logs
os.makedirs(log_dir, exist_ok=True)
for f in os.listdir(log_dir):
os.remove(os.path.join(log_dir, f))
# configure new logs
formatter = GelfFormatter()
logger = logging.getLogger("Basegun")
# new log file at midnight
log_file = os.path.join(log_dir, "log.json")
handler = TimedRotatingFileHandler(
log_file, when="midnight", interval=1, backupCount=7
)
logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ services:
- AWS_SECRET_ACCESS_KEY=minioadmin
- http_proxy
- https_proxy
- UVICORN_LOG_LEVEL=${UVICORN_LOG_LEVEL}
- LOG_LEVEL=${UVICORN_LOG_LEVEL}
- no_proxy
- WORKSPACE=dev
- REQUESTS_CA_BUNDLE=$CACERT_LOCATION
Expand Down

0 comments on commit 722138c

Please sign in to comment.