Add a global logger for the script

Issue: INFRA-237
Change-Id: I87b9cd1574676fa380e0611ed043a48f42600b06
diff --git a/deploy.py b/deploy.py
index f9d1fc1..d3dc1b0 100755
--- a/deploy.py
+++ b/deploy.py
@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 
+import logging
 import pathlib
 import re
 import subprocess
@@ -15,6 +16,9 @@
 
 PREBUILT_PROXY_APK_PATTERN = "com.lunarlabs.panda.proxy-latest-sdk{sdk}-{flavour}.apk"
 
+
+_LOG = logging.getLogger(__name__)
+
 PREBUILT_APKS = ["com.smartviser.demogame-latest.apk", "com.lunarlabs.panda-latest.apk"]
 
 FAIRPHONE_WIFI_NETWORKS = {
@@ -460,7 +464,7 @@
         serials = list_devices()
 
     for serial in serials:
-        print("Configuring device {}…".format(serial))
+        _LOG.info("Deploy to device %s", serial)
 
         device = DeviceUnderTest(serial)
         try:
@@ -503,15 +507,18 @@
             configure_perms(device)
 
             configure_settings(device)
-        except (HostCommandError, DeviceCommandError) as e:
-            print("ERROR {}".format(e), file=sys.stderr)
+        except (HostCommandError, DeviceCommandError, uiautomator.JsonRPCError):
+            _LOG.error("Failed to execute deployment", exc_info=True)
         finally:
             try:
                 # Leave the device alone now
                 device.force_awake(always=False)
-            except DeviceCommandError as e:
-                print("WARNING {}".format(e), file=sys.stderr)
+            except DeviceCommandError:
+                _LOG.warning("Failed to tear down device", exc_info=True)
 
 
 if __name__ == "__main__":
+    logging.basicConfig(
+        format="%(asctime)-15s:%(levelname)s:%(message)s", level=logging.INFO
+    )
     deploy()