Skip to content

Commit

Permalink
fix for logging in h5tojson
Browse files Browse the repository at this point in the history
  • Loading branch information
jreadey committed Feb 24, 2015
1 parent 5ebe49b commit 21ace92
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions util/h5tojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import sys
import json
import argparse
import os.path as op
import os

import logging
import logging.handlers

Expand All @@ -25,9 +28,14 @@
"""

class DumpJson:
def __init__(self, db, options=None):
def __init__(self, db, app_logger=None, options=None):
self.options = options
self.db = db
if app_logger:
self.log = app_logger
else:
print "default logger"
self.log = logging.getLogger()
self.json = {}

def dumpAttribute(self, col_name, uuid, attr_name):
Expand All @@ -37,7 +45,10 @@ def dumpAttribute(self, col_name, uuid, attr_name):
response['type'] = hdf5dtype.getTypeResponse(typeItem)
response['shape'] = item['shape']
if not self.options.D:
response['value'] = item['value'] # dump values unless header -D was passed
if 'value' not in item:
self.log.warning("no value key in attribute: " + attr_name)
else:
response['value'] = item['value'] # dump values unless header -D was passed
return response


Expand Down Expand Up @@ -178,17 +189,23 @@ def main():

# create logger
log = logging.getLogger("h5serv")
log.setLevel(logging.INFO)
log.setLevel(logging.WARN)
# set daily rotating log
handler = logging.FileHandler('./h5tojson.log')

# add handler to logger
log.addHandler(handler)
log.info("h5tojson " + args.filename[0])

filename = args.filename[0]
if not op.isfile(filename):
print "Cannot find file:", filename
sys.exit()

log.info("h5tojson " + filename)


with Hdf5db(args.filename[0], readonly=True) as db:
dumper = DumpJson(db, options=args)
with Hdf5db(filename, readonly=True, app_logger=log) as db:
dumper = DumpJson(db, app_logger=log, options=args)
dumper.dumpFile()


Expand Down

0 comments on commit 21ace92

Please sign in to comment.