backup.py

changeset 31
b4b4bb7a2ec5
parent 30
3dd525652dc8
child 32
06fc14211ba9
--- a/backup.py	Sun Jan 21 12:10:57 2018 +0000
+++ b/backup.py	Sun Jan 21 13:34:12 2018 +0000
@@ -10,6 +10,8 @@
 from queue import Queue
 from threading import Thread, Lock, Timer
 
+logger=logging.getLogger(__name__)
+
 loglevel_translation={
     'CRITICAL': logging.CRITICAL,
     'ERROR': logging.ERROR,
@@ -122,10 +124,10 @@
         assert(not running)
 
     def __log_listener(self):
-        logging.debug('Log listener thread waiting for entries')
+        logger.debug('Log listener thread waiting for entries')
         success=True
         for status in iter(self.borg_instance.read_log, None):
-            logging.debug(str(status))
+            logger.debug(str(status))
             t=status['type']
 
             errors_this_message=None
@@ -165,23 +167,23 @@
                 if 'name' not in status:
                     status['name']='borg'
                 lvl=translate_loglevel(status['levelname'])
-                logging.log(lvl, status['name'] + ': ' + status['message'])
+                logger.log(lvl, status['name'] + ': ' + status['message'])
                 if lvl>=logging.WARNING:
                     errors_this_message=status
                     with self.lock:
                         self.current_operation['errors']=True
                         status, callback=self.__status_unlocked()
             else:
-                logging.debug('Unrecognised log entry %s' % str(status))
+                logger.debug('Unrecognised log entry %s' % str(status))
 
             if callback:
                 callback(self, status, errors=errors_this_message)
 
-        logging.debug('Waiting for borg subprocess to terminate in log thread')
+        logger.debug('Waiting for borg subprocess to terminate in log thread')
 
         self.borg_instance.wait()
 
-        logging.debug('Borg subprocess terminated; terminating log listener thread')
+        logger.debug('Borg subprocess terminated; terminating log listener thread')
 
     def __result_listener(self):
         with self.lock:
@@ -189,22 +191,22 @@
         if callback:
             callback(self, status)
 
-        logging.debug('Result listener thread waiting for result')
+        logger.debug('Result listener thread waiting for result')
 
         res=self.borg_instance.read_result()
 
         success=True
 
-        logging.debug('Borg result: %s' % str(res))
+        logger.debug('Borg result: %s' % str(res))
 
         if res==None:
             success=False
 
-        logging.debug('Waiting for borg subprocess to terminate in result thread')
+        logger.debug('Waiting for borg subprocess to terminate in result thread')
 
         success=success and self.borg_instance.wait()
 
-        logging.debug('Borg subprocess terminated (success: %s); terminating result listener thread' % str(success))
+        logger.debug('Borg subprocess terminated (success: %s); terminating result listener thread' % str(success))
 
         self.thread_log.join()
 
@@ -227,6 +229,8 @@
         inst=BorgInstance(op['operation'], archive_or_repository, *args)
         inst.launch(passphrase=self.__passphrase)
 
+        logger.debug('Creating listener threads')
+
         t_log=Thread(target=self.__log_listener)
         t_log.daemon=True
 
@@ -250,11 +254,11 @@
             return False
         else:
             if self.timer:
-                logging.debug('Unscheduling timed operation due to launch of operation')
+                logger.debug('Unscheduling timed operation due to launch of operation')
                 self.timer=None
                 self.scheduled_operation=None
 
-            logging.debug("Launching '%s' on '%s'" % (op['operation'], self.name))
+            logger.debug("Launching '%s' on '%s'" % (op['operation'], self.name))
 
             if op['operation']=='create':
                 archive="%s::%s%s" % (self.repository,
@@ -270,7 +274,7 @@
                                   self.common_parameters +
                                   self.prune_parameters))
             else:
-                logging.error("Invalid operaton '%s'" % op['operation'])
+                logger.error("Invalid operaton '%s'" % op['operation'])
                 self.__schedule_unlocked()
 
             return True
@@ -303,7 +307,7 @@
 
 
     def join(self):
-        logging.debug('Waiting for borg listener threads to terminate')
+        logger.debug('Waiting for borg listener threads to terminate')
 
         with self.lock:
             thread_log=self.thread_log

mercurial