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:
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:
else:
dest_path = prefs['output']
logger.debug("Outputting to {0}".format(dest_path))
- if (argparser.parse_args().embed_styles or prefs['embed-styles']) and not (argparser.parse_args.plain or prefs['plain']):
+ if (argparser.parse_args().embed_styles or prefs['embed-styles']) and not (argparser.parse_args().plain or prefs['plain']):
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':
to = argparser.parse_args().to
else:
to = prefs['mail']['to']
- if argparser.parse_args().plain or prefs['plain']:
- mail.sendmail(mailbin=prefs['mail']['mailbin'], body=(output.embed_css(prefs['css']) if isinstance(output, formatting.HtmlOutput) else output.content), recipient=to, subject=formatting.fsubject(config.prefs['mail']['subject']))
-
+ mail.sendmail(mailbin=prefs['mail']['mailbin'], body=(output.embed_css(prefs['css']) if isinstance(output, formatting.HtmlOutput) else output.content), recipient=to, subject=formatting.fsubject(config.prefs['mail']['subject']), html=isinstance(output, formatting.HtmlOutput), sender=prefs['mail']['from'])
+
# Print end message
finish = datetime.now()
logger.info("Finished parsing logs at {0} {1} (total time: {2})".format(finish.strftime(formatting.DATEFMT), finish.strftime(formatting.TIMEFMT), finish - start))