Commits

mickael9  committed 8d00cd5

Better logging

  • Participants
  • Parent commits 96a8240

Comments (0)

Files changed (2)

 
     try:
         resp = urlopen(req)
+        logger.debug("got %d response", resp.status)
         raw = resp.read()
     except HTTPError as ex:
         resp = ex
+        logger.debug("got %d error", resp.code) # urllib sucks
         raw = ex.read()
 
     raw = raw.decode('utf-8')
         print("Error: unable to decode JSON: %s" % raw)
         raise APIError("Unable to decode JSON: %s", raw)
 
-    logger.debug("response (%d):\n%s", resp.status, pprint.pformat(result))
+    logger.debug("json:\n%s", pprint.pformat(result))
 
     if 'error' in result:
         raise APIError(result['error'])

File gett_uploader.py

     try:
         main()
     except APIError as ex:
-        print('API error: %s' % ex)
+        logger.error('API error: %s', ex)
 
 def pattern(string):
     import glob
                 ret.append(open(item, 'rb'))
 
     if not ret:
-        print('warning: %s: no match' % string)
+        logger.warning('%s: no match', string)
     return ret
 
 def main():
 
         try:
             user.login_auth(args.email, args.password)
-        except Exception as ex:
-            print('Unable to login: %s' % ex.args[0])
+        except APIError as ex:
+            logger.error('Unable to login: %s', ex)
             sys.exit(1)
 
         reply = input('Do you wish to store the session token? (y/n): ')