Skip to content

Commit

Permalink
cleanup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhanson committed Feb 6, 2017
1 parent 68d0fb8 commit ea28cd4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
4 changes: 0 additions & 4 deletions modispds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import logging

logger = logging.getLogger(__name__)
#logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
8 changes: 4 additions & 4 deletions modispds/cmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
cmr = CMR(os.path.join(os.path.dirname(__file__), 'cmr.cfg'))

# logging
log = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


def query(start_date, end_date, product='MCD43A4.006', provider='LPDAAC_ECS'):
Expand All @@ -50,7 +50,7 @@ def query(start_date, end_date, product='MCD43A4.006', provider='LPDAAC_ECS'):
date = parse(dt) + datetime.timedelta(days=products[product]['day_offset'])
if (start_date <= date <= end_date):
granules.append(gran)
log.debug("%s granules found within %s - %s" % (len(granules), start_date.date(), end_date.date()))
logger.info("%s granules found within %s - %s" % (len(granules), start_date.date(), end_date.date()))
return granules


Expand All @@ -63,7 +63,7 @@ def download_granule(meta, outdir=''):
# save metadata
fn_meta = os.path.join(outdir, bname + '_meta.json')
with open(fn_meta, 'w') as f:
log.info('Writing metadata to %s' % fn_meta)
logger.debug('Writing metadata to %s' % fn_meta)
dump(meta, f, sort_keys=True, indent=4, ensure_ascii=False)

# download hdf
Expand Down Expand Up @@ -91,7 +91,7 @@ def download_file(url, noauth=False, outdir=''):
chunk_size = 1024
try:
with open(fout, 'wb') as f:
log.info('Saving %s' % fout)
logger.debug('Saving %s' % fout)
for chunk in stream.iter_content(chunk_size):
f.write(chunk)
except:
Expand Down
11 changes: 9 additions & 2 deletions modispds/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
from modispds.version import __version__
from modispds.products import products

logger = logging.getLogger('modispds')
# quiet these loggers
logging.getLogger('boto3').setLevel(logging.CRITICAL)
logging.getLogger('botocore').setLevel(logging.CRITICAL)
logging.getLogger('nose').setLevel(logging.CRITICAL)
logging.getLogger('requests').setLevel(logging.CRITICAL)

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

# default product
_PRODUCT = 'MCD43A4.006'
Expand Down Expand Up @@ -100,7 +107,7 @@ def convert_to_geotiff(hdf, outdir=''):
# save each band as a TIF
for i, band in enumerate(img):
fname = os.path.join(outdir, bname.replace('.hdf', '') + '_' + bandnames[i] + '.TIF')
logger.info('Writing %s' % fname)
logger.debug('Writing %s' % fname)
imgout = img.select([i+1]).save(fname, options=opts)
file_names.append(fname)
# add overview as separate file
Expand Down
5 changes: 2 additions & 3 deletions modispds/pds.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def make_index(thumb, product, files):
html = template.render(thumb=thumb, product=product, files=sorted(files))
index_fname = 'index.html'
with open(index_fname, 'w') as outfile:
logger.info('Writing %s' % index_fname)
outfile.write(html)

return index_fname
Expand Down Expand Up @@ -58,7 +57,7 @@ def push_to_s3(filename, bucket, prefix=''):

ext = os.path.splitext(filename)[1]
with open(filename, 'rb') as f:
logger.info('Uploading %s to: %s' % (key, bucket))
logger.debug('Uploading %s to: %s' % (key, bucket))
if ext == '.html':
content_type = 'text/html'
elif ext == '.json':
Expand Down Expand Up @@ -119,7 +118,7 @@ def del_from_s3(url):
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY
)
logger.info('Deleting %s' % url)
logger.debug('Deleting %s' % url)
parts = splitall(url)
bucket = parts[1]
key = os.path.sep.join(parts[2:])
Expand Down
7 changes: 0 additions & 7 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import logging
import unittest
import datetime
from dateutil.parser import parse
Expand All @@ -8,12 +7,6 @@
from modispds.pds import s3_list, del_from_s3
from modispds.products import products

# quiet these loggers
logging.getLogger('boto3').setLevel(logging.CRITICAL)
logging.getLogger('botocore').setLevel(logging.CRITICAL)
logging.getLogger('nose').setLevel(logging.CRITICAL)
logging.getLogger('requests').setLevel(logging.CRITICAL)


class TestMain(unittest.TestCase):
""" Test query and downloading from CMR """
Expand Down

0 comments on commit ea28cd4

Please sign in to comment.