-def follow(filename):
- while True:
- try:
- with open(filename, "r") as f:
- logging.info("Re-attached to log file.")
- for line in f: pass
- while True:
- line = f.readline()
- if not line:
- if not os.path.exists(filename):
- break
- else:
- time.sleep(1.0)
- yield None
- else:
- yield line.rstrip("\n")
- except FileNotFoundError:
- time.sleep(1.0)
- yield None
-
-def feed_handler(data):
- try:
- handler = subprocess.Popen(shlex.split(args.handler),
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- encoding='UTF-8')
- out_data, err_data = handler.communicate("%s\n" % data)
- if handler.returncode != 0:
- logging.warning("Handler exited with non-zero return code %d! (%s)" %
- (handler.returncode, err_data))
- except Exception as e:
- logging.error("Error feeding handler: %s" % str(e))
-
-def create_msg(title, icon, logfile, text, lines):
- msg = "<b>%s</b> <i>%s</i> %s" % (title, logfile, icon)
- msg += "<br>%s" % text
- msg += "<br><pre>"
- for line in lines: msg += line + "\n"
- msg += "</pre>"
- return msg
-
-logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s',
- level=logging.INFO,
- datefmt='%m/%d/%Y %H:%M:%S')
-