From 68db0a5c00f4b9b54121a461b50e9180ef1548de Mon Sep 17 00:00:00 2001 From: nfsec Date: Wed, 12 Jul 2017 21:58:43 +0200 Subject: [PATCH] Barachiel v0.3 - Logger --- barachiel | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/barachiel b/barachiel index 2424ce6..d4e6814 100755 --- a/barachiel +++ b/barachiel @@ -15,6 +15,7 @@ # ----------------- import os, re, sys, argparse +import logging, logging.handlers from getpass import getpass from fabric.api import * from fabric.colors import * @@ -256,10 +257,18 @@ def sudo_put_command(putthis, failok): abort("Aborting at user request.") print(yellow("||| Done.") + "\n") +def logger(logfile): + """Basic logging and file rotate.""" + if os.path.isfile(logfile): + size = os.path.getsize(logfile) + if size >= 104857600: + logging.handlers.RotatingFileHandler(filename=logfile, backupCount=10).doRollover() + logging.basicConfig(filename=logfile, format='%(asctime)s : %(levelname)-9s : %(message)s', level=logging.DEBUG) def main(): """Main logic.""" try: + logger('barachiel.log') args = parse_arguments() env.skip_bad_hosts = True env.colorize_errors = True