Mercurial > p > roundup > code
comparison roundup/configuration.py @ 8452:e91ff70e4563
bug: improve error reporting for errors for logging fileConfig.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 20 Sep 2025 16:49:38 -0400 |
| parents | 401c6f0be6c5 |
| children | 588ae856cd57 6d6f689d3701 |
comparison
equal
deleted
inserted
replaced
| 8451:401c6f0be6c5 | 8452:e91ff70e4563 |
|---|---|
| 2632 | 2632 |
| 2633 def init_logging(self): | 2633 def init_logging(self): |
| 2634 _file = self["LOGGING_CONFIG"] | 2634 _file = self["LOGGING_CONFIG"] |
| 2635 if _file and os.path.isfile(_file): | 2635 if _file and os.path.isfile(_file): |
| 2636 if _file.endswith(".ini"): | 2636 if _file.endswith(".ini"): |
| 2637 logging.config.fileConfig( | 2637 try: |
| 2638 _file, | 2638 logging.config.fileConfig( |
| 2639 disable_existing_loggers=self["LOGGING_DISABLE_LOGGERS"]) | 2639 _file, |
| 2640 disable_existing_loggers=self[ | |
| 2641 "LOGGING_DISABLE_LOGGERS"]) | |
| 2642 except (ValueError, RuntimeError, | |
| 2643 KeyError, NameError, ModuleNotFoundError) as e: | |
| 2644 # configparser.DuplicateOptionError includes | |
| 2645 # filename, line number and a useful error. | |
| 2646 # so we don't have to augment it. | |
| 2647 context = [] | |
| 2648 if hasattr(e, '__context__') and e.__context__: | |
| 2649 # get additional error info. | |
| 2650 context.append(str(e.__context__)) | |
| 2651 if hasattr(e, '__doc__') and e.__doc__: | |
| 2652 context.append(e.__doc__) | |
| 2653 | |
| 2654 if isinstance(e, KeyError): | |
| 2655 context.append("No section found with this name.") | |
| 2656 if not context: | |
| 2657 context = ["No additional information available."] | |
| 2658 | |
| 2659 raise LoggingConfigError( | |
| 2660 "Error loading logging config from %(file)s.\n\n" | |
| 2661 " %(msg)s\n\n%(context)s\n" % { | |
| 2662 "file": _file, | |
| 2663 "msg": e.args[0], | |
| 2664 "context": " ".join(context), | |
| 2665 } | |
| 2666 ) | |
| 2640 elif _file.endswith(".json"): | 2667 elif _file.endswith(".json"): |
| 2641 config_dict = self.load_config_dict_from_json_file(_file) | 2668 config_dict = self.load_config_dict_from_json_file(_file) |
| 2642 try: | 2669 try: |
| 2643 logging.config.dictConfig(config_dict) | 2670 logging.config.dictConfig(config_dict) |
| 2644 except ValueError as e: | 2671 except ValueError as e: |
