Skip to content

Commit

Permalink
Merge pull request #1444 from missionpinball/improve_error_links
Browse files Browse the repository at this point in the history
only use device class in url. not the name
  • Loading branch information
jabdoa2 committed Oct 13, 2019
2 parents 40d7908 + 23967b1 commit fe7853a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mpf/core/device.py
Expand Up @@ -114,7 +114,7 @@ def _configure_device_logging(self, config):

self.configure_logging(self.class_label + '.' + self.name,
config['console_log'],
config['file_log'])
config['file_log'], url_base=self.class_label)

self.debug_log("Configuring device with settings: '%s'", config)

Expand Down
11 changes: 8 additions & 3 deletions mpf/core/logging.py
Expand Up @@ -15,7 +15,7 @@ class LogMixin:

unit_test = False

__slots__ = ["log", "_info_to_console", "_debug_to_console", "_info_to_file", "_debug_to_file"]
__slots__ = ["log", "_info_to_console", "_debug_to_console", "_info_to_file", "_debug_to_file", "_url_base"]

def __init__(self) -> None:
"""Initialise Log Mixin."""
Expand All @@ -24,6 +24,7 @@ def __init__(self) -> None:
self._debug_to_console = False
self._info_to_file = False
self._debug_to_file = False
self._url_base = None

logging.addLevelName(21, "INFO")
logging.addLevelName(11, "DEBUG")
Expand All @@ -39,7 +40,7 @@ def _debug(self):
return self._debug_to_console or self._debug_to_file

def configure_logging(self, logger: str, console_level: str = 'basic',
file_level: str = 'basic'):
file_level: str = 'basic', url_base=None):
"""Configure logging.
Args:
Expand All @@ -49,6 +50,10 @@ def configure_logging(self, logger: str, console_level: str = 'basic',
file_level: The level of logging for the console. Valid options
are "none", "basic", or "full".
"""
if url_base:
self._url_base = url_base
else:
self._url_base = logger
self.log = logging.getLogger(logger)
if hasattr(self, "machine") and self.machine and self.machine.options['production']:
return
Expand Down Expand Up @@ -157,7 +162,7 @@ def format_log_line(self, msg, context, error_no) -> str:

def raise_config_error(self, msg, error_no, *, context=None):
"""Raise a ConfigFileError exception."""
raise ConfigFileError(msg, error_no, self.log.name, context)
raise ConfigFileError(msg, error_no, self.log.name, context, self._url_base)

def ignorable_runtime_exception(self, msg: str) -> None:
"""Handle ignorable runtime exception.
Expand Down
9 changes: 7 additions & 2 deletions mpf/exceptions/config_file_error.py
Expand Up @@ -6,16 +6,21 @@ class ConfigFileError(AssertionError):

"""Error in a config file found."""

def __init__(self, message, error_no, logger_name, context=None):
# pylint: disable-msg=too-many-arguments
def __init__(self, message, error_no, logger_name, context=None, url_name=None):
"""Initialise exception."""
self._logger_name = logger_name
self._error_no = error_no
self._context = context
if url_name:
self._url_name = url_name
else:
self._url_name = logger_name
super().__init__(message)

def __str__(self):
"""Return nice string."""
error_slug = "CFE-{}-{}".format(self._logger_name, self._error_no)
error_slug = "CFE-{}-{}".format(self._url_name, self._error_no)
error_url = log_url.format(error_slug)
if self._context:
return "Config File Error in {}: {} Context: {} Error Code: {} ({})".format(
Expand Down

0 comments on commit fe7853a

Please sign in to comment.