From 9c782ad2a4e5106d25946a07adf97805302faf38 Mon Sep 17 00:00:00 2001 From: Duncan Eastoe Date: Tue, 14 Jul 2020 18:03:56 +0100 Subject: [PATCH] tools: frr-reload: more detailed log level control Add a "--log-level" option to frr-reload to set the maximum message level to be logged. When the option is not used, the level is set to info as before. The existing --debug option is synonymous with --log-level=debug and these options are therefore mutually exclusive. Signed-off-by: Duncan Eastoe --- tools/frr-reload.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 9e86cf2156..772a9bc88d 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -1169,7 +1169,11 @@ if __name__ == '__main__': group = parser.add_mutually_exclusive_group(required=True) group.add_argument('--reload', action='store_true', help='Apply the deltas', default=False) group.add_argument('--test', action='store_true', help='Show the deltas', default=False) - parser.add_argument('--debug', action='store_true', help='Enable debugs', default=False) + level_group = parser.add_mutually_exclusive_group() + level_group.add_argument('--debug', action='store_true', + help='Enable debugs (synonym for --log-level=debug)', default=False) + level_group.add_argument('--log-level', help='Log level', default="info", + choices=("critical", "error", "warning", "info", "debug")) parser.add_argument('--stdout', action='store_true', help='Log to STDOUT', default=False) parser.add_argument('filename', help='Location of new frr config file') parser.add_argument('--overwrite', action='store_true', help='Overwrite frr.conf with running config output', default=False) @@ -1185,8 +1189,7 @@ if __name__ == '__main__': # For --test log to stdout # For --reload log to /var/log/frr/frr-reload.log if args.test or args.stdout: - logging.basicConfig(level=logging.INFO, - format='%(asctime)s %(levelname)5s: %(message)s') + logging.basicConfig(format='%(asctime)s %(levelname)5s: %(message)s') # Color the errors and warnings in red logging.addLevelName(logging.ERROR, "\033[91m %s\033[0m" % logging.getLevelName(logging.ERROR)) @@ -1197,7 +1200,6 @@ if __name__ == '__main__': os.makedirs('/var/log/frr/') logging.basicConfig(filename='/var/log/frr/frr-reload.log', - level=logging.INFO, format='%(asctime)s %(levelname)5s: %(message)s') # argparse should prevent this from happening but just to be safe... @@ -1205,6 +1207,11 @@ if __name__ == '__main__': raise Exception('Must specify --reload or --test') log = logging.getLogger(__name__) + if args.debug: + log.setLevel(logging.DEBUG) + else: + log.setLevel(args.log_level.upper()) + # Verify the new config file is valid if not os.path.isfile(args.filename): msg = "Filename %s does not exist" % args.filename @@ -1267,9 +1274,6 @@ if __name__ == '__main__': log.error(msg) sys.exit(1) - if args.debug: - log.setLevel(logging.DEBUG) - log.info('Called via "%s"', str(args)) # Create a Config object from the config generated by newconf