summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-05-21 12:49:57 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-05-21 12:49:57 +0200
commitc508926d4ffb25d8ed05a55938ab0741d50b09d2 (patch)
treec6b6ff9f29d2f4c8eb357841c5d6df00465df7b0
parent75eeb5f3515bf3416c98e4337d837cda4f9950e4 (diff)
downloadlogilab-common-c508926d4ffb25d8ed05a55938ab0741d50b09d2.tar.gz
fix deprecated usage of lgc.logger, superseeded by logging + lgc.logging_extlogilab-common-version-0.50.2
-rw-r--r--daemon.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/daemon.py b/daemon.py
index e995b9e..3c20507 100644
--- a/daemon.py
+++ b/daemon.py
@@ -26,8 +26,6 @@ import sys
import time
import warnings
-from logilab.common.logger import make_logger, LOG_ALERT, LOG_NOTICE
-
def daemonize(pidfile):
# See http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC16
@@ -84,11 +82,6 @@ class DaemonMixIn:
If it i not the case, remove the file %s''' % (self.name, self._pid_file))
self._alive = 1
self._sleeping = 0
- treshold = configmod.LOG_TRESHOLD
- if configmod.NODETACH:
- configmod.log = make_logger('print', treshold, self.name).log
- else:
- configmod.log = make_logger('syslog', treshold, self.name).log
self.config = configmod
def _daemonize(self):
@@ -107,17 +100,16 @@ If it i not the case, remove the file %s''' % (self.name, self._pid_file))
"""
if self._daemonize() == -1:
return
- self.config.log(LOG_NOTICE, '%s instance started' % self.name)
if self.delay < 0:
self.delay = -self.delay
time.sleep(self.delay)
while 1:
try:
self._run()
- except Exception, e:
+ except Exception, ex:
# display for info, sleep, and hope the problem will be solved
# later.
- self.config.log(LOG_ALERT, 'Internal error: %s'%(e))
+ self.config.exception('Internal error: %s', ex)
if not self._alive:
break
try:
@@ -126,7 +118,7 @@ If it i not the case, remove the file %s''' % (self.name, self._pid_file))
self._sleeping = 0
except SystemExit:
break
- self.config.log(LOG_NOTICE, '%s instance exited'%self.name)
+ self.config.info('%s instance exited', self.name)
# remove pid file
os.remove(self._pid_file)
@@ -134,19 +126,24 @@ If it i not the case, remove the file %s''' % (self.name, self._pid_file))
if sig_num == signal.SIGTERM:
if self._sleeping:
# we are sleeping so we can exit without fear
- self.config.log(LOG_NOTICE, 'exit on SIGTERM')
+ self.config.debug('exit on SIGTERM')
sys.exit(0)
else:
- self.config.log(LOG_NOTICE, 'exit on SIGTERM (on next turn)')
+ self.config.debug('exit on SIGTERM (on next turn)')
self._alive = 0
elif sig_num == signal.SIGHUP:
- self.config.log(LOG_NOTICE, 'reloading configuration on SIGHUP')
+ self.config.info('reloading configuration on SIGHUP')
reload(self.config)
def _run(self):
"""should be overridden in the mixed class"""
raise NotImplementedError()
+
+import logging
+from logilab.common.logging_ext import set_log_methods
+set_log_methods(DaemonMixIn, logging.getLogger('lgc.daemon'))
+
## command line utilities ######################################################
L_OPTIONS = ["help", "log=", "delay=", 'no-detach']