[REF] Use the logging module instead of the Logger().notifyChannel() function
bzr revid: stephane@openerp.com-20100303130435-027rr4aw8k1tz4tj
This commit is contained in:
parent
16b87751fc
commit
f17afd9d89
|
@ -24,18 +24,13 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import SimpleXMLRPCServer
|
|
||||||
import SocketServer
|
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import os
|
|
||||||
import signal
|
|
||||||
import socket
|
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import xmlrpclib
|
|
||||||
import release
|
import release
|
||||||
|
from pprint import pformat
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
class Service(object):
|
class Service(object):
|
||||||
|
@ -78,6 +73,7 @@ class LocalService(object):
|
||||||
Any instance of this class will behave like the single instance
|
Any instance of this class will behave like the single instance
|
||||||
of Service(name)
|
of Service(name)
|
||||||
"""
|
"""
|
||||||
|
__logger = logging.getLogger('service')
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
try:
|
try:
|
||||||
|
@ -85,8 +81,9 @@ class LocalService(object):
|
||||||
for method_name, method_definition in self._service._methods.items():
|
for method_name, method_definition in self._service._methods.items():
|
||||||
setattr(self, method_name, method_definition)
|
setattr(self, method_name, method_definition)
|
||||||
except KeyError, keyError:
|
except KeyError, keyError:
|
||||||
Logger().notifyChannel('module', LOG_ERROR, 'This service does not exist: %s' % (str(keyError),) )
|
self.__logger.error('This service does not exist: %s' % (str(keyError),) )
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def __call__(self, method, *params):
|
def __call__(self, method, *params):
|
||||||
return getattr(self, method)(*params)
|
return getattr(self, method)(*params)
|
||||||
|
|
||||||
|
@ -270,10 +267,12 @@ class Agent(object):
|
||||||
_timers = {}
|
_timers = {}
|
||||||
_logger = Logger()
|
_logger = Logger()
|
||||||
|
|
||||||
|
__logger = logging.getLogger('timer')
|
||||||
|
|
||||||
def setAlarm(self, fn, dt, db_name, *args, **kwargs):
|
def setAlarm(self, fn, dt, db_name, *args, **kwargs):
|
||||||
wait = dt - time.time()
|
wait = dt - time.time()
|
||||||
if wait > 0:
|
if wait > 0:
|
||||||
self._logger.notifyChannel('timers', LOG_DEBUG, "Job scheduled in %.3g seconds for %s.%s" % (wait, fn.im_class.__name__, fn.func_name))
|
self.__logger.debug("Job scheduled in %.3g seconds for %s.%s" % (wait, fn.im_class.__name__, fn.func_name))
|
||||||
timer = threading.Timer(wait, fn, args, kwargs)
|
timer = threading.Timer(wait, fn, args, kwargs)
|
||||||
timer.start()
|
timer.start()
|
||||||
self._timers.setdefault(db_name, []).append(timer)
|
self._timers.setdefault(db_name, []).append(timer)
|
||||||
|
@ -307,18 +306,19 @@ class Server:
|
||||||
__is_started = False
|
__is_started = False
|
||||||
__servers = []
|
__servers = []
|
||||||
|
|
||||||
|
|
||||||
|
__logger = logging.getLogger('server')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
if Server.__is_started:
|
if Server.__is_started:
|
||||||
raise Exception('All instances of servers must be inited before the startAll()')
|
raise Exception('All instances of servers must be inited before the startAll()')
|
||||||
Server.__servers.append(self)
|
Server.__servers.append(self)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
print "called stub Server.start"
|
self.__logger.debug("called stub Server.start")
|
||||||
pass
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
print "called stub Server.stop"
|
self.__logger.debug("called stub Server.stop")
|
||||||
pass
|
|
||||||
|
|
||||||
def stats(self):
|
def stats(self):
|
||||||
""" This function should return statistics about the server """
|
""" This function should return statistics about the server """
|
||||||
|
@ -328,8 +328,7 @@ class Server:
|
||||||
def startAll(cls):
|
def startAll(cls):
|
||||||
if cls.__is_started:
|
if cls.__is_started:
|
||||||
return
|
return
|
||||||
Logger().notifyChannel("services", LOG_INFO,
|
cls.__logger.info("Starting %d services" % len(cls.__servers))
|
||||||
"Starting %d services" % len(cls.__servers))
|
|
||||||
for srv in cls.__servers:
|
for srv in cls.__servers:
|
||||||
srv.start()
|
srv.start()
|
||||||
cls.__is_started = True
|
cls.__is_started = True
|
||||||
|
@ -338,25 +337,16 @@ class Server:
|
||||||
def quitAll(cls):
|
def quitAll(cls):
|
||||||
if not cls.__is_started:
|
if not cls.__is_started:
|
||||||
return
|
return
|
||||||
Logger().notifyChannel("services", LOG_INFO,
|
cls.__logger.info("Stopping %d services" % len(cls.__servers))
|
||||||
"Stopping %d services" % len(cls.__servers))
|
|
||||||
for srv in cls.__servers:
|
for srv in cls.__servers:
|
||||||
srv.stop()
|
srv.stop()
|
||||||
cls.__is_started = False
|
cls.__is_started = False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def allStats(cls):
|
def allStats(cls):
|
||||||
res = ''
|
res = ["Servers %s" % ('stopped', 'started')[cls.__is_started]]
|
||||||
if cls.__is_started:
|
res.extend(srv.stats() for srv in cls.__servers)
|
||||||
res += "Servers started\n"
|
return '\n'.join(res)
|
||||||
else:
|
|
||||||
res += "Servers stopped\n"
|
|
||||||
for srv in cls.__servers:
|
|
||||||
try:
|
|
||||||
res += srv.stats() + "\n"
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return res
|
|
||||||
|
|
||||||
class OpenERPDispatcherException(Exception):
|
class OpenERPDispatcherException(Exception):
|
||||||
def __init__(self, exception, traceback):
|
def __init__(self, exception, traceback):
|
||||||
|
@ -365,7 +355,6 @@ class OpenERPDispatcherException(Exception):
|
||||||
|
|
||||||
class OpenERPDispatcher:
|
class OpenERPDispatcher:
|
||||||
def log(self, title, msg):
|
def log(self, title, msg):
|
||||||
from pprint import pformat
|
|
||||||
Logger().notifyChannel('%s' % title, LOG_DEBUG_RPC, pformat(msg))
|
Logger().notifyChannel('%s' % title, LOG_DEBUG_RPC, pformat(msg))
|
||||||
|
|
||||||
def dispatch(self, service_name, method, params):
|
def dispatch(self, service_name, method, params):
|
||||||
|
|
Loading…
Reference in New Issue