Skip to content

Commit

Permalink
adding logger for inclusion in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
chilcote committed Nov 18, 2018
1 parent 6888a1a commit 1645a95
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion pkgroot/usr/local/vfuse/bin/vfuse
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand All @@ -30,6 +30,7 @@ import argparse
import glob
import hashlib
import json
import logging
import os
import plistlib
import shutil
Expand Down Expand Up @@ -771,6 +772,7 @@ def main():
serial_format = False
dmg_name = ''
guest_os = ''
logger_file = None

if args.list_templates:
templates = []
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit 1645a95

Please sign in to comment.