Move GUI/CLI conditional into get_plugin_logger()

It's cleaner here than in the calling plug.py code.
This commit is contained in:
Athanasius committed 2020-09-22 16:09:39 +01:00
1 parent fa326ad3d3
commit 7750bbdf4a
2 files changed
+8 -7

No files matched your search

+7 -2
View File
@@ -123,7 +123,7 @@ class Logger:
return self.logger_channel
def get_plugin_logger(name: str, loglevel: int = _default_loglevel) -> logging.Logger:
def get_plugin_logger(plugin_name: str, loglevel: int = _default_loglevel) -> logging.Logger:
"""
Return a logger suitable for a plugin.
@@ -144,7 +144,12 @@ def get_plugin_logger(name: str, loglevel: int = _default_loglevel) -> logging.L
:param loglevel: Optional logLevel for this Logger.
:return: logging.Logger instance, all set up.
"""
plugin_logger = logging.getLogger(name)
if not os.getenv('EDMC_NO_UI'):
base_logger_name = appname
else:
base_logger_name = appcmdname
plugin_logger = logging.getLogger(f'{base_logger_name}.{plugin_name}')
plugin_logger.setLevel(loglevel)
plugin_logger.addFilter(EDMCContextFilter())
+1 -5
View File
@@ -203,12 +203,8 @@ def load_plugins(master):
# Create a logger for this 'found' plugin. Must be before the
# load.py is loaded.
import EDMCLogging
if not os.getenv('EDMC_NO_UI'):
base_logger_name = appname
else:
base_logger_name = appcmdname
plugin_logger = EDMCLogging.get_plugin_logger(f'{base_logger_name}.{name}')
plugin_logger = EDMCLogging.get_plugin_logger(name)
found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py'), plugin_logger))
except Exception as e:
logger.exception(f'Failure loading found Plugin "{name}"')