Commit b85adacb authored by Gintautas Miliauskas's avatar Gintautas Miliauskas

This should be the last nail in zLOG's coffin. grep reveals no more references

to zLOG other than a few comments.

This definitely broke the log analyzers pretty bad.
parent af86eebd
...@@ -25,6 +25,7 @@ import tempfile ...@@ -25,6 +25,7 @@ import tempfile
import threading import threading
import time import time
import types import types
import logging
from ZEO import ServerStub from ZEO import ServerStub
from ZEO.cache import ClientCache from ZEO.cache import ClientCache
...@@ -34,11 +35,15 @@ from ZEO.auth import get_module ...@@ -34,11 +35,15 @@ from ZEO.auth import get_module
from ZEO.zrpc.client import ConnectionManager from ZEO.zrpc.client import ConnectionManager
from ZODB import POSException from ZODB import POSException
from ZODB.loglevels import BLATHER
from persistent.TimeStamp import TimeStamp from persistent.TimeStamp import TimeStamp
from zLOG import LOG, PROBLEM, INFO, BLATHER, ERROR
def log2(type, msg, subsys="ZCS:%d" % os.getpid()): logger = logging.getLogger('ZEO.ClientStorage')
LOG(subsys, type, msg) _pid = str(os.getpid())
def log2(msg, level=logging.INFO, subsys=_pid, exc_info=False):
message = "(%s) %s" % (subsys, msg)
logger.log(level, message, exc_info=exc_info)
try: try:
from ZODB.ConflictResolution import ResolvedSerial from ZODB.ConflictResolution import ResolvedSerial
...@@ -177,7 +182,7 @@ class ClientStorage(object): ...@@ -177,7 +182,7 @@ class ClientStorage(object):
testConnection() and doAuth() for details). testConnection() and doAuth() for details).
""" """
log2(INFO, "%s (pid=%d) created %s/%s for storage: %r" % log2("%s (pid=%d) created %s/%s for storage: %r" %
(self.__class__.__name__, (self.__class__.__name__,
os.getpid(), os.getpid(),
read_only and "RO" or "RW", read_only and "RO" or "RW",
...@@ -185,18 +190,17 @@ class ClientStorage(object): ...@@ -185,18 +190,17 @@ class ClientStorage(object):
storage)) storage))
if debug: if debug:
log2(INFO, "ClientStorage(): debug argument is no longer used") log2("ClientStorage(): debug argument is no longer used")
# wait defaults to True, but wait_for_server_on_startup overrides # wait defaults to True, but wait_for_server_on_startup overrides
# if not None # if not None
if wait_for_server_on_startup is not None: if wait_for_server_on_startup is not None:
if wait is not None and wait != wait_for_server_on_startup: if wait is not None and wait != wait_for_server_on_startup:
log2(PROBLEM, log2("ClientStorage(): conflicting values for wait and "
"ClientStorage(): conflicting values for wait and " "wait_for_server_on_startup; wait prevails",
"wait_for_server_on_startup; wait prevails") level=logging.WARNING)
else: else:
log2(INFO, log2("ClientStorage(): wait_for_server_on_startup "
"ClientStorage(): wait_for_server_on_startup "
"is deprecated; please use wait instead") "is deprecated; please use wait instead")
wait = wait_for_server_on_startup wait = wait_for_server_on_startup
elif wait is None: elif wait is None:
...@@ -325,7 +329,7 @@ class ClientStorage(object): ...@@ -325,7 +329,7 @@ class ClientStorage(object):
def _wait(self, timeout=None): def _wait(self, timeout=None):
if timeout is not None: if timeout is not None:
deadline = time.time() + timeout deadline = time.time() + timeout
log2(BLATHER, "Setting deadline to %f" % deadline) log2("Setting deadline to %f" % deadline, level=BLATHER)
else: else:
deadline = None deadline = None
# Wait for a connection to be established. # Wait for a connection to be established.
...@@ -341,9 +345,10 @@ class ClientStorage(object): ...@@ -341,9 +345,10 @@ class ClientStorage(object):
if self._ready.isSet(): if self._ready.isSet():
break break
if timeout and time.time() > deadline: if timeout and time.time() > deadline:
log2(PROBLEM, "Timed out waiting for connection") log2("Timed out waiting for connection",
level=logging.WARNING)
break break
log2(INFO, "Waiting for cache verification to finish") log2("Waiting for cache verification to finish")
else: else:
self._wait_sync(deadline) self._wait_sync(deadline)
...@@ -354,9 +359,9 @@ class ClientStorage(object): ...@@ -354,9 +359,9 @@ class ClientStorage(object):
if self._ready.isSet(): if self._ready.isSet():
break break
if deadline and time.time() > deadline: if deadline and time.time() > deadline:
log2(PROBLEM, "Timed out waiting for connection") log2("Timed out waiting for connection", level=logging.WARNING)
break break
log2(INFO, "Waiting for cache verification to finish") log2("Waiting for cache verification to finish")
if self._connection is None: if self._connection is None:
# If the connection was closed while we were # If the connection was closed while we were
# waiting for it to become ready, start over. # waiting for it to become ready, start over.
...@@ -408,16 +413,15 @@ class ClientStorage(object): ...@@ -408,16 +413,15 @@ class ClientStorage(object):
module = get_module(protocol) module = get_module(protocol)
if not module: if not module:
log2(PROBLEM, "%s: no such an auth protocol: %s" % log2("%s: no such an auth protocol: %s" %
(self.__class__.__name__, protocol)) (self.__class__.__name__, protocol), level=logging.WARNING)
return return
storage_class, client, db_class = module storage_class, client, db_class = module
if not client: if not client:
log2(PROBLEM, log2("%s: %s isn't a valid protocol, must have a Client class" %
"%s: %s isn't a valid protocol, must have a Client class" % (self.__class__.__name__, protocol), level=logging.WARNING)
(self.__class__.__name__, protocol))
raise AuthError, "invalid protocol" raise AuthError, "invalid protocol"
c = client(stub) c = client(stub)
...@@ -446,20 +450,20 @@ class ClientStorage(object): ...@@ -446,20 +450,20 @@ class ClientStorage(object):
succeeding register() call is deemed an optimal match, and any succeeding register() call is deemed an optimal match, and any
exception raised by register() is passed through. exception raised by register() is passed through.
""" """
log2(INFO, "Testing connection %r" % conn) log2("Testing connection %r" % conn)
# XXX Check the protocol version here? # XXX Check the protocol version here?
self._conn_is_read_only = 0 self._conn_is_read_only = 0
stub = self.StorageServerStubClass(conn) stub = self.StorageServerStubClass(conn)
auth = stub.getAuthProtocol() auth = stub.getAuthProtocol()
log2(INFO, "Server authentication protocol %r" % auth) log2("Server authentication protocol %r" % auth)
if auth: if auth:
skey = self.doAuth(auth, stub) skey = self.doAuth(auth, stub)
if skey: if skey:
log2(INFO, "Client authentication successful") log2("Client authentication successful")
conn.setSessionKey(skey) conn.setSessionKey(skey)
else: else:
log2(ERROR, "Authentication failed") log2("Authentication failed")
raise AuthError, "Authentication failed" raise AuthError, "Authentication failed"
try: try:
...@@ -468,7 +472,7 @@ class ClientStorage(object): ...@@ -468,7 +472,7 @@ class ClientStorage(object):
except POSException.ReadOnlyError: except POSException.ReadOnlyError:
if not self._read_only_fallback: if not self._read_only_fallback:
raise raise
log2(INFO, "Got ReadOnlyError; trying again with read_only=1") log2("Got ReadOnlyError; trying again with read_only=1")
stub.register(str(self._storage), read_only=1) stub.register(str(self._storage), read_only=1)
self._conn_is_read_only = 1 self._conn_is_read_only = 1
return 0 return 0
...@@ -499,16 +503,16 @@ class ClientStorage(object): ...@@ -499,16 +503,16 @@ class ClientStorage(object):
self._connection = conn self._connection = conn
if reconnect: if reconnect:
log2(INFO, "Reconnected to storage: %s" % self._server_addr) log2("Reconnected to storage: %s" % self._server_addr)
else: else:
log2(INFO, "Connected to storage: %s" % self._server_addr) log2("Connected to storage: %s" % self._server_addr)
stub = self.StorageServerStubClass(conn) stub = self.StorageServerStubClass(conn)
self._oids = [] self._oids = []
self._info.update(stub.get_info()) self._info.update(stub.get_info())
self.verify_cache(stub) self.verify_cache(stub)
if not conn.is_async(): if not conn.is_async():
log2(INFO, "Waiting for cache verification to finish") log2("Waiting for cache verification to finish")
self._wait_sync() self._wait_sync()
self._handle_extensions() self._handle_extensions()
...@@ -532,7 +536,8 @@ class ClientStorage(object): ...@@ -532,7 +536,8 @@ class ClientStorage(object):
try: try:
canonical, aliases, addrs = socket.gethostbyaddr(host) canonical, aliases, addrs = socket.gethostbyaddr(host)
except socket.error, err: except socket.error, err:
log2(BLATHER, "Error resolving host: %s (%s)" % (host, err)) log2("Error resolving host: %s (%s)" % (host, err),
level=BLATHER)
canonical = host canonical = host
self._server_addr = str((canonical, addr[1])) self._server_addr = str((canonical, addr[1]))
...@@ -559,27 +564,26 @@ class ClientStorage(object): ...@@ -559,27 +564,26 @@ class ClientStorage(object):
if last_inval_tid is not None: if last_inval_tid is not None:
ltid = server.lastTransaction() ltid = server.lastTransaction()
if ltid == last_inval_tid: if ltid == last_inval_tid:
log2(INFO, "No verification necessary " log2("No verification necessary (last_inval_tid up-to-date)")
"(last_inval_tid up-to-date)")
self._server = server self._server = server
self._ready.set() self._ready.set()
return "no verification" return "no verification"
# log some hints about last transaction # log some hints about last transaction
log2(INFO, "last inval tid: %r %s\n" log2("last inval tid: %r %s\n"
% (last_inval_tid, tid2time(last_inval_tid))) % (last_inval_tid, tid2time(last_inval_tid)))
log2(INFO, "last transaction: %r %s" % log2("last transaction: %r %s" %
(ltid, ltid and tid2time(ltid))) (ltid, ltid and tid2time(ltid)))
pair = server.getInvalidations(last_inval_tid) pair = server.getInvalidations(last_inval_tid)
if pair is not None: if pair is not None:
log2(INFO, "Recovering %d invalidations" % len(pair[1])) log2("Recovering %d invalidations" % len(pair[1]))
self.invalidateTransaction(*pair) self.invalidateTransaction(*pair)
self._server = server self._server = server
self._ready.set() self._ready.set()
return "quick verification" return "quick verification"
log2(INFO, "Verifying cache") log2("Verifying cache")
# setup tempfile to hold zeoVerify results # setup tempfile to hold zeoVerify results
self._tfile = tempfile.TemporaryFile(suffix=".inv") self._tfile = tempfile.TemporaryFile(suffix=".inv")
self._pickler = cPickle.Pickler(self._tfile, 1) self._pickler = cPickle.Pickler(self._tfile, 1)
...@@ -607,7 +611,7 @@ class ClientStorage(object): ...@@ -607,7 +611,7 @@ class ClientStorage(object):
This is called by ConnectionManager when the connection is This is called by ConnectionManager when the connection is
closed or when certain problems with the connection occur. closed or when certain problems with the connection occur.
""" """
log2(INFO, "Disconnected from storage: %s" % repr(self._server_addr)) log2("Disconnected from storage: %s" % repr(self._server_addr))
self._connection = None self._connection = None
self._ready.clear() self._ready.clear()
self._server = disconnected_stub self._server = disconnected_stub
...@@ -934,7 +938,8 @@ class ClientStorage(object): ...@@ -934,7 +938,8 @@ class ClientStorage(object):
try: try:
self._server.tpc_abort(id(txn)) self._server.tpc_abort(id(txn))
except ClientDisconnected: except ClientDisconnected:
log2(BLATHER, 'ClientDisconnected in tpc_abort() ignored') log2("ClientDisconnected in tpc_abort() ignored",
level=BLATHER)
finally: finally:
self._tbuf.clear() self._tbuf.clear()
self._seriald.clear() self._seriald.clear()
...@@ -1088,11 +1093,11 @@ class ClientStorage(object): ...@@ -1088,11 +1093,11 @@ class ClientStorage(object):
self._process_invalidations(InvalidationLogIterator(f)) self._process_invalidations(InvalidationLogIterator(f))
f.close() f.close()
log2(INFO, "endVerify finishing") log2("endVerify finishing")
self._server = self._pending_server self._server = self._pending_server
self._ready.set() self._ready.set()
self._pending_conn = None self._pending_conn = None
log2(INFO, "endVerify finished") log2("endVerify finished")
def invalidateTransaction(self, tid, args): def invalidateTransaction(self, tid, args):
"""Invalidate objects modified by tid.""" """Invalidate objects modified by tid."""
...@@ -1102,8 +1107,8 @@ class ClientStorage(object): ...@@ -1102,8 +1107,8 @@ class ClientStorage(object):
finally: finally:
self._lock.release() self._lock.release()
if self._pickler is not None: if self._pickler is not None:
log2(BLATHER, log2("Transactional invalidation during cache verification",
"Transactional invalidation during cache verification") level=BLATHER)
for t in args: for t in args:
self._pickler.dump(t) self._pickler.dump(t)
return return
......
...@@ -26,6 +26,7 @@ import os ...@@ -26,6 +26,7 @@ import os
import sys import sys
import threading import threading
import time import time
import logging
import transaction import transaction
...@@ -37,23 +38,30 @@ from ZEO.zrpc.connection import ManagedServerConnection, Delay, MTDelay ...@@ -37,23 +38,30 @@ from ZEO.zrpc.connection import ManagedServerConnection, Delay, MTDelay
from ZEO.zrpc.trigger import trigger from ZEO.zrpc.trigger import trigger
from ZEO.Exceptions import AuthError from ZEO.Exceptions import AuthError
import zLOG
from ZODB.ConflictResolution import ResolvedSerial from ZODB.ConflictResolution import ResolvedSerial
from ZODB.POSException import StorageError, StorageTransactionError from ZODB.POSException import StorageError, StorageTransactionError
from ZODB.POSException import TransactionError, ReadOnlyError, ConflictError from ZODB.POSException import TransactionError, ReadOnlyError, ConflictError
from ZODB.serialize import referencesf from ZODB.serialize import referencesf
from ZODB.utils import u64, oid_repr from ZODB.utils import u64, oid_repr
from ZODB.loglevels import BLATHER
_label = "ZSS" # Default label used for logging. logger = logging.getLogger('ZEO.StorageServer')
# XXX This used to say "ZSS", which is now implied in the logger name, can this
# be either set to str(os.getpid()) (if that makes sense) or removed?
_label = "" # default label used for logging.
def set_label(): def set_label():
"""Internal helper to reset the logging label (e.g. after fork()).""" """Internal helper to reset the logging label (e.g. after fork())."""
global _label global _label
_label = "ZSS:%s" % os.getpid() _label = "%s" % os.getpid()
def log(message, level=zLOG.INFO, label=None, error=None): def log(message, level=logging.INFO, label=None, exc_info=False):
"""Internal helper to log a message using zLOG.""" """Internal helper to log a message."""
zLOG.LOG(label or _label, level, message, error=error) label = label or _label
if label:
message = "(%s) %s" % (label, message)
logger.log(level, message, exc_info=exc_info)
class StorageServerError(StorageError): class StorageServerError(StorageError):
"""Error reported when an unpickleable exception is raised.""" """Error reported when an unpickleable exception is raised."""
...@@ -131,8 +139,8 @@ class ZEOStorage: ...@@ -131,8 +139,8 @@ class ZEOStorage:
name = self.__class__.__name__ name = self.__class__.__name__
return "<%s %X trans=%s s_trans=%s>" % (name, id(self), tid, stid) return "<%s %X trans=%s s_trans=%s>" % (name, id(self), tid, stid)
def log(self, msg, level=zLOG.INFO, error=None): def log(self, msg, level=logging.INFO, exc_info=False):
zLOG.LOG(self.log_label, level, msg, error=error) log(msg, level=level, label=self.log_label, exc_info=exc_info)
def setup_delegation(self): def setup_delegation(self):
"""Delegate several methods to the storage""" """Delegate several methods to the storage"""
...@@ -164,7 +172,8 @@ class ZEOStorage: ...@@ -164,7 +172,8 @@ class ZEOStorage:
raise ReadOnlyError() raise ReadOnlyError()
if self.transaction is None: if self.transaction is None:
caller = sys._getframe().f_back.f_code.co_name caller = sys._getframe().f_back.f_code.co_name
self.log("no current transaction: %s()" % caller, zLOG.PROBLEM) self.log("no current transaction: %s()" % caller,
level=logging.WARNING)
if exc is not None: if exc is not None:
raise exc(None, tid) raise exc(None, tid)
else: else:
...@@ -173,7 +182,7 @@ class ZEOStorage: ...@@ -173,7 +182,7 @@ class ZEOStorage:
caller = sys._getframe().f_back.f_code.co_name caller = sys._getframe().f_back.f_code.co_name
self.log("%s(%s) invalid; current transaction = %s" % self.log("%s(%s) invalid; current transaction = %s" %
(caller, repr(tid), repr(self.transaction.id)), (caller, repr(tid), repr(self.transaction.id)),
zLOG.PROBLEM) logging.WARNING)
if exc is not None: if exc is not None:
raise exc(self.transaction.id, tid) raise exc(self.transaction.id, tid)
else: else:
...@@ -412,7 +421,7 @@ class ZEOStorage: ...@@ -412,7 +421,7 @@ class ZEOStorage:
self.locked = 0 self.locked = 0
self.timeout.end(self) self.timeout.end(self)
self.stats.lock_time = None self.stats.lock_time = None
self.log("Transaction released storage lock", zLOG.BLATHER) self.log("Transaction released storage lock", BLATHER)
# _handle_waiting() can start another transaction (by # _handle_waiting() can start another transaction (by
# restarting a waiting one) so must be done last # restarting a waiting one) so must be done last
self._handle_waiting() self._handle_waiting()
...@@ -494,13 +503,11 @@ class ZEOStorage: ...@@ -494,13 +503,11 @@ class ZEOStorage:
if isinstance(err, ConflictError): if isinstance(err, ConflictError):
self.stats.conflicts += 1 self.stats.conflicts += 1
self.log("conflict error oid=%s msg=%s" % self.log("conflict error oid=%s msg=%s" %
(oid_repr(oid), str(err)), zLOG.BLATHER) (oid_repr(oid), str(err)), BLATHER)
if not isinstance(err, TransactionError): if not isinstance(err, TransactionError):
# Unexpected errors are logged and passed to the client # Unexpected errors are logged and passed to the client
exc_info = sys.exc_info() self.log("store error: %s, %s" % sys.exc_info()[:2],
self.log("store error: %s, %s" % exc_info[:2], logging.ERROR, exc_info=True)
zLOG.ERROR, error=exc_info)
del exc_info
# Try to pickle the exception. If it can't be pickled, # Try to pickle the exception. If it can't be pickled,
# the RPC response would fail, so use something else. # the RPC response would fail, so use something else.
pickler = cPickle.Pickler() pickler = cPickle.Pickler()
...@@ -509,7 +516,7 @@ class ZEOStorage: ...@@ -509,7 +516,7 @@ class ZEOStorage:
pickler.dump(err, 1) pickler.dump(err, 1)
except: except:
msg = "Couldn't pickle storage exception: %s" % repr(err) msg = "Couldn't pickle storage exception: %s" % repr(err)
self.log(msg, zLOG.ERROR) self.log(msg, logging.ERROR)
err = StorageServerError(msg) err = StorageServerError(msg)
# The exception is reported back as newserial for this oid # The exception is reported back as newserial for this oid
newserial = err newserial = err
...@@ -518,7 +525,7 @@ class ZEOStorage: ...@@ -518,7 +525,7 @@ class ZEOStorage:
self.invalidated.append((oid, version)) self.invalidated.append((oid, version))
if newserial == ResolvedSerial: if newserial == ResolvedSerial:
self.stats.conflicts_resolved += 1 self.stats.conflicts_resolved += 1
self.log("conflict resolved oid=%s" % oid_repr(oid), zLOG.BLATHER) self.log("conflict resolved oid=%s" % oid_repr(oid), BLATHER)
self.serials.append((oid, newserial)) self.serials.append((oid, newserial))
return err is None return err is None
...@@ -572,7 +579,7 @@ class ZEOStorage: ...@@ -572,7 +579,7 @@ class ZEOStorage:
"Clients waiting: %d." % len(self.storage._waiting)) "Clients waiting: %d." % len(self.storage._waiting))
return d return d
else: else:
self.log("Transaction acquired storage lock.", zLOG.BLATHER) self.log("Transaction acquired storage lock.", BLATHER)
return self._restart() return self._restart()
def _restart(self, delay=None): def _restart(self, delay=None):
...@@ -582,7 +589,7 @@ class ZEOStorage: ...@@ -582,7 +589,7 @@ class ZEOStorage:
else: else:
template = "Preparing to commit transaction: %d objects, %d bytes" template = "Preparing to commit transaction: %d objects, %d bytes"
self.log(template % (self.txnlog.stores, self.txnlog.size()), self.log(template % (self.txnlog.stores, self.txnlog.size()),
level=zLOG.BLATHER) level=BLATHER)
self._tpc_begin(self.transaction, self.tid, self.status) self._tpc_begin(self.transaction, self.tid, self.status)
loads, loader = self.txnlog.get_loader() loads, loader = self.txnlog.get_loader()
for i in range(loads): for i in range(loads):
...@@ -615,7 +622,7 @@ class ZEOStorage: ...@@ -615,7 +622,7 @@ class ZEOStorage:
zeo_storage._restart(delay) zeo_storage._restart(delay)
except: except:
self.log("Unexpected error handling waiting transaction", self.log("Unexpected error handling waiting transaction",
level=zLOG.WARNING, error=sys.exc_info()) level=logging.WARNING, exc_info=True)
zeo_storage.connection.close() zeo_storage.connection.close()
return 0 return 0
else: else:
...@@ -794,7 +801,7 @@ class StorageServer: ...@@ -794,7 +801,7 @@ class StorageServer:
zstorage = self.ZEOStorageClass(self, self.read_only) zstorage = self.ZEOStorageClass(self, self.read_only)
c = self.ManagedServerConnectionClass(sock, addr, zstorage, self) c = self.ManagedServerConnectionClass(sock, addr, zstorage, self)
log("new connection %s: %s" % (addr, `c`)) log("new connection %s: %s" % (addr, repr(c)))
return c return c
def register_connection(self, storage_id, conn): def register_connection(self, storage_id, conn):
......
...@@ -13,16 +13,16 @@ ...@@ -13,16 +13,16 @@
############################################################################## ##############################################################################
"""Monitor behavior of ZEO server and record statistics. """Monitor behavior of ZEO server and record statistics.
$Id: monitor.py,v 1.5 2003/11/28 16:44:47 jim Exp $ $Id: monitor.py,v 1.6 2004/04/25 11:34:15 gintautasm Exp $
""" """
import asyncore import asyncore
import socket import socket
import time import time
import types import types
import logging
import ZEO import ZEO
import zLOG
class StorageStats: class StorageStats:
"""Per-storage usage statistics.""" """Per-storage usage statistics."""
...@@ -129,7 +129,8 @@ class StatsServer(asyncore.dispatcher): ...@@ -129,7 +129,8 @@ class StatsServer(asyncore.dispatcher):
else: else:
self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.set_reuse_addr() self.set_reuse_addr()
zLOG.LOG("ZSM", zLOG.INFO, "monitor listening on %s" % repr(self.addr)) logger = logging.getLogger('ZEO.monitor')
logger.info("listening on %s", repr(self.addr))
self.bind(self.addr) self.bind(self.addr)
self.listen(5) self.listen(5)
......
...@@ -36,17 +36,27 @@ import os ...@@ -36,17 +36,27 @@ import os
import sys import sys
import signal import signal
import socket import socket
import logging
import ZConfig, ZConfig.datatypes import ZConfig, ZConfig.datatypes
import zLOG
import ZEO import ZEO
from zdaemon.zdoptions import ZDOptions from zdaemon.zdoptions import ZDOptions
logger = logging.getLogger('ZEO.runzeo')
_pid = str(os.getpid())
def log(msg, level=logging.INFO, exc_info=False):
"""Internal: generic logging function."""
message = "(%s) %s" % (_pid, msg)
logger.log(level, message, exc_info=exc_info)
def parse_address(arg): def parse_address(arg):
# XXX Not part of the official ZConfig API # XXX Not part of the official ZConfig API
obj = ZConfig.datatypes.SocketAddress(arg) obj = ZConfig.datatypes.SocketAddress(arg)
return obj.family, obj.address return obj.family, obj.address
class ZEOOptionsMixin: class ZEOOptionsMixin:
storages = None storages = None
...@@ -129,7 +139,6 @@ class ZEOServer: ...@@ -129,7 +139,6 @@ class ZEOServer:
if self.options.config_logger is not None: if self.options.config_logger is not None:
return return
# No log file is configured; default to stderr. # No log file is configured; default to stderr.
import logging
logger = logging.getLogger() logger = logging.getLogger()
handler = logging.StreamHandler() handler = logging.StreamHandler()
handler.setLevel(logging.INFO) handler.setLevel(logging.INFO)
...@@ -160,7 +169,7 @@ class ZEOServer: ...@@ -160,7 +169,7 @@ class ZEOServer:
def open_storages(self): def open_storages(self):
self.storages = {} self.storages = {}
for opener in self.options.storages: for opener in self.options.storages:
info("opening storage %r using %s" log("opening storage %r using %s"
% (opener.name, opener.__class__.__name__)) % (opener.name, opener.__class__.__name__))
self.storages[opener.name] = opener.open() self.storages[opener.name] = opener.open()
...@@ -202,33 +211,31 @@ class ZEOServer: ...@@ -202,33 +211,31 @@ class ZEOServer:
ThreadedAsync.LoopCallback.loop() ThreadedAsync.LoopCallback.loop()
def handle_sigterm(self): def handle_sigterm(self):
info("terminated by SIGTERM") log("terminated by SIGTERM")
sys.exit(0) sys.exit(0)
def handle_sigint(self): def handle_sigint(self):
info("terminated by SIGINT") log("terminated by SIGINT")
sys.exit(0) sys.exit(0)
def handle_sighup(self): def handle_sighup(self):
info("restarted by SIGHUP") log("restarted by SIGHUP")
sys.exit(1) sys.exit(1)
def handle_sigusr2(self): def handle_sigusr2(self):
# This requires a modern zLOG (from Zope 2.6 or later); older # XXX this used to reinitialize zLOG. How do I achieve
# zLOG packages don't have the initialize() method # the same effect with Python's logging package?
info("reinitializing zLOG") # Should we restart as with SIGHUP?
# XXX Shouldn't this be below with _log()? log("received SIGUSR2, but it was not handled!", level=logging.WARNING)
import zLOG
zLOG.initialize()
info("reinitialized zLOG")
def close_storages(self): def close_storages(self):
for name, storage in self.storages.items(): for name, storage in self.storages.items():
info("closing storage %r" % name) log("closing storage %r" % name)
try: try:
storage.close() storage.close()
except: # Keep going except: # Keep going
exception("failed to close storage %r" % name) log("failed to close storage %r" % name,
level=logging.EXCEPTION, exc_info=True)
# Signal names # Signal names
...@@ -257,43 +264,6 @@ def init_signames(): ...@@ -257,43 +264,6 @@ def init_signames():
signames[sig] = name signames[sig] = name
# Log messages with various severities.
# This uses zLOG, but the API is a simplified version of PEP 282
def critical(msg):
"""Log a critical message."""
_log(msg, zLOG.PANIC)
def error(msg):
"""Log an error message."""
_log(msg, zLOG.ERROR)
def exception(msg):
"""Log an exception (an error message with a traceback attached)."""
_log(msg, zLOG.ERROR, error=sys.exc_info())
def warn(msg):
"""Log a warning message."""
_log(msg, zLOG.PROBLEM)
def info(msg):
"""Log an informational message."""
_log(msg, zLOG.INFO)
def debug(msg):
"""Log a debugging message."""
_log(msg, zLOG.DEBUG)
# XXX It would be nice if a program that extended this one (like
# runzrs) could change the label.
_label = "RUNZEO:%d" % os.getpid()
def _log(msg, severity=zLOG.INFO, error=None):
"""Internal: generic logging function."""
zLOG.LOG(_label, severity, msg, "", error)
# Main program # Main program
def main(args=None): def main(args=None):
......
...@@ -19,8 +19,7 @@ import random ...@@ -19,8 +19,7 @@ import random
import asyncore import asyncore
import tempfile import tempfile
import threading import threading
import logging
import zLOG
import ZEO.ServerStub import ZEO.ServerStub
from ZEO.ClientStorage import ClientStorage from ZEO.ClientStorage import ClientStorage
...@@ -38,6 +37,8 @@ from ZODB.tests.StorageTestBase \ ...@@ -38,6 +37,8 @@ from ZODB.tests.StorageTestBase \
import transaction import transaction
from transaction import Transaction from transaction import Transaction
logger = logging.getLogger('ZEO.tests.ConnectionTests')
ZERO = '\0'*8 ZERO = '\0'*8
class TestServerStub(ZEO.ServerStub.StorageServer): class TestServerStub(ZEO.ServerStub.StorageServer):
...@@ -91,7 +92,7 @@ class CommonSetupTearDown(StorageTestBase): ...@@ -91,7 +92,7 @@ class CommonSetupTearDown(StorageTestBase):
for i in 1, 2, ... for i in 1, 2, ...
""" """
self.__super_setUp() self.__super_setUp()
zLOG.LOG("testZEO", zLOG.INFO, "setUp() %s" % self.id()) logging.info("setUp() %s", self.id())
self.file = tempfile.mktemp() self.file = tempfile.mktemp()
self.addr = [] self.addr = []
self._pids = [] self._pids = []
...@@ -103,13 +104,13 @@ class CommonSetupTearDown(StorageTestBase): ...@@ -103,13 +104,13 @@ class CommonSetupTearDown(StorageTestBase):
def tearDown(self): def tearDown(self):
"""Try to cause the tests to halt""" """Try to cause the tests to halt"""
zLOG.LOG("testZEO", zLOG.INFO, "tearDown() %s" % self.id()) logging.info("tearDown() %s" % self.id())
for p in self.conf_paths: for p in self.conf_paths:
os.remove(p) os.remove(p)
if getattr(self, '_storage', None) is not None: if getattr(self, '_storage', None) is not None:
self._storage.close() self._storage.close()
if hasattr(self._storage, 'cleanup'): if hasattr(self._storage, 'cleanup'):
zLOG.LOG("testZEO", zLOG.DEBUG, "cleanup storage %s" % logging.debug("cleanup storage %s" %
self._storage.__name__) self._storage.__name__)
self._storage.cleanup() self._storage.cleanup()
for adminaddr in self._servers: for adminaddr in self._servers:
...@@ -191,8 +192,7 @@ class CommonSetupTearDown(StorageTestBase): ...@@ -191,8 +192,7 @@ class CommonSetupTearDown(StorageTestBase):
def startServer(self, create=1, index=0, read_only=0, ro_svr=0, keep=None): def startServer(self, create=1, index=0, read_only=0, ro_svr=0, keep=None):
addr = self.addr[index] addr = self.addr[index]
zLOG.LOG("testZEO", zLOG.INFO, logging.info("startServer(create=%d, index=%d, read_only=%d) @ %s" %
"startServer(create=%d, index=%d, read_only=%d) @ %s" %
(create, index, read_only, addr)) (create, index, read_only, addr))
path = "%s.%d" % (self.file, index) path = "%s.%d" % (self.file, index)
sconf = self.getConfig(path, create, read_only) sconf = self.getConfig(path, create, read_only)
...@@ -206,7 +206,7 @@ class CommonSetupTearDown(StorageTestBase): ...@@ -206,7 +206,7 @@ class CommonSetupTearDown(StorageTestBase):
self._servers.append(adminaddr) self._servers.append(adminaddr)
def shutdownServer(self, index=0): def shutdownServer(self, index=0):
zLOG.LOG("testZEO", zLOG.INFO, "shutdownServer(index=%d) @ %s" % logging.info("shutdownServer(index=%d) @ %s" %
(index, self._servers[index])) (index, self._servers[index]))
adminaddr = self._servers[index] adminaddr = self._servers[index]
if adminaddr is not None: if adminaddr is not None:
...@@ -450,11 +450,9 @@ class ConnectionTests(CommonSetupTearDown): ...@@ -450,11 +450,9 @@ class ConnectionTests(CommonSetupTearDown):
oid = self._storage.new_oid() oid = self._storage.new_oid()
obj = MinPO(12) obj = MinPO(12)
self._dostore(oid, data=obj) self._dostore(oid, data=obj)
zLOG.LOG("checkReconnection", zLOG.INFO, logging.info("checkReconnection(): About to shutdown server")
"About to shutdown server")
self.shutdownServer() self.shutdownServer()
zLOG.LOG("checkReconnection", zLOG.INFO, logging.info("checkReconnection(): About to restart server")
"About to restart server")
self.startServer(create=0) self.startServer(create=0)
oid = self._storage.new_oid() oid = self._storage.new_oid()
obj = MinPO(12) obj = MinPO(12)
...@@ -464,13 +462,12 @@ class ConnectionTests(CommonSetupTearDown): ...@@ -464,13 +462,12 @@ class ConnectionTests(CommonSetupTearDown):
break break
except ClientDisconnected: except ClientDisconnected:
# Maybe the exception mess is better now # Maybe the exception mess is better now
zLOG.LOG("checkReconnection", zLOG.INFO, logging.info("checkReconnection(): Error after"
"Error after server restart; retrying.", " server restart; retrying.", exc_info=True)
error=sys.exc_info())
transaction.abort() transaction.abort()
# Give the other thread a chance to run. # Give the other thread a chance to run.
time.sleep(0.1) time.sleep(0.1)
zLOG.LOG("checkReconnection", zLOG.INFO, "finished") logging.info("checkReconnection(): finished")
self._storage.close() self._storage.close()
def checkBadMessage1(self): def checkBadMessage1(self):
...@@ -832,7 +829,7 @@ class ReconnectionTests(CommonSetupTearDown): ...@@ -832,7 +829,7 @@ class ReconnectionTests(CommonSetupTearDown):
self.pollDown() self.pollDown()
self._storage.verify_result = None self._storage.verify_result = None
perstorage.verify_result = None perstorage.verify_result = None
zLOG.LOG("testZEO", zLOG.INFO, '2ALLBEEF') logging.info('2ALLBEEF')
self.startServer(create=0, keep=0) self.startServer(create=0, keep=0)
self.pollUp() self.pollUp()
self.pollUp(storage=perstorage) self.pollUp(storage=perstorage)
......
...@@ -21,8 +21,9 @@ import socket ...@@ -21,8 +21,9 @@ import socket
import logging import logging
import StringIO import StringIO
import tempfile import tempfile
import logging
import zLOG logger = logging.getLogger('ZEO.tests.forker')
class ZEOConfig: class ZEOConfig:
"""Class to generate ZEO configuration file. """ """Class to generate ZEO configuration file. """
...@@ -143,19 +144,19 @@ def start_zeo_server(storage_conf, zeo_conf, port, keep=0): ...@@ -143,19 +144,19 @@ def start_zeo_server(storage_conf, zeo_conf, port, keep=0):
for i in range(120): for i in range(120):
time.sleep(0.25) time.sleep(0.25)
try: try:
zLOG.LOG('forker', zLOG.DEBUG, 'connect %s' % i) logger.debug('connect %s', i)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(adminaddr) s.connect(adminaddr)
ack = s.recv(1024) ack = s.recv(1024)
s.close() s.close()
zLOG.LOG('forker', zLOG.DEBUG, 'acked: %s' % ack) logging.debug('acked: %s' % ack)
break break
except socket.error, e: except socket.error, e:
if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET): if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET):
raise raise
s.close() s.close()
else: else:
zLOG.LOG('forker', zLOG.DEBUG, 'boo hoo') logging.debug('boo hoo')
raise raise
return ('localhost', port), adminaddr, pid, tmpfile return ('localhost', port), adminaddr, pid, tmpfile
...@@ -187,5 +188,5 @@ def shutdown_zeo_server(adminaddr): ...@@ -187,5 +188,5 @@ def shutdown_zeo_server(adminaddr):
if e[0] == errno.ECONNRESET: if e[0] == errno.ECONNRESET:
raise raise
ack = 'no ack received' ack = 'no ack received'
zLOG.LOG('shutdownServer', zLOG.DEBUG, 'acked: %s' % ack) logger.debug('shutdown_zeo_server(): acked: %s' % ack)
s.close() s.close()
...@@ -20,16 +20,13 @@ import socket ...@@ -20,16 +20,13 @@ import socket
import asyncore import asyncore
import tempfile import tempfile
import unittest import unittest
import logging
# Zope/ZODB3 imports
import zLOG
# ZODB test support # ZODB test support
import ZODB import ZODB
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle from ZODB.tests.StorageTestBase import zodb_unpickle
# ZODB test mixin classes # ZODB test mixin classes
from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \ from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \
TransactionalUndoStorage, TransactionalUndoVersionStorage, \ TransactionalUndoStorage, TransactionalUndoVersionStorage, \
...@@ -39,6 +36,8 @@ from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \ ...@@ -39,6 +36,8 @@ from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \
from ZEO.ClientStorage import ClientStorage from ZEO.ClientStorage import ClientStorage
from ZEO.tests import forker, Cache, CommitLockTests, ThreadTests from ZEO.tests import forker, Cache, CommitLockTests, ThreadTests
logger = logging.getLogger('ZEO.tests.testZEO')
class DummyDB: class DummyDB:
def invalidate(self, *args): def invalidate(self, *args):
pass pass
...@@ -113,7 +112,7 @@ class GenericTests( ...@@ -113,7 +112,7 @@ class GenericTests(
"""Combine tests from various origins in one class.""" """Combine tests from various origins in one class."""
def setUp(self): def setUp(self):
zLOG.LOG("testZEO", zLOG.INFO, "setUp() %s" % self.id()) logger.info("setUp() %s", self.id()) # XXX is this really needed?
port = get_port() port = get_port()
zconf = forker.ZEOConfig(('', port)) zconf = forker.ZEOConfig(('', port))
zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(), zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(),
......
...@@ -22,9 +22,10 @@ import socket ...@@ -22,9 +22,10 @@ import socket
import signal import signal
import asyncore import asyncore
import threading import threading
import logging
import ThreadedAsync.LoopCallback import ThreadedAsync.LoopCallback
import zLOG
from ZEO.StorageServer import StorageServer from ZEO.StorageServer import StorageServer
from ZEO.runzeo import ZEOOptions from ZEO.runzeo import ZEOOptions
...@@ -38,9 +39,11 @@ def cleanup(storage): ...@@ -38,9 +39,11 @@ def cleanup(storage):
except AttributeError: except AttributeError:
pass pass
logger = logging.getLogger('ZEO.tests.zeoserver')
def log(label, msg, *args): def log(label, msg, *args):
zLOG.LOG(label, zLOG.DEBUG, msg % args) message = "(%s) %s" % (label, msg)
logger.debug(message, args)
class ZEOTestServer(asyncore.dispatcher): class ZEOTestServer(asyncore.dispatcher):
...@@ -67,8 +70,7 @@ class ZEOTestServer(asyncore.dispatcher): ...@@ -67,8 +70,7 @@ class ZEOTestServer(asyncore.dispatcher):
self._keep = keep self._keep = keep
# Count down to zero, the number of connects # Count down to zero, the number of connects
self._count = 1 self._count = 1
# For zLOG self._label ='%d @ %s' % (os.getpid(), addr)
self._label ='zeoserver:%d @ %s' % (os.getpid(), addr)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
# Some ZEO tests attempt a quick start of the server using the same # Some ZEO tests attempt a quick start of the server using the same
# port so we have to set the reuse flag. # port so we have to set the reuse flag.
...@@ -126,7 +128,7 @@ class Suicide(threading.Thread): ...@@ -126,7 +128,7 @@ class Suicide(threading.Thread):
# as long as 300 seconds. Set this timeout to 330 to minimize # as long as 300 seconds. Set this timeout to 330 to minimize
# chance that the server gives up before the clients. # chance that the server gives up before the clients.
time.sleep(330) time.sleep(330)
log("zeoserver", "suicide thread invoking shutdown") log(str(os.getpid()), "suicide thread invoking shutdown")
# If the server hasn't shut down yet, the client may not be # If the server hasn't shut down yet, the client may not be
# able to connect to it. If so, try to kill the process to # able to connect to it. If so, try to kill the process to
...@@ -146,8 +148,8 @@ class Suicide(threading.Thread): ...@@ -146,8 +148,8 @@ class Suicide(threading.Thread):
def main(): def main():
global pid global pid
pid = os.getpid() pid = os.getpid()
label = 'zeoserver:%d' % pid label = str(pid)
log(label, 'starting') log(label, "starting")
# We don't do much sanity checking of the arguments, since if we get it # We don't do much sanity checking of the arguments, since if we get it
# wrong, it's a bug in the test suite. # wrong, it's a bug in the test suite.
......
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