From: Andrew Lorimer Date: Fri, 30 Aug 2019 12:58:30 +0000 (+1000) Subject: bugfixing in config & add quiet mode X-Git-Url: https://git.lorimer.id.au/logparse.git/diff_plain/1542324ac8be481a0108927bb023568a37a5fa7c?ds=sidebyside bugfixing in config & add quiet mode --- diff --git a/logparse/config.py b/logparse/config.py index c7455bd..8b7d798 100644 --- a/logparse/config.py +++ b/logparse/config.py @@ -55,8 +55,9 @@ defaults = Configuration({ 'subject': 'logparse from $hostname$', 'mailbin': '/usr/bin/mail', }, - 'rotate': 'n', - 'verbose': 'n', + 'rotate': False, + 'verbose': False, + 'quiet': False, 'hddtemp': { 'drives': ['/dev/sda'], 'host': '127.0.0.1', @@ -79,7 +80,7 @@ defaults = Configuration({ }, 'du': { 'paths': ['/', '/etc', '/home'], - 'force-write': 'n', + 'force-write': False, }, 'hostname-path': '/etc/hostname', 'parsers': {}, diff --git a/logparse/formatting.py b/logparse/formatting.py index b303449..ab6266e 100644 --- a/logparse/formatting.py +++ b/logparse/formatting.py @@ -325,7 +325,7 @@ class Table(object): def draw_plain(self): output = tabulate(self._gen_list(), self.headers, tablefmt="fancy_grid" if self.borders else "plain", colalign=tuple(self._align_cols)) - return output + return output + "\n"*2 class Table0(object): diff --git a/logparse/interface.py b/logparse/interface.py index 3c2b1a2..c37ec9a 100644 --- a/logparse/interface.py +++ b/logparse/interface.py @@ -46,7 +46,8 @@ def main(): argparser.add_argument('-l', '--logs', help='services to analyse', required=False) argparser.add_argument('-nl', '--ignore-logs', help='skip these services (takes precedence over -l)', required=False) argparser.add_argument('-es', '--embed-styles', help='make CSS rules inline rather than linking the file', required=False, default=False, action='store_true') - argparser.add_argument('-nh', '--plain', help='write/send plain text rather than HTML', required = False, default=False, action='store_true') + argparser.add_argument('-nh', '--plain', help='write/send plain text rather than HTML', required=False, default=False, action='store_true') + argparser.add_argument('-q', '--quiet', help='no output to stdout', required=False, default=False, action='store_true') # Load config if argparser.parse_args().config: @@ -59,8 +60,10 @@ def main(): logger = logging.getLogger(__name__) loghandler = logging.handlers.SysLogHandler(address = '/dev/log') loghandler.setFormatter(logging.Formatter(fmt='logparse.py[' + str(os.getpid()) + ']: %(message)s')) - loghandler.setLevel(logging.WARNING) # don't spam syslog with debug messages - if argparser.parse_args().verbose or (config.prefs['verbose'] == 'y' or config.prefs['verbose'] == 'yes'): + loghandler.setLevel(logging.INFO) # don't spam syslog with debug messages + if argparser.parse_args().quiet or config.prefs['quiet']: + logging.basicConfig(level=logging.CRITICAL) + elif argparser.parse_args().verbose or config.prefs['verbose']: logging.basicConfig(level=logging.DEBUG) logger.debug("Verbose mode turned on") else: @@ -139,6 +142,8 @@ def main(): output.embed_css(prefs['css']) if (not os.path.isfile(dest_path)) and not (argparser.parse_args().overwrite or config['overwrite']): output.write(dest_path) + elif logging.root.level == logging.CRITICAL: + pass else: logger.warning("Destination file already exists") if input("Would you like to overwrite {0}? (y/n) [n] ".format(dest_path)) == 'y': diff --git a/logparse/parsers/cron-journald.py b/logparse/parsers/cron-journald.py index 9df7e2b..b085aea 100644 --- a/logparse/parsers/cron-journald.py +++ b/logparse/parsers/cron-journald.py @@ -51,7 +51,7 @@ def parse_log(): for usr, cmdlist in users.items(): user_data = Data() - user_data.subtitle = plural("cron sessions", len(cmdlist)) + " for " + usr + user_data.subtitle = plural("cron session", len(cmdlist)) + " for " + usr user_data.items = ("`{0}`".format(cmd) for cmd in cmdlist) user_data.orderbyfreq() user_data.truncl(config.prefs['maxcmd']) diff --git a/logparse/parsers/temperature.py b/logparse/parsers/temperature.py index 9d08119..d1d4058 100644 --- a/logparse/parsers/temperature.py +++ b/logparse/parsers/temperature.py @@ -110,7 +110,7 @@ def parse_log(): section.append_data(temp_data) finally: - logger.info("Finished reading onboard temperatures") + logger.debug("Finished reading onboard temperatures") sensors.cleanup() @@ -141,7 +141,7 @@ def parse_log(): logger.debug("Sum of temperatures: {}; Number of drives: {}; => Avg disk temp is {}".format(str(sumtemp), str(len(drives)), hddavg)) hddtemp_data.subtitle += " (avg {0}{1}{2})".format(str(hddavg), DEG, CEL) - logger.info("Finished processing drive temperatures") - + logger.debug("Finished processing drive temperatures") logger.info("Finished temp section") + return section