From: Alexander Schmidt Date: Tue, 6 Oct 2020 19:33:43 +0000 (+0200) Subject: added log level option X-Git-Url: http://git.treefish.org/~alex/logalert.git/commitdiff_plain/082f53238d44c1b52dc6a8110ec7dc4c56aa41df?ds=inline added log level option --- diff --git a/src/logalert.py b/src/logalert.py index e2f02cc..c8eed19 100755 --- a/src/logalert.py +++ b/src/logalert.py @@ -9,10 +9,6 @@ import misc MAX_LINES = 10 ALERT_INTERVAL = 86400 -logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', - level=logging.INFO, - datefmt='%m/%d/%Y %H:%M:%S') - parser = argparse.ArgumentParser(description='Alert on excessive number of error log lines.') parser.add_argument('logfile', type=str, help='logfile to be watched') parser.add_argument('handler', type=str, @@ -21,9 +17,15 @@ parser.add_argument('-s', '--interval-size', type=int, default=600, dest='interv help='sample interval size in seconds (default: 600)') parser.add_argument('-n', '--num-intervals', type=int, default=6, dest='num_intervals', help='number of intervals to keep in history (default: 6)') +parser.add_argument('-l', '--log-level', type=str, default='INFO', dest='log_lvl', + choices=['DEBUG', 'INFO', 'WARNING'], help='select log level') args = parser.parse_args() +logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', + level=logging.getLevelName(args.log_lvl), + datefmt='%m/%d/%Y %H:%M:%S') + kept_times = [] lines = [] last_slot_time = None