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
|
|
|
|
2005-06-13 21:31:48 +02:00
|
|
|
#include "Singleton.h"
|
|
|
|
|
|
|
|
#define g_Logger CLogger::GetSingleton()
|
|
|
|
#define LOG (CLogger::GetSingleton().Log)
|
|
|
|
#define LOG_ONCE (CLogger::GetSingleton().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
|
|
|
|
};
|
|
|
|
|
2005-06-13 21:31:48 +02:00
|
|
|
class CLogger : public Singleton<CLogger>
|
2004-04-14 23:52:59 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2005-06-13 21:31:48 +02:00
|
|
|
CLogger();
|
|
|
|
~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
|
|
|
|
|
|
|
//Function to log stuff to memory buffer
|
|
|
|
void QuickLog(const char *fmt, ...);
|
2005-06-13 21:31:48 +02:00
|
|
|
|
2004-04-14 23:52:59 +02:00
|
|
|
private:
|
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);
|
|
|
|
|
2004-08-15 22:57:04 +02:00
|
|
|
//the three filestreams
|
2004-04-14 23:52:59 +02:00
|
|
|
std::ofstream m_MainLog;
|
2004-08-15 22:57:04 +02:00
|
|
|
std::ofstream m_InterestingLog;
|
|
|
|
std::ofstream m_MemoryLog;
|
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-04-14 23:52:59 +02:00
|
|
|
//this holds the start of the memory buffer.
|
2004-08-15 22:57:04 +02:00
|
|
|
char *m_MemoryLogBuffer;
|
2004-04-14 23:52:59 +02:00
|
|
|
//this holds the next available place to write to.
|
|
|
|
char *m_CurrentPosition;
|
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
|
|
|
|
|
|
|
// squelch "unable to generate" warnings
|
|
|
|
CLogger(const CLogger& rhs);
|
|
|
|
const CLogger& operator=(const CLogger& rhs);
|
2004-04-14 23:52:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|