Add an --error-log option to wescamp.py,

...which writes warnings and errors to a specified file
This commit is contained in:
Alexander van Gessel 2013-02-12 01:15:48 +01:00
parent 0f9b110d02
commit 18f765246e

View file

@ -406,6 +406,9 @@ if __name__ == "__main__":
optionparser.add_option("-b", "--build-system",
help = "Path to a github.com/wescamp/build-system checkout.")
optionparser.add_option("-e", "--error-log",
help = "File to append errors and warnings to.")
options, args = optionparser.parse_args()
campaignd_configured = False
@ -425,6 +428,25 @@ if __name__ == "__main__":
format='[%(levelname)s] %(message)s',
stream=sys.stdout)
if options.error_log:
import time
formatter = logging.Formatter(fmt="[%(levelname)s %(asctime)s]\n%(message)s")
formatter.converter = time.gmtime
handler = logging.FileHandler(options.error_log)
handler.setLevel(logging.WARN)
handler.setFormatter(formatter)
record = logging.LogRecord(
name = None,
level = logging.INFO,
pathname = '',
lineno = 0,
msg = "{0}\nwescamp.py run start\n".format("="*80),
args = [],
exc_info = None,
)
handler.emit(record)
logging.getLogger().addHandler(handler)
server = "localhost"
if(options.server != None):
server = options.server