From c0b01f88acd886889628deec543a46578817eb0c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 22 Sep 2020 15:35:42 +0100 Subject: [PATCH] Add get_main_logger() method to EDMCLogging.py This is so the decision on appname versus appcmdname is in one place. --- EDMCLogging.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/EDMCLogging.py b/EDMCLogging.py index 62aab91a..514a38f0 100644 --- a/EDMCLogging.py +++ b/EDMCLogging.py @@ -10,13 +10,14 @@ strings. import inspect import logging import logging.handlers +import os import pathlib import tempfile # So that any warning about accessing a protected member is only in one place. from sys import _getframe as getframe from typing import Tuple -from config import appname, config +from config import appcmdname, appname, config # TODO: Tests: # @@ -327,6 +328,17 @@ class EDMCContextFilter(logging.Filter): return module_name +def get_main_logger() -> logging.Logger: + """Return the correct logger for how the program is being run.""" + + if not os.getenv("EDMC_NO_UI"): + # GUI app being run + return logging.getLogger(appname) + else: + # Must be the CLI + return logging.getLogger(appcmdname) + + # Singleton loglevel = config.get('loglevel') if not loglevel: