From 3441ca75831644597ca830e89862eb3d6d5b9d15 Mon Sep 17 00:00:00 2001 From: "Ryan P. Kelly" Date: Fri, 4 Mar 2016 07:51:59 -0500 Subject: [PATCH 1/2] let users of the module to determine their logging configuration --- tzwhere/tzwhere.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tzwhere/tzwhere.py b/tzwhere/tzwhere.py index 9e4fd18..8bb0259 100755 --- a/tzwhere/tzwhere.py +++ b/tzwhere/tzwhere.py @@ -36,8 +36,6 @@ class are instantiated and queried directly, but the module can be run except ImportError: WRAP = tuple -LOGGER_FORMAT = '%(asctime)-15s %(filename)s %(funcName)s %(lineno)d %(levelname)s %(message)s' -logging.basicConfig(format=LOGGER_FORMAT, level=logging.DEBUG) LOGGER = logging.getLogger('pytzwhere') @@ -357,6 +355,10 @@ def _feature_collection_polygons(featureCollection): def main(): + + LOGGER_FORMAT = '%(asctime)-15s %(filename)s %(funcName)s %(lineno)d %(levelname)s %(message)s' + logging.basicConfig(format=LOGGER_FORMAT, level=logging.DEBUG) + try: import docopt except ImportError: From 40765e3dbad79be8209186a44ae692eeffd84f52 Mon Sep 17 00:00:00 2001 From: "Ryan P. Kelly" Date: Fri, 4 Mar 2016 12:09:45 -0500 Subject: [PATCH 2/2] and use the logger we requested instead of logging on the root --- tzwhere/tzwhere.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tzwhere/tzwhere.py b/tzwhere/tzwhere.py index 8bb0259..dfdf567 100755 --- a/tzwhere/tzwhere.py +++ b/tzwhere/tzwhere.py @@ -259,7 +259,7 @@ def read_tzworld(input_kind='json', path=None): def read_json(path=None): if path is None: path = tzwhere.DEFAULT_JSON - logging.info('Reading json input file: %s\n' % path) + LOGGER.info('Reading json input file: %s\n' % path) with open(path, 'r') as f: featureCollection = json.load(f) return featureCollection @@ -268,14 +268,14 @@ def read_json(path=None): def read_pickle(path=None): if path is None: path = tzwhere.DEFAULT_PICKLE - logging.info('Reading pickle input file: %s\n' % path) + LOGGER.info('Reading pickle input file: %s\n' % path) with open(path, 'rb') as f: featureCollection = pickle.load(f) return featureCollection @staticmethod def write_pickle(featureCollection, path=DEFAULT_PICKLE): - logging.info('Writing pickle output file: %s\n' % path) + LOGGER.info('Writing pickle output file: %s\n' % path) with open(path, 'wb') as f: pickle.dump(featureCollection, f, protocol=2) @@ -283,7 +283,7 @@ def write_pickle(featureCollection, path=DEFAULT_PICKLE): def _read_polygons_from_csv(path=None): if path is None: path = tzwhere.DEFAULT_CSV - logging.info('Reading from CSV input file: %s\n' % path) + LOGGER.info('Reading from CSV input file: %s\n' % path) with open(path, 'r') as f: for row in f: row = row.split(',') @@ -291,7 +291,7 @@ def _read_polygons_from_csv(path=None): @staticmethod def write_csv(featureCollection, path=DEFAULT_CSV): - logging.info('Writing csv output file: %s\n' % path) + LOGGER.info('Writing csv output file: %s\n' % path) with open(path, 'w') as f: writer = csv.writer(f) for (tzname, polygon) in tzwhere._feature_collection_polygons( @@ -366,7 +366,7 @@ def main(): import sys sys.exit(1) - logging.info('Application started..') + LOGGER.info('Application started..') args = docopt.docopt(HELP) global report_memory