From 647364c1ee45b7d19efc5ae97faff4487cf80bbc Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 13 Aug 2021 14:15:28 +0100 Subject: [PATCH] EDMC: Add --trace-on, --trace-all & use monitor.currentdir In testing `EDMC.py --trace` I ran into issues with NavRoute and ShipLocker events wanting to open the auxilary files, but it failing. This turned out to be because that code assumes `monitor.currentdir` is set and EDMC.py was using a local variable rather than setting and using it. --- EDMC.py | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/EDMC.py b/EDMC.py index b3e6d0c9..4d7a5dd8 100755 --- a/EDMC.py +++ b/EDMC.py @@ -123,10 +123,25 @@ def main(): # noqa: C901, CCR001 help='Set the logging loglevel to one of: ' 'CRITICAL, ERROR, WARNING, INFO, DEBUG, TRACE', ) - group_loglevel.add_argument('--trace', - help='Set the Debug logging loglevel to TRACE', - action='store_true', - ) + + parser.add_argument( + '--trace', + help='Set the Debug logging loglevel to TRACE', + action='store_true', + ) + + parser.add_argument( + '--trace-on', + help='Mark the selected trace logging as active. "*" or "all" is equivalent to --trace-all', + action='append', + ) + + parser.add_argument( + "--trace-all", + help='Force trace level logging, with all possible --trace-on values active.', + action='store_true' + ) + parser.add_argument('-a', metavar='FILE', help='write ship loadout to FILE in Companion API json format') parser.add_argument('-e', metavar='FILE', help='write ship loadout to FILE in E:D Shipyard plain text format') parser.add_argument('-l', metavar='FILE', help='write ship locations to FILE in CSV format') @@ -150,8 +165,18 @@ def main(): # noqa: C901, CCR001 return - if args.trace: - edmclogger.set_channels_loglevel(logging.TRACE) + level_to_set: Optional[int] = None + if args.trace or args.trace_on: + level_to_set = logging.TRACE # type: ignore # it exists + logger.info('Setting TRACE level debugging due to either --trace or a --trace-on') + + if args.trace_all or (args.trace_on and ('*' in args.trace_on or 'all' in args.trace_on)): + level_to_set = logging.TRACE_ALL # type: ignore # it exists + logger.info('Setting TRACE_ALL level debugging due to either --trace-all or a --trace-on *|all') + + if level_to_set is not None: + logger.setLevel(level_to_set) + edmclogger.set_channels_loglevel(level_to_set) elif args.loglevel: if args.loglevel not in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'TRACE'): @@ -188,15 +213,15 @@ sys.path: {sys.path}''' # Get state from latest Journal file logger.debug('Getting state from latest journal file') try: - logdir = config.get_str('journaldir', default=config.default_journal_dir) - if not logdir: - logdir = config.default_journal_dir + monitor.currentdir = config.get_str('journaldir', default=config.default_journal_dir) + if not monitor.currentdir: + monitor.currentdir = config.default_journal_dir - logger.debug(f'logdir = "{logdir}"') - logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)), + logger.debug(f'logdir = "{monitor.currentdir}"') + logfiles = sorted((x for x in os.listdir(monitor.currentdir) if JOURNAL_RE.search(x)), key=lambda x: x.split('.')[1:]) - logfile = join(logdir, logfiles[-1]) + logfile = join(monitor.currentdir, logfiles[-1]) logger.debug(f'Using logfile "{logfile}"') with open(logfile, 'r', encoding='utf-8') as loghandle: