Commit 3428da3c authored by Julien Muchembled's avatar Julien Muchembled

logger: new RTMIN+1 signal to reopen the log

RTMIN+1 & RTMIN+2 signals, which were previously used for debugging,
have been remapped to RTMIN+2 & RTMIN+3

No journal on disk anymore because this is incompatible with the
rename+reopen way to rotate logs, and we want to support logrotate.
Of course in case of crash the log may be corrupt or entries may be lost,
but we currenty don't think NEO logs would be useful to debug such failure.
parent 17fc0ef9
......@@ -22,9 +22,9 @@ import sys
from functools import wraps
import neo
# kill -RTMIN+1 <pid>
# Dump information to logs.
# kill -RTMIN+2 <pid>
# Dump information to logs.
# kill -RTMIN+3 <pid>
# Loads (or reloads) neo.debug module.
# The content is up to you (it's only imported). It can be a breakpoint.
......@@ -89,5 +89,5 @@ def register(on_log=None):
def on_log_signal(signum, signal):
signal.signal(signal.SIGRTMIN+1, on_log_signal)
signal.signal(signal.SIGRTMIN+2, debugHandler)
signal.signal(signal.SIGRTMIN+2, on_log_signal)
signal.signal(signal.SIGRTMIN+3, debugHandler)
......@@ -96,6 +96,18 @@ class NEOLogger(Logger):
return wraps(wrapped)(wrapper)
def reopen(self):
if self._db is None:
q = self._db.execute
if not q("SELECT id FROM packet LIMIT 1").fetchone():
q("DROP TABLE protocol")
# DROP TABLE already replaced previous data with zeros,
# so VACUUM is not really useful. But here, it should be free.
self._setup(q("PRAGMA database_list").fetchone()[2])
def flush(self):
if self._db is None:
......@@ -151,6 +163,8 @@ class NEOLogger(Logger):
q = self._db.execute
if self._max_size is None:
q("PRAGMA synchronous = OFF")
if 1: # Not only when logging everything,
# but also for interoperability with logrotate.
q("PRAGMA journal_mode = MEMORY")
if reset:
for t in 'log', 'packet':
......@@ -185,8 +199,12 @@ class NEOLogger(Logger):
if p == t:
t = self._record_queue[0].created
except IndexError:
t = time()
with self._db:
q("INSERT INTO protocol VALUES (?,?)", (time(), p))
q("INSERT INTO protocol VALUES (?,?)", (t, p))
def setup(self, filename=None, reset=False):
with self:
......@@ -254,3 +272,4 @@ class NEOLogger(Logger):
logging = NEOLogger()
signal.signal(signal.SIGRTMIN, lambda signum, frame: logging.flush())
signal.signal(signal.SIGRTMIN+1, lambda signum, frame: logging.reopen())
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