From 1645a952ca18c1262ae9d23da9d5611a2e73702e Mon Sep 17 00:00:00 2001 From: Joseph Chilcote Date: Sat, 17 Nov 2018 19:03:43 -0800 Subject: [PATCH] adding logger for inclusion in templates --- pkgroot/usr/local/vfuse/bin/vfuse | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pkgroot/usr/local/vfuse/bin/vfuse b/pkgroot/usr/local/vfuse/bin/vfuse index 4cfa080..c80f2ba 100755 --- a/pkgroot/usr/local/vfuse/bin/vfuse +++ b/pkgroot/usr/local/vfuse/bin/vfuse @@ -3,7 +3,7 @@ This script takes a never-booted DMG and converts it to a VMware Fusion VM. Requirements: - OS X 10.9.5+ + OS X 10.13.6+ VMware Fusion Pro DMG created with AutoDMG ''' @@ -30,6 +30,7 @@ import argparse import glob import hashlib import json +import logging import os import plistlib import shutil @@ -771,6 +772,7 @@ def main(): serial_format = False dmg_name = '' guest_os = '' + logger_file = None if args.list_templates: templates = [] @@ -1007,6 +1009,8 @@ def main(): snapshot = d['snapshot'] if d.get('snapshot_name'): snapshot_name = d['snapshot_name'] + if d.get('logger_file'): + logger_file = d['logger_file'] mount_point, disk_id, volume_kind = mount_dmg(source_dmg) @@ -1130,6 +1134,30 @@ def main(): if os.getuid() == 0: set_perms(cache_receipt) + if logger_file: + msg_type = 'vfuse' + action = 'build' + status = 'success' + message = args.template.split('/')[-1].replace('.json', '') + + root_logger = logging.getLogger() + mylogger = logging.getLogger("vfuse_logger") + mylogger.setLevel(logging.INFO) + our_formatter = logging.Formatter( + fmt='%(asctime)s; %(message)s', + datefmt='%Y-%m-%d %H:%M:%S %z' + ) + # Set up file handler + file_handler = logging.FileHandler(logger_file) + file_handler.setLevel(logging.INFO) + file_handler.setFormatter(our_formatter) + mylogger.addHandler(file_handler) + root_logger.disabled = True + # Message must always match a certain structure + msg = 'type: {}; action: {}; status: {}; msg: {};'.format( + msg_type, action, status, message + ) + mylogger.info(msg) if __name__ == '__main__':