dcs-retribution/qt_ui/logging_config.py
Dan Albert 6bfb8cf2fd Fix double logging.
Calling logging.basicConfig creates a stream handler for the root
logger, and then we were adding our own with a different formatter.
Pass the format string to basicConfig so we don't need to add our own
duplicate stream handler.
2020-10-06 23:31:40 -07:00

23 lines
632 B
Python

"""Logging APIs."""
import logging
import os
from logging.handlers import RotatingFileHandler
def init_logging(version: str) -> None:
"""Initializes the logging configuration."""
if not os.path.isdir("./logs"):
os.mkdir("logs")
fmt = "%(asctime)s :: %(levelname)s :: %(message)s"
logging.basicConfig(level=logging.DEBUG, format=fmt)
logger = logging.getLogger()
handler = RotatingFileHandler('./logs/liberation.log', 'a', 5000000, 1)
handler.setLevel(logging.INFO)
handler.setFormatter(logging.Formatter(fmt))
logger.addHandler(handler)
logger.info(f"DCS Liberation {version}")