Files
barrier/base/CLog.h
crs d2135af0d9 fixes, mainly for windows. first, had to add a notification from
CServer to the primary screen when the configuration changes so it
can make necessary adjustments (the win32 primary screen must tell
the hook dll about the new jump zones).

changed includes of some std c++ library files to go through
our own include files.  these wrap the include with stuff to
keep vc++ quiet when compiling at warning level 4, which is
what it does now.  it also works around missing <istream> and
<ostream> on g++2.96.

added missing std:: where necessary.  g++ doesn't really support
namespaces so it lets references without the namespace slip
through.

added workaround or fix.  not sure if istringstream::str(string)
should reset eofbit.  it does on g++ but does not on vc++.
added clear() after str() so it works either way.

added low-level keyboard hook to win32.  if available (it's only
available on NT SP3 and up) it allows us to catch and handle
alt+tab, alt+esc, ctrl+esc, and windows key hot keys.  i think
that leaves only ctrl+alt+del and accessibility functions
uncaught on those systems.
2002-06-01 19:26:11 +00:00

86 lines
2.4 KiB
C++

#ifndef CLOG_H
#define CLOG_H
#include "BasicTypes.h"
#include <stdarg.h>
class CLog {
public:
typedef void (*Outputter)(const char*);
typedef void (*Lock)(bool lock);
//
static void print(const char*, ...);
static void printt(const char* file, int line, const char*, ...);
// get/set the function used to write the log. a NULL outputter
// means to use the default which is fprintf(stderr, ...). note
// that the outputter should not call CLog methods but, if it
// does, the current lock function must permit recursive locks.
static void setOutputter(Outputter);
static Outputter getOutputter();
// get/set the lock/unlock function. use setLock(NULL) to remove
// the locking function. note that the lock function is used when
// retrieving the lock function. there is no default lock function.
static void setLock(Lock);
static Lock getLock();
// get/set the minimum priority filter. any message below this
// priority is discarded. the default priority is 4 (INFO)
// (unless built without NDEBUG in which case it's 5 (DEBUG)).
// the default can be overridden by setting the SYN_LOG_PRI env
// var to "CRIT", "ERR", etc.
static void setFilter(int);
static int getFilter();
private:
class CHoldLock {
public:
CHoldLock(Lock lock) : m_lock(lock) { m_lock(true); }
~CHoldLock() { m_lock(false); }
private:
Lock m_lock;
};
static void dummyLock(bool);
static int getMaxPriority();
static void output(int priority, char* msg);
static char* vsprint(int pad, char*, int len, const char*, va_list);
static int nprint(const char*, va_list);
#if defined(CONFIG_PLATFORM_WIN32)
static void openConsole();
#endif
private:
static Outputter s_outputter;
static Lock s_lock;
static int s_maxPriority;
};
#if defined(NOLOGGING)
#define log(_a1)
#define logc(_a1, _a2)
#define CLOG_TRACE
#elif defined(NDEBUG)
#define log(_a1) CLog::print _a1
#define logc(_a1, _a2) if (_a1) CLog::print _a2
#define CLOG_TRACE
#else
#define log(_a1) CLog::printt _a1
#define logc(_a1, _a2) if (_a1) CLog::printt _a2
#define CLOG_TRACE __FILE__, __LINE__,
#endif
#define CLOG_CRIT CLOG_TRACE "%z\060"
#define CLOG_ERR CLOG_TRACE "%z\061"
#define CLOG_WARN CLOG_TRACE "%z\062"
#define CLOG_NOTE CLOG_TRACE "%z\063"
#define CLOG_INFO CLOG_TRACE "%z\064"
#define CLOG_DEBUG CLOG_TRACE "%z\065"
#define CLOG_DEBUG1 CLOG_TRACE "%z\066"
#define CLOG_DEBUG2 CLOG_TRACE "%z\067"
#endif