Commit 70dcead3 authored by Vincent Pelletier's avatar Vincent Pelletier

Move logger initialisation from client.app to Storage.__init__

This makes it easier to control logging in runner (otherwise, would
go to stderr) and functional tests (directed to its own file).

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2377 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 61afbbee
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
from ZODB import BaseStorage, ConflictResolution, POSException from ZODB import BaseStorage, ConflictResolution, POSException
from neo import setupLog
from neo.client.app import Application from neo.client.app import Application
from neo.client.exception import NEOStorageNotFoundError from neo.client.exception import NEOStorageNotFoundError
from neo.client.exception import NEOStorageDoesNotExistError from neo.client.exception import NEOStorageDoesNotExistError
...@@ -35,9 +36,10 @@ class Storage(BaseStorage.BaseStorage, ...@@ -35,9 +36,10 @@ class Storage(BaseStorage.BaseStorage,
__name__ = 'NEOStorage' __name__ = 'NEOStorage'
def __init__(self, master_nodes, name, connector=None, read_only=False, def __init__(self, master_nodes, name, connector=None, read_only=False,
compress=None, **kw): compress=None, logfile=None, verbose=False, **kw):
if compress is None: if compress is None:
compress = True compress = True
setupLog('CLIENT', filename=logfile, verbose=verbose)
BaseStorage.BaseStorage.__init__(self, name) BaseStorage.BaseStorage.__init__(self, name)
self._is_read_only = read_only self._is_read_only = read_only
self.app = Application(master_nodes, name, connector, self.app = Application(master_nodes, name, connector,
......
...@@ -26,9 +26,6 @@ from ZODB.POSException import UndoError, StorageTransactionError, ConflictError ...@@ -26,9 +26,6 @@ from ZODB.POSException import UndoError, StorageTransactionError, ConflictError
from ZODB.ConflictResolution import ResolvedSerial from ZODB.ConflictResolution import ResolvedSerial
from persistent.TimeStamp import TimeStamp from persistent.TimeStamp import TimeStamp
from neo import setupLog
setupLog('CLIENT', verbose=True)
import neo import neo
from neo.protocol import NodeTypes, Packets, INVALID_PARTITION, ZERO_TID from neo.protocol import NodeTypes, Packets, INVALID_PARTITION, ZERO_TID
from neo.event import EventManager from neo.event import EventManager
......
...@@ -32,8 +32,6 @@ from neo.neoctl.neoctl import NeoCTL, NotReadyException ...@@ -32,8 +32,6 @@ from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo.protocol import ClusterStates, NodeTypes, CellStates from neo.protocol import ClusterStates, NodeTypes, CellStates
from neo.util import dump from neo.util import dump
from neo.tests import DB_ADMIN, DB_PASSWD from neo.tests import DB_ADMIN, DB_PASSWD
import neo
from neo.client.Storage import Storage from neo.client.Storage import Storage
NEO_MASTER = 'neomaster' NEO_MASTER = 'neomaster'
...@@ -175,9 +173,6 @@ class NEOCluster(object): ...@@ -175,9 +173,6 @@ class NEOCluster(object):
temp_dir = tempfile.mkdtemp(prefix='neo_') temp_dir = tempfile.mkdtemp(prefix='neo_')
print 'Using temp directory %r.' % (temp_dir, ) print 'Using temp directory %r.' % (temp_dir, )
self.temp_dir = temp_dir self.temp_dir = temp_dir
# Setup client logger
neo.setupLog(name='CLIENT', filename=os.path.join(self.temp_dir,
'client.log'), verbose=self.verbose)
admin_port = self.__allocatePort() admin_port = self.__allocatePort()
self.cluster_name = 'neo_%s' % (random.randint(0, 100), ) self.cluster_name = 'neo_%s' % (random.randint(0, 100), )
master_node_list = [self.__allocatePort() for i in xrange(master_node_count)] master_node_list = [self.__allocatePort() for i in xrange(master_node_count)]
...@@ -329,7 +324,10 @@ class NEOCluster(object): ...@@ -329,7 +324,10 @@ class NEOCluster(object):
return Storage( return Storage(
master_nodes=master_nodes, master_nodes=master_nodes,
name=self.cluster_name, name=self.cluster_name,
connector='SocketConnector') connector='SocketConnector',
logfile=os.path.join(self.temp_dir, 'client.log'),
verbose=self.verbose,
)
def getZODBConnection(self): def getZODBConnection(self):
""" Return a tuple with the database and a connection """ """ Return a tuple with the database and a connection """
......
...@@ -22,6 +22,7 @@ import tempfile ...@@ -22,6 +22,7 @@ import tempfile
import logging import logging
import time import time
import sys import sys
import neo
import os import os
# list of test modules # list of test modules
...@@ -90,23 +91,12 @@ ZODB_TEST_MODULES = [ ...@@ -90,23 +91,12 @@ ZODB_TEST_MODULES = [
] ]
# configuration # configuration
CONSOLE_LOG = False
ATTACH_LOG = False # for ZODB test, only the client side is logged ATTACH_LOG = False # for ZODB test, only the client side is logged
LOG_FILE = 'neo.log' LOG_FILE = 'neo.log'
# override logging configuration to send all messages to a file # override logging configuration to send all messages to a file
logger = logging.getLogger() for logger_name in ('NEO', 'CLIENT'):
logger.setLevel(logging.INFO) neo.setupLog(logger_name, filename=LOG_FILE)
handler = logging.FileHandler(LOG_FILE, 'w+')
format='[%(module)12s:%(levelname)s:%(lineno)3d] %(message)s'
formatter = logging.Formatter(format)
handler.setFormatter(formatter)
logger.addHandler(handler)
# enabled console logging if desired
if CONSOLE_LOG:
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
class NeoTestRunner(unittest.TestResult): class NeoTestRunner(unittest.TestResult):
""" Custom result class to build report with statistics per module """ """ Custom result class to build report with statistics per module """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment