Repository: MITLibraries/slingshot

Issue:
Add logging

Discussion:

Patch:
diff --git a/slingshot/cli.py b/slingshot/cli.py
index 55efcf6..047d98e 100644
--- a/slingshot/cli.py
+++ b/slingshot/cli.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import
+from datetime import datetime
 import os
 import shutil
 
@@ -58,4 +59,8 @@ def run(layers, store, url, namespace, username, password):
                 submit(zf, url, auth)
         except Exception as e:
             shutil.rmtree(bag, ignore_errors=True)
+            click.echo("%sZ: %s failed with %r" %
+                       (datetime.utcnow().isoformat(), data_layer, e))
             raise e
+        click.echo("%sZ: %s uploaded" % (datetime.utcnow().isoformat(),
+                                         data_layer))


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 1aff724..61eca94 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -59,3 +59,21 @@ def test_run_uses_authentication(runner, layers_dir):
                              '--username', 'foo', '--password', 'bar'])
     assert m.request_history[0].headers['Authorization'] == \
         'Basic Zm9vOmJhcg=='
+
+
+def test_run_logs_uploaded_layers_to_stdout(runner, layers_dir):
+    with requests_mock.Mocker() as m:
+        store = tempfile.mkdtemp()
+        m.post('http://localhost')
+        res = runner.invoke(main, ['run', layers_dir, store,
+                                   'http://localhost'])
+        assert 'SDE_DATA_BD_A8GNS_2003.zip uploaded' in res.output
+
+
+def test_run_logs_failed_layers_to_stdout(runner, layers_dir):
+    with requests_mock.Mocker() as m:
+        store = tempfile.mkdtemp()
+        m.post('http://localhost', status_code=500)
+        res = runner.invoke(main, ['run', layers_dir, store,
+                                   'http://localhost'])
+        assert 'SDE_DATA_BD_A8GNS_2003.zip failed' in res.output