2001-10-14 14:38:45 +00:00
|
|
|
#ifndef CLOG_H
|
|
|
|
#define CLOG_H
|
|
|
|
|
2002-06-19 11:23:49 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include <stdarg.h>
|
2001-10-14 14:38:45 +00:00
|
|
|
|
|
|
|
class CLog {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2002-06-03 18:53:18 +00:00
|
|
|
enum {
|
|
|
|
kFATAL,
|
|
|
|
kERROR,
|
|
|
|
kWARNING,
|
|
|
|
kNOTE,
|
|
|
|
kINFO,
|
|
|
|
kDEBUG,
|
|
|
|
kDEBUG1,
|
|
|
|
kDEBUG2
|
|
|
|
};
|
|
|
|
|
2002-06-08 21:48:00 +00:00
|
|
|
// type of outputter function. return false if CLog should use
|
|
|
|
// the default outputter, true otherwise.
|
|
|
|
typedef bool (*Outputter)(int priority, const char*);
|
|
|
|
|
|
|
|
// type of lock/unlock function
|
2002-05-31 14:25:26 +00:00
|
|
|
typedef void (*Lock)(bool lock);
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
// print a log message
|
2001-10-14 14:38:45 +00:00
|
|
|
static void print(const char*, ...);
|
|
|
|
static void printt(const char* file, int line, const char*, ...);
|
2002-05-31 14:25:26 +00:00
|
|
|
|
|
|
|
// 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.
|
2001-11-19 00:33:36 +00:00
|
|
|
static void setOutputter(Outputter);
|
2002-05-31 14:25:26 +00:00
|
|
|
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
|
2002-06-03 16:36:45 +00:00
|
|
|
// var to "FATAL", "ERROR", etc. setFilter(const char*) returns
|
|
|
|
// true if the priority name was recognized; if name == NULL
|
|
|
|
// then it simply returns true.
|
|
|
|
static bool setFilter(const char* name);
|
2002-05-31 14:25:26 +00:00
|
|
|
static void setFilter(int);
|
|
|
|
static int getFilter();
|
2001-10-14 14:38:45 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2002-05-31 14:25:26 +00:00
|
|
|
class CHoldLock {
|
|
|
|
public:
|
2002-06-01 19:26:11 +00:00
|
|
|
CHoldLock(Lock lock) : m_lock(lock) { m_lock(true); }
|
2002-05-31 14:25:26 +00:00
|
|
|
~CHoldLock() { m_lock(false); }
|
|
|
|
|
|
|
|
private:
|
2002-06-01 19:26:11 +00:00
|
|
|
Lock m_lock;
|
2002-05-31 14:25:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void dummyLock(bool);
|
|
|
|
static int getMaxPriority();
|
2001-11-19 00:33:36 +00:00
|
|
|
static void output(int priority, char* msg);
|
2002-06-19 11:23:49 +00:00
|
|
|
#if WINDOWS_LIKE
|
2002-05-22 17:01:17 +00:00
|
|
|
static void openConsole();
|
|
|
|
#endif
|
2001-11-19 00:33:36 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2001-11-19 00:33:36 +00:00
|
|
|
static Outputter s_outputter;
|
2002-05-31 14:25:26 +00:00
|
|
|
static Lock s_lock;
|
|
|
|
static int s_maxPriority;
|
2001-10-14 14:38:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(NOLOGGING)
|
|
|
|
#define log(_a1)
|
2001-10-14 18:29:43 +00:00
|
|
|
#define logc(_a1, _a2)
|
2001-10-14 14:38:45 +00:00
|
|
|
#define CLOG_TRACE
|
|
|
|
#elif defined(NDEBUG)
|
|
|
|
#define log(_a1) CLog::print _a1
|
2001-10-14 18:29:43 +00:00
|
|
|
#define logc(_a1, _a2) if (_a1) CLog::print _a2
|
2001-10-14 14:38:45 +00:00
|
|
|
#define CLOG_TRACE
|
|
|
|
#else
|
|
|
|
#define log(_a1) CLog::printt _a1
|
2001-10-14 18:29:43 +00:00
|
|
|
#define logc(_a1, _a2) if (_a1) CLog::printt _a2
|
2001-10-14 14:38:45 +00:00
|
|
|
#define CLOG_TRACE __FILE__, __LINE__,
|
|
|
|
#endif
|
|
|
|
|
2002-06-03 16:36:45 +00:00
|
|
|
#define CLOG_PRINT CLOG_TRACE "%z\057"
|
2001-10-14 14:38:45 +00:00
|
|
|
#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"
|
2002-04-27 18:49:03 +00:00
|
|
|
#define CLOG_DEBUG1 CLOG_TRACE "%z\066"
|
|
|
|
#define CLOG_DEBUG2 CLOG_TRACE "%z\067"
|
2001-10-14 14:38:45 +00:00
|
|
|
|
|
|
|
#endif
|