2004-04-14 23:52:59 +02:00
|
|
|
#ifndef _ps_CLogger_H
|
|
|
|
#define _ps_CLogger_H
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2004-08-27 19:41:02 +02:00
|
|
|
#include <set>
|
2004-04-14 23:52:59 +02:00
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
class CLogger;
|
|
|
|
extern CLogger* g_Logger;
|
2005-06-13 21:31:48 +02:00
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
#define LOG (g_Logger->Log)
|
|
|
|
#define LOG_ONCE (g_Logger->LogOnce)
|
2004-04-14 23:52:59 +02:00
|
|
|
|
|
|
|
enum ELogMethod
|
|
|
|
{
|
|
|
|
NORMAL,
|
2004-11-11 08:09:32 +01:00
|
|
|
MESSAGE = NORMAL,
|
2004-04-14 23:52:59 +02:00
|
|
|
ERROR,
|
|
|
|
WARNING
|
|
|
|
};
|
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
class CLogger
|
2004-04-14 23:52:59 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
// Default constructor - outputs to normal log files
|
2005-06-13 21:31:48 +02:00
|
|
|
CLogger();
|
2006-09-28 22:41:12 +02:00
|
|
|
|
|
|
|
// Special constructor (mostly for testing) - outputs to provided streams.
|
|
|
|
// Takes ownership of streams and will delete them in the destructor.
|
|
|
|
CLogger(std::ostream* mainLog, std::ostream* interestingLog);
|
|
|
|
|
2005-06-13 21:31:48 +02:00
|
|
|
~CLogger();
|
2004-04-14 23:52:59 +02:00
|
|
|
|
|
|
|
//Functions to write different message types
|
2004-08-15 22:57:04 +02:00
|
|
|
void WriteMessage(const char *message, int interestedness);
|
|
|
|
void WriteError (const char *message, int interestedness);
|
|
|
|
void WriteWarning(const char *message, int interestedness);
|
2004-04-14 23:52:59 +02:00
|
|
|
|
|
|
|
//Function to log stuff to file
|
2004-08-15 22:57:04 +02:00
|
|
|
void Log(ELogMethod method, const char* category, const char *fmt, ...);
|
2004-08-27 19:41:02 +02:00
|
|
|
//Similar to Log, but only outputs each message once no matter how many times it's called
|
|
|
|
void LogOnce(ELogMethod method, const char* category, const char *fmt, ...);
|
2004-04-14 23:52:59 +02:00
|
|
|
|
|
|
|
private:
|
2006-09-28 22:41:12 +02:00
|
|
|
void Init();
|
2005-08-09 17:55:44 +02:00
|
|
|
|
2004-08-27 19:41:02 +02:00
|
|
|
void LogUsingMethod(ELogMethod method, const char* category, const char* message);
|
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
//the output streams
|
|
|
|
std::ostream* m_MainLog;
|
|
|
|
std::ostream* m_InterestingLog;
|
2004-04-14 23:52:59 +02:00
|
|
|
|
|
|
|
//vars to hold message counts
|
|
|
|
int m_NumberOfMessages;
|
|
|
|
int m_NumberOfErrors;
|
|
|
|
int m_NumberOfWarnings;
|
|
|
|
|
2004-08-15 22:57:04 +02:00
|
|
|
// Returns how interesting this category is to the user
|
|
|
|
// (0 = no messages, 1(default) = warnings/errors, 2 = all)
|
|
|
|
int Interestedness(const char* category);
|
|
|
|
|
2004-08-27 19:41:02 +02:00
|
|
|
// Used to remember LogOnce messages
|
|
|
|
std::set<std::string> m_LoggedOnce;
|
2005-08-09 17:55:44 +02:00
|
|
|
|
2006-07-21 03:11:23 +02:00
|
|
|
NO_COPY_CTOR(CLogger);
|
2004-04-14 23:52:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|