dcs_liberation/game/logging_config.py
Dan Albert 99ea06c0d5 Fix file encoding for some loads.
We've actually been pretty good at getting this right in most of the
code base, but we've missed it in a few places. Python defaults to the
encoding of the current locale unless otherwise specified, and for a US
English Windows install that's cp1252, not UTF-8. I'm not brave enough
to change the locale at startup because I don't know how that might
affect CJK encoding users (or for that matter, non-Latin derived
alphabet UTF-8 variants).

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/2786.
2023-04-15 13:27:08 -07:00

23 lines
613 B
Python

"""Logging APIs."""
import logging
import logging.config
import os
from pathlib import Path
import yaml
def init_logging(version: str) -> None:
"""Initializes the logging configuration."""
if not os.path.isdir("./logs"):
os.mkdir("logs")
resources = Path("resources")
log_config = resources / "default_logging.yaml"
if (custom_log_config := resources / "logging.yaml").exists():
log_config = custom_log_config
with log_config.open(encoding="utf-8") as log_file:
logging.config.dictConfig(yaml.safe_load(log_file))
logging.info(f"DCS Liberation {version}")