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 <duncan.eastoe@att.com>
This commit is contained in:
Duncan Eastoe 2020-07-14 18:03:56 +01:00
parent 909a8a3fc2
commit 9c782ad2a4

View File

@ -1169,7 +1169,11 @@ if __name__ == '__main__':
group = parser.add_mutually_exclusive_group(required=True) group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--reload', action='store_true', help='Apply the deltas', default=False) 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) 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('--stdout', action='store_true', help='Log to STDOUT', default=False)
parser.add_argument('filename', help='Location of new frr config file') 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) 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 --test log to stdout
# For --reload log to /var/log/frr/frr-reload.log # For --reload log to /var/log/frr/frr-reload.log
if args.test or args.stdout: if args.test or args.stdout:
logging.basicConfig(level=logging.INFO, logging.basicConfig(format='%(asctime)s %(levelname)5s: %(message)s')
format='%(asctime)s %(levelname)5s: %(message)s')
# Color the errors and warnings in red # Color the errors and warnings in red
logging.addLevelName(logging.ERROR, "\033[91m %s\033[0m" % logging.getLevelName(logging.ERROR)) 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/') os.makedirs('/var/log/frr/')
logging.basicConfig(filename='/var/log/frr/frr-reload.log', logging.basicConfig(filename='/var/log/frr/frr-reload.log',
level=logging.INFO,
format='%(asctime)s %(levelname)5s: %(message)s') format='%(asctime)s %(levelname)5s: %(message)s')
# argparse should prevent this from happening but just to be safe... # 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') raise Exception('Must specify --reload or --test')
log = logging.getLogger(__name__) 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 # Verify the new config file is valid
if not os.path.isfile(args.filename): if not os.path.isfile(args.filename):
msg = "Filename %s does not exist" % args.filename msg = "Filename %s does not exist" % args.filename
@ -1267,9 +1274,6 @@ if __name__ == '__main__':
log.error(msg) log.error(msg)
sys.exit(1) sys.exit(1)
if args.debug:
log.setLevel(logging.DEBUG)
log.info('Called via "%s"', str(args)) log.info('Called via "%s"', str(args))
# Create a Config object from the config generated by newconf # Create a Config object from the config generated by newconf