Doing a better job of managing the lifetime of my objects
[gc-dialer] / src / alarm_notify.py
index 5810710..bc6240e 100755 (executable)
@@ -5,6 +5,7 @@ import filecmp
 import ConfigParser
 import pprint
 import logging
+import logging.handlers
 
 import constants
 from backends.gvoice import gvoice
@@ -92,7 +93,7 @@ def create_backend(config):
        loggedIn = False
 
        if not loggedIn:
-               loggedIn = backend.is_authed()
+               loggedIn = backend.refresh_account_info() is not None
 
        if not loggedIn:
                import base64
@@ -106,7 +107,7 @@ def create_backend(config):
                                for blob in blobs
                        )
                        username, password = tuple(creds)
-                       loggedIn = backend.login(username, password)
+                       loggedIn = backend.login(username, password) is not None
                except ConfigParser.NoOptionError, e:
                        pass
                except ConfigParser.NoSectionError, e:
@@ -164,7 +165,12 @@ def notify_on_change():
 
 
 if __name__ == "__main__":
-       logging.basicConfig(level=logging.DEBUG, filename=constants._notifier_logpath_)
+       logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
+       logging.basicConfig(level=logging.DEBUG, format=logFormat)
+       rotating = logging.handlers.RotatingFileHandler(constants._notifier_logpath_, maxBytes=512*1024, backupCount=1)
+       rotating.setFormatter(logging.Formatter(logFormat))
+       root = logging.getLogger()
+       root.addHandler(rotating)
        logging.info("Notifier %s-%s" % (constants.__version__, constants.__build__))
        logging.info("OS: %s" % (os.uname()[0], ))
        logging.info("Kernel: %s (%s) for %s" % os.uname()[2:])