Commit 573a3dd4 authored by Jim Fulton's avatar Jim Fulton

Integrated with zLOG.

parent 364674cc
...@@ -4,9 +4,12 @@ from smac import smac ...@@ -4,9 +4,12 @@ from smac import smac
from ZODB import POSException from ZODB import POSException
from ZODB.Transaction import Transaction from ZODB.Transaction import Transaction
import traceback import traceback
from zLOG import LOG, INFO, ERROR
class StorageServerError(POSException.StorageError): pass class StorageServerError(POSException.StorageError): pass
def blather(*args):
LOG('ZEO Server', INFO, string.join(args))
class StorageServer(asyncore.dispatcher): class StorageServer(asyncore.dispatcher):
...@@ -71,6 +74,13 @@ class StorageServer(asyncore.dispatcher): ...@@ -71,6 +74,13 @@ class StorageServer(asyncore.dispatcher):
Connection(self, sock, addr) Connection(self, sock, addr)
def log_info(self, message, type='info'):
if type=='error': type=ERROR
else: type=INFO
LOG('ZEO Server', type, message)
log=log_info
storage_methods={} storage_methods={}
for n in ('get_info', 'abortVersion', 'commitVersion', 'history', for n in ('get_info', 'abortVersion', 'commitVersion', 'history',
'load', 'modifiedInVersion', 'new_oid', 'pack', 'store', 'load', 'modifiedInVersion', 'new_oid', 'pack', 'store',
...@@ -107,7 +117,7 @@ class Connection(smac): ...@@ -107,7 +117,7 @@ class Connection(smac):
if __debug__: if __debug__:
m=`message` m=`message`
if len(m) > 60: m=m[:60]+' ...' if len(m) > 60: m=m[:60]+' ...'
print 'message_input', m blather('message_input', m)
if self.__storage is None: if self.__storage is None:
self.__storage, self.__storage_id = ( self.__storage, self.__storage_id = (
...@@ -121,7 +131,7 @@ class Connection(smac): ...@@ -121,7 +131,7 @@ class Connection(smac):
if __debug__: if __debug__:
m=`tuple(args)` m=`tuple(args)`
if len(m) > 60: m=m[:60]+' ...' if len(m) > 60: m=m[:60]+' ...'
print 'call: %s%s' % (name, m) blather('call: %s%s' % (name, m))
if not storage_method(name): if not storage_method(name):
raise 'Invalid Method Name', name raise 'Invalid Method Name', name
...@@ -131,7 +141,7 @@ class Connection(smac): ...@@ -131,7 +141,7 @@ class Connection(smac):
r=apply(getattr(self.__storage, name), args) r=apply(getattr(self.__storage, name), args)
if r is _noreturn: return if r is _noreturn: return
except: except:
traceback.print_exc() LOG('ZEO Server', ERROR, 'error', error=sys.exc_info())
t, r = sys.exc_info()[:2] t, r = sys.exc_info()[:2]
if type(r) is not type(self): r=t,r if type(r) is not type(self): r=t,r
rt='E' rt='E'
...@@ -139,7 +149,7 @@ class Connection(smac): ...@@ -139,7 +149,7 @@ class Connection(smac):
if __debug__: if __debug__:
m=`r` m=`r`
if len(m) > 60: m=m[:60]+' ...' if len(m) > 60: m=m[:60]+' ...'
print '%s: %s' % (rt, m) blather('%s: %s' % (rt, m))
r=cPickle.dumps(r,1) r=cPickle.dumps(r,1)
self.message_output(rt+r) self.message_output(rt+r)
...@@ -271,7 +281,7 @@ class Connection(smac): ...@@ -271,7 +281,7 @@ class Connection(smac):
if __name__=='__main__': if __name__=='__main__':
import ZODB.FileStorage import ZODB.FileStorage
name, port = sys.argv[1:3] name, port = sys.argv[1:3]
print name, port blather(name, port)
try: port='',string.atoi(port) try: port='',string.atoi(port)
except: pass except: pass
StorageServer(port, ZODB.FileStorage.FileStorage(name)) StorageServer(port, ZODB.FileStorage.FileStorage(name))
......
"""Sized message async connections """Sized message async connections
""" """
import asyncore, string, struct import asyncore, string, struct, zLOG
from zLOG import LOG, INFO, ERROR
class smac(asyncore.dispatcher): class smac(asyncore.dispatcher):
...@@ -64,5 +65,12 @@ class smac(asyncore.dispatcher): ...@@ -64,5 +65,12 @@ class smac(asyncore.dispatcher):
if __debug__: if __debug__:
if len(message) > 40: m=message[:40]+' ...' if len(message) > 40: m=message[:40]+' ...'
else: m=message else: m=message
print 'message_output', `m` LOG('smax', INFO, 'message_output %s' % `m`)
self.__append(pack(">i",len(message))+message) self.__append(pack(">i",len(message))+message)
def log_info(self, message, type='info'):
if type=='error': type=ERROR
else: type=INFO
LOG('ZEO Server', type, message)
log=log_info
"""Sized message async connections """Sized message async connections
""" """
import asyncore, string, struct import asyncore, string, struct, zLOG
from zLOG import LOG, INFO, ERROR
class smac(asyncore.dispatcher): class smac(asyncore.dispatcher):
...@@ -64,5 +65,12 @@ class smac(asyncore.dispatcher): ...@@ -64,5 +65,12 @@ class smac(asyncore.dispatcher):
if __debug__: if __debug__:
if len(message) > 40: m=message[:40]+' ...' if len(message) > 40: m=message[:40]+' ...'
else: m=message else: m=message
print 'message_output', `m` LOG('smax', INFO, 'message_output %s' % `m`)
self.__append(pack(">i",len(message))+message) self.__append(pack(">i",len(message))+message)
def log_info(self, message, type='info'):
if type=='error': type=ERROR
else: type=INFO
LOG('ZEO Server', type, message)
log=log_info
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