--- deliantra/server/common/logger.C 2010/04/11 17:27:51 1.24 +++ deliantra/server/common/logger.C 2012/01/03 11:25:31 1.28 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -40,12 +40,14 @@ int flags; }; +typedef std::vector > logvector; + static SMUTEX(mutex); static SMUTEX(fdlock); static SCOND(cond); static int logfd = STDERR_FILENO; static int logsync = 1; -static std::vector > queue; +static logvector queue; int log_setfd (int fd) { @@ -57,24 +59,26 @@ return old; } -#define PREFIX_LEN sizeof ("0000-00-00 00:00:00.0000+") - 1 +#define PREFIX_LEN sizeof ("0000-00-00 00:00:00.0000 L+") - 1 static void log_sync (logline &line) { + static const char levelchar [16+1] = "EWIDt???????????"; struct tm lt; char pfx [PREFIX_LEN]; localtime_r (&line.tv.tv_sec, <); - sprintf (pfx, "%04d-%02d-%02d %02d:%02d:%02d.%04d", + sprintf (pfx, "%04d-%02d-%02d %02d:%02d:%02d.%04d %c", lt.tm_year + 1900, lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec, - (int)(line.tv.tv_usec / 100) + (int)(line.tv.tv_usec / 100), + levelchar [line.flags & 15] ); pfx [PREFIX_LEN - 1] = line.flags & logSync ? '=' : ' '; @@ -133,7 +137,11 @@ // we have bigger problems. if (idx == queue.size ()) { - queue.clear (); + if (idx < 32) + queue.clear (); + else + logvector ().swap (queue); // free memory, hopefully + idx = 0; } @@ -147,6 +155,7 @@ log_cleanup () { logsync = 1; + SMUTEX_UNLOCK (fdlock); for (;;) {