Skip to content
This repository
Browse code

Added fix for logrotate causing dangling file handlers . Closes #111

  • Loading branch information...
commit e1f67eda29855cecb202f9b72ed0a7169f2aa296 1 parent a5fd367
Nicholas Davidson authored

Showing 2 changed files with 12 additions and 6 deletions. Show diff stats Hide diff stats

  1. +9 6 pybit-client
  2. +3 0  pybitclient/__init__.py
15 pybit-client
@@ -36,6 +36,7 @@ import daemon
36 36 from pybit.daemonlogger import LoggingDaemonContext, FileLikeLogger
37 37 import time
38 38 import logging
  39 +from logging.handlers import WatchedFileHandler
39 40 from pybitclient import PyBITClient
40 41 from pybitclient.debianclient import DebianBuildClient
41 42 from pybitclient.subversion import SubversionClient
@@ -64,9 +65,12 @@ def run(settings) :
64 65 sys.exit (os.EX_OSERR)
65 66
66 67 def getDaemonLogger (filePath, format = None) :
67   - FORMAT = format or '%(asctime)s %(msg)s'
68   - logging.basicConfig(filename=filePath, format=FORMAT, level=logging.DEBUG)
69   - return logging.getLogger()
  68 + logger = logging.getLogger()
  69 + logger.setLevel(logging.DEBUG)
  70 + watchedHandler = WatchedFileHandler(filePath)
  71 + watchedHandler.setFormatter(logging.Formatter(format or '%(asctime)s %(msg)s'))
  72 + logger.addHandler(watchedHandler)
  73 + return logger
70 74
71 75 if __name__ == '__main__':
72 76 parser = optparse.OptionParser()
@@ -134,8 +138,7 @@ if __name__ == '__main__':
134 138 context.loggers_preserve=[testLogger]
135 139 context.signal_map = {
136 140 signal.SIGTERM: signal_handler,
137   - signal.SIGHUP: signal_handler,
138   - signal.SIGUSR1: None,
  141 + signal.SIGHUP: signal_handler
139 142 }
140 143 logging.debug ("Daemonised")
141 144 else :
@@ -149,7 +152,7 @@ if __name__ == '__main__':
149 152 if settings == {}:
150 153 logging.debug ("No settings found - exiting")
151 154 sys.exit(os.EX_OSERR)
152   - if 'configured' in settings and settings.configured == False:
  155 + if 'configured' in settings and settings['configured'] == False:
153 156 logging.debug ("Please configure your client.")
154 157 sys.exit(os.EX_OK)
155 158
3  pybitclient/__init__.py
@@ -415,16 +415,19 @@ def disconnect(self):
415 415 if self.command_chan:
416 416 #self.command_chan.basic_cancel("build_callback")
417 417 try:
  418 + logging.debug("Closing down command channel")
418 419 self.command_chan.close()
419 420 except socket.error :
420 421 pass
421 422 if self.message_chan:
422 423 #self.message_chan.basic_cancel("build_callback")
423 424 try:
  425 + logging.debug("Closing down message channel")
424 426 self.message_chan.close()
425 427 except socket.error :
426 428 pass
427 429 try :
  430 + logging.debug("Closing down rabbitmq connection")
428 431 self.conn.close()
429 432 except socket.error :
430 433 pass

0 comments on commit e1f67ed

Please sign in to comment.
Something went wrong with that request. Please try again.