Commit 24b1d024 by Julien Muchembled

logger: drop payload of big packets in unit tests

parent 51c4f647
...@@ -137,8 +137,9 @@ class NEOLogger(Logger): ...@@ -137,8 +137,9 @@ class NEOLogger(Logger):
return return
raise raise
def backlog(self, max_size=1<<24): def backlog(self, max_size=1<<24, max_packet=None):
with self: with self:
self._max_packet = max_packet
self._max_size = max_size self._max_size = max_size
if max_size is None: if max_size is None:
self.flush() self.flush()
...@@ -219,8 +220,11 @@ class NEOLogger(Logger): ...@@ -219,8 +220,11 @@ class NEOLogger(Logger):
ip, port = r.addr ip, port = r.addr
peer = '%s %s (%s:%u)' % ('>' if r.outgoing else '<', peer = '%s %s (%s:%u)' % ('>' if r.outgoing else '<',
uuid_str(r.uuid), ip, port) uuid_str(r.uuid), ip, port)
msg = r.msg
if msg is not None:
msg = buffer(msg)
self._db.execute("INSERT INTO packet VALUES (NULL,?,?,?,?,?,?)", self._db.execute("INSERT INTO packet VALUES (NULL,?,?,?,?,?,?)",
(r.created, r._name, r.msg_id, r.code, peer, buffer(r.msg))) (r.created, r._name, r.msg_id, r.code, peer, msg))
else: else:
pathname = os.path.relpath(r.pathname, *neo.__path__) pathname = os.path.relpath(r.pathname, *neo.__path__)
self._db.execute("INSERT INTO log VALUES (NULL,?,?,?,?,?,?)", self._db.execute("INSERT INTO log VALUES (NULL,?,?,?,?,?,?)",
...@@ -260,6 +264,9 @@ class NEOLogger(Logger): ...@@ -260,6 +264,9 @@ class NEOLogger(Logger):
def packet(self, connection, packet, outgoing): def packet(self, connection, packet, outgoing):
if self._db is not None: if self._db is not None:
body = packet._body
if self._max_packet and self._max_packet < len(body):
body = None
self._queue(PacketRecord( self._queue(PacketRecord(
created=time(), created=time(),
msg_id=packet._id, msg_id=packet._id,
...@@ -267,7 +274,7 @@ class NEOLogger(Logger): ...@@ -267,7 +274,7 @@ class NEOLogger(Logger):
outgoing=outgoing, outgoing=outgoing,
uuid=connection.getUUID(), uuid=connection.getUUID(),
addr=connection.getAddress(), addr=connection.getAddress(),
msg=packet._body)) msg=body))
logging = NEOLogger() logging = NEOLogger()
......
...@@ -67,7 +67,7 @@ IP_VERSION_FORMAT_DICT = { ...@@ -67,7 +67,7 @@ IP_VERSION_FORMAT_DICT = {
ADDRESS_TYPE = socket.AF_INET ADDRESS_TYPE = socket.AF_INET
logging.default_root_handler.handle = lambda record: None logging.default_root_handler.handle = lambda record: None
logging.backlog(None) logging.backlog(None, 1<<20)
debug.register() debug.register()
# prevent "signal only works in main thread" errors in subprocesses # prevent "signal only works in main thread" errors in subprocesses
......
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 sign in to comment