-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
+
"""
This module is the entrypoint of the `logparse` shell command and also contains
single-use functions which don't fit elsewhere. All user interaction with
- `rotate_sim()`: Simulate log rotation
"""
-import logging, logging.handlers
import argparse
+from copy import copy
+import logging
+import logging.handlers
import os
from sys import stdin, version
from subprocess import check_output
from datetime import datetime
import logparse
-from logparse import formatting, mail, config, load_parsers
+from logparse import formatting, mail, config, load_parsers, util
def main():
argparser.parse_args().time_period)
# Set up logging
-
logger = logging.getLogger(__name__)
- loghandler = logging.handlers.SysLogHandler(address = '/dev/log')
- loghandler.setFormatter(logging.Formatter(
- fmt='logparse[' + str(os.getpid()) + ']: %(message)s'))
- loghandler.setLevel(logging.INFO) # don't spam syslog with debug messages
-
if (argparser.parse_args().quiet
or config.prefs.getboolean("logparse", "quiet")):
- logging.basicConfig(level=logging.CRITICAL)
+ logparse.logger.setLevel(logging.CRITICAL)
elif (argparser.parse_args().verbose
or config.prefs.getboolean("logparse", "verbose")):
- logging.basicConfig(level=logging.DEBUG)
+ logparse.logger.setLevel(logging.DEBUG)
logger.debug("Verbose mode turned on")
else:
- logging.basicConfig(level=logging.INFO)
+ logparse.logger.setLevel(logging.INFO)
+
- logger.addHandler(loghandler)
# Time analysis