File: Log.cpp

package info (click to toggle)
eris 1.2.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,360 kB
  • ctags: 1,348
  • sloc: sh: 8,289; cpp: 7,576; perl: 287; ansic: 172; makefile: 143
file content (56 lines) | stat: -rw-r--r-- 1,268 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifdef HAVE_CONFIG_H
    #include "config.h"
#endif

#include <Eris/Log.h>

#include <cassert>
#include <stdarg.h>
#include <stdio.h>
#include <algorithm>

#ifdef __WIN32__

// Provide missing / misaligned function names.  May only be for mingw32
#ifndef vsnprintf
#define vsnprintf _vsnprintf
#endif

#endif // __WIN32__

namespace Eris
{

static LogLevel _logLevel = DEFAULT_LOG;    
SigC::Signal2<void, LogLevel, const std::string&> Logged;
    
void setLogLevel(LogLevel lvl)
{
    _logLevel = lvl;
}    
    
LogLevel getLogLevel()
{
    return _logLevel;
}

const int MSG_BUFFER_SIZE = 2048;	///< bounds for the static char[] buffers useds in vsnprintf

/** Log the specified printf() style string if the current LogLevel is sufficent. The client is free to attach
any (and several) outputs to the Connection::Log signal; notably to files, standard out, Quake style 'consoles',
etc, etc. Note this is purely informational - the client should never need to watch the log stream.*/
void log(LogLevel lvl, const char *str, ...)
{
    if (_logLevel < lvl) return;
	
	va_list args;
	va_start(args, str);
	
	static char buffer[MSG_BUFFER_SIZE];
	::vsnprintf(buffer, MSG_BUFFER_SIZE, str, args);
	
	Logged.emit(lvl, buffer);
	va_end(args);
}    
    
} // of namespace