2007-01-05 00:41:51 +01:00
|
|
|
#ifndef _INCLUDE_SOURCEMOD_CLOGGER_H_
|
|
|
|
#define _INCLUDE_SOURCEMOD_CLOGGER_H_
|
|
|
|
|
2007-01-06 08:53:34 +01:00
|
|
|
#include "sm_globals.h"
|
2007-01-05 00:41:51 +01:00
|
|
|
#include <time.h>
|
|
|
|
#include "sourcemm_api.h"
|
|
|
|
#include <sh_string.h>
|
|
|
|
#include "sourcemod.h"
|
|
|
|
#include "sm_version.h"
|
|
|
|
|
|
|
|
using namespace SourceHook;
|
|
|
|
|
|
|
|
enum LogType
|
|
|
|
{
|
|
|
|
LogType_Normal,
|
|
|
|
LogType_Error
|
|
|
|
};
|
|
|
|
|
|
|
|
enum LoggingMode
|
|
|
|
{
|
|
|
|
LoggingMode_Daily,
|
|
|
|
LoggingMode_PerMap,
|
|
|
|
LoggingMode_HL2
|
|
|
|
};
|
|
|
|
|
2007-01-11 02:11:24 +01:00
|
|
|
class CLogger : public SMGlobalClass
|
2007-01-05 00:41:51 +01:00
|
|
|
{
|
|
|
|
public:
|
2007-01-05 14:23:25 +01:00
|
|
|
CLogger() : m_ErrMapStart(false), m_Active(false), m_DelayedStart(false), m_DailyPrintHdr(false) {}
|
2007-01-11 02:11:24 +01:00
|
|
|
public: //SMGlobalClass
|
|
|
|
void OnSourceModStartup(bool late);
|
|
|
|
void OnSourceModAllShutdown();
|
2007-01-05 00:41:51 +01:00
|
|
|
public:
|
|
|
|
void InitLogger(LoggingMode mode, bool startlogging);
|
|
|
|
void CloseLogger();
|
|
|
|
void EnableLogging();
|
|
|
|
void DisableLogging();
|
|
|
|
void LogMessage(const char *msg, ...);
|
2007-01-06 08:53:34 +01:00
|
|
|
void LogError(const char *msg, ...);
|
2007-01-05 00:41:51 +01:00
|
|
|
void MapChange(const char *mapname);
|
2007-01-11 00:49:22 +01:00
|
|
|
const char *GetLogFileName(LogType type) const;
|
|
|
|
LoggingMode GetLoggingMode() const;
|
2007-01-05 00:41:51 +01:00
|
|
|
private:
|
|
|
|
void _CloseFile();
|
|
|
|
void _NewMapFile();
|
2007-01-07 02:30:28 +01:00
|
|
|
void _PrintToHL2Log(const char *fmt, va_list ap);
|
2007-01-05 00:41:51 +01:00
|
|
|
private:
|
|
|
|
String m_NrmFileName;
|
|
|
|
String m_ErrFileName;
|
|
|
|
String m_CurMapName;
|
|
|
|
LoggingMode m_mode;
|
|
|
|
int m_CurDay;
|
|
|
|
bool m_ErrMapStart;
|
|
|
|
bool m_Active;
|
|
|
|
bool m_DelayedStart;
|
|
|
|
bool m_DailyPrintHdr;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern CLogger g_Logger;
|
|
|
|
|
2007-01-11 00:49:22 +01:00
|
|
|
inline const char *CLogger::GetLogFileName(LogType type) const
|
2007-01-05 00:41:51 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case LogType_Normal:
|
|
|
|
{
|
|
|
|
return m_NrmFileName.c_str();
|
|
|
|
}
|
|
|
|
case LogType_Error:
|
|
|
|
{
|
|
|
|
return m_ErrFileName.c_str();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-11 00:49:22 +01:00
|
|
|
inline LoggingMode CLogger::GetLoggingMode() const
|
2007-01-05 00:41:51 +01:00
|
|
|
{
|
|
|
|
return m_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void CLogger::EnableLogging()
|
|
|
|
{
|
|
|
|
if (m_Active)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_Active = true;
|
|
|
|
LogMessage("Logging enabled manually by user.");
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void CLogger::DisableLogging()
|
|
|
|
{
|
|
|
|
if (!m_Active)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LogMessage("Logging disabled manually by user.");
|
|
|
|
m_Active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _INCLUDE_SOURCEMOD_CLOGGER_H_
|