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):
@safe_handler
def on_log_signal(signum, signal):
on_log()
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):
self._release()
return wraps(wrapped)(wrapper)
@__async
def reopen(self):
if self._db is None:
return
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.
q("VACUUM")
self._setup(q("PRAGMA database_list").fetchone()[2])
@__async
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:
break
else:
try:
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