ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/logger.C
(Generate patch)

Comparing deliantra/server/common/logger.C (file contents):
Revision 1.11 by pippijn, Mon Jan 15 21:06:18 2007 UTC vs.
Revision 1.12 by root, Fri Apr 27 19:53:05 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
23 */ 23 */
24 24
25#include <stdarg.h> 25#include <cstdarg>
26#include <global.h> 26#include <global.h>
27#include <funcpoint.h> 27#include <funcpoint.h>
28 28
29/* 29void
30 * Logs a message to stderr, or to file, and/or even to socket. 30LOG (int flags, const char *format, ...)
31 * Or discards the message if it is of no importanse, and none have 31{
32 * asked to hear messages of that logLevel. 32 int level = flags & 15;
33 *
34 * See include/logger.h for possible logLevels. Messages with llevInfo
35 * and llevError are always printed, regardless of debug mode.
36 */
37 33
38void
39LOG (LogLevel logLevel, const char *format, ...)
40{
41 if (logLevel <= settings.debug) 34 if (level > settings.debug)
42 { 35 return;
43 char msec[20];
44 char buf[20460];
45 char tbuf[20480];
46 36
47 struct timeval tv; 37 char msec[20];
48 gettimeofday (&tv, 0); 38 char buf[20460];
49 struct tm *ptime = localtime (&tv.tv_sec); 39 char tbuf[20480];
50 40
51 strftime (tbuf, sizeof (tbuf), "%Y-%m-%d %H:%M:%S", ptime); 41 struct timeval tv;
52 sprintf (msec, ".%03d ", (int)(tv.tv_usec / 1000)); 42 gettimeofday (&tv, 0);
43 struct tm *ptime = localtime (&tv.tv_sec);
53 44
54 va_list ap; 45 strftime (tbuf, sizeof (tbuf), "%Y-%m-%d %H:%M:%S", ptime);
55 va_start (ap, format); 46 sprintf (msec, ".%03d ", (int)(tv.tv_usec / 1000));
56 vsnprintf (buf, sizeof (buf), format, ap);
57 va_end (ap);
58 47
59 strncat (tbuf, msec, sizeof (tbuf)); 48 va_list ap;
60 strncat (tbuf, buf, sizeof (tbuf)); 49 va_start (ap, format);
50 vsnprintf (buf, sizeof (buf), format, ap);
51 va_end (ap);
61 52
53 strncat (tbuf, msec, sizeof (tbuf));
54 strncat (tbuf, buf, sizeof (tbuf));
55
62 fputs (tbuf, logfile); 56 fputs (tbuf, logfile);
57 if (logfile != stderr)
63 fputs (tbuf, stderr); 58 fputs (tbuf, stderr);
64 } 59
60 if (flags & logBacktrace)
61 log_backtrace (tbuf);
65} 62}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines