thread-safe and fully buffered logging

Uses own thread to actually write to logs, so the main thread can't be
blocked by a slow logfile. Log entries are buffered in two ringbuffers,
one for the main thread and one for all other threads. The main thread
will copy the second buffer to the main buffer periodically. The main
thread buffer is read from the log worker thread.

Since two buffers are kept, there are now several functions to add a log
entry:

  mlog()
    for main thread functions only: will never block

  tlog()
    other threads only: may block, until main thread copied some entries

  xlog()
    automatically determines, which thread it's been called from and
    then writes to the proper buffer (will block accordingly)

To avoid improper usage, mlog and tlog verify, if they are used correctly.
(Only for debug builds. An assert triggers, if necessary.)
This commit is contained in:
ac-stef
2017-06-27 15:15:23 +02:00
parent dd295bb54a
commit 035d7caf2f
11 changed files with 285 additions and 190 deletions
+1 -6
View File
@@ -214,12 +214,7 @@ void output(client &c, const char *msg, int len = 0)
void outputf(client &c, const char *fmt, ...)
{
string msg;
va_list args;
va_start(args, fmt);
vformatstring(msg, fmt, args);
va_end(args);
defvformatstring(msg, fmt, fmt);
output(c, msg);
}