Skip to content

Commit

Permalink
Write log to file
Browse files Browse the repository at this point in the history
  • Loading branch information
vladsavelyev committed Feb 21, 2024
1 parent b77ab1b commit 6e3a5ee
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List, Dict

import sys

from pathlib import Path

Expand Down Expand Up @@ -30,8 +29,17 @@

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Make sure logs are printed to stdout:
logger.addHandler(logging.StreamHandler(sys.stdout))
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log_path = Path(os.getenv("TMPDIR", "/tmp")) / "multiqc_api.log"
fh = logging.FileHandler(log_path)
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
logger.debug(f"Logging to {log_path}")

app = FastAPI(
title="MultiQC API",
Expand Down

0 comments on commit 6e3a5ee

Please sign in to comment.