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 ...@@ -22,9 +22,9 @@ import sys
from functools import wraps from functools import wraps
import neo import neo
# kill -RTMIN+1 <pid>
# Dump information to logs.
# kill -RTMIN+2 <pid> # kill -RTMIN+2 <pid>
# Dump information to logs.
# kill -RTMIN+3 <pid>
# Loads (or reloads) neo.debug module. # Loads (or reloads) neo.debug module.
# The content is up to you (it's only imported). It can be a breakpoint. # The content is up to you (it's only imported). It can be a breakpoint.
...@@ -89,5 +89,5 @@ def register(on_log=None): ...@@ -89,5 +89,5 @@ def register(on_log=None):
@safe_handler @safe_handler
def on_log_signal(signum, signal): def on_log_signal(signum, signal):
on_log() on_log()
signal.signal(signal.SIGRTMIN+1, on_log_signal) signal.signal(signal.SIGRTMIN+2, on_log_signal)
signal.signal(signal.SIGRTMIN+2, debugHandler) signal.signal(signal.SIGRTMIN+3, debugHandler)
...@@ -96,6 +96,18 @@ class NEOLogger(Logger): ...@@ -96,6 +96,18 @@ class NEOLogger(Logger):
self._release() self._release()
return wraps(wrapped)(wrapper) 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 @__async
def flush(self): def flush(self):
if self._db is None: if self._db is None:
...@@ -151,6 +163,8 @@ class NEOLogger(Logger): ...@@ -151,6 +163,8 @@ class NEOLogger(Logger):
q = self._db.execute q = self._db.execute
if self._max_size is None: if self._max_size is None:
q("PRAGMA synchronous = OFF") q("PRAGMA synchronous = OFF")
if 1: # Not only when logging everything,
# but also for interoperability with logrotate.
q("PRAGMA journal_mode = MEMORY") q("PRAGMA journal_mode = MEMORY")
if reset: if reset:
for t in 'log', 'packet': for t in 'log', 'packet':
...@@ -185,8 +199,12 @@ class NEOLogger(Logger): ...@@ -185,8 +199,12 @@ class NEOLogger(Logger):
if p == t: if p == t:
break break
else: else:
try:
t = self._record_queue[0].created
except IndexError:
t = time()
with self._db: with self._db:
q("INSERT INTO protocol VALUES (?,?)", (time(), p)) q("INSERT INTO protocol VALUES (?,?)", (t, p))
def setup(self, filename=None, reset=False): def setup(self, filename=None, reset=False):
with self: with self:
...@@ -254,3 +272,4 @@ class NEOLogger(Logger): ...@@ -254,3 +272,4 @@ class NEOLogger(Logger):
logging = NEOLogger() logging = NEOLogger()
signal.signal(signal.SIGRTMIN, lambda signum, frame: logging.flush()) 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