core/Logger.h
author David Anderson <dvander@alliedmods.net>
Sun May 06 06:15:48 2007 +0000 (2007-05-06)
changeset 743 a2804c2faba2
parent 673 fc1d50579d06
child 1231 17badaf66ce4
permissions -rw-r--r--
added request amb251
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_CLOGGER_H_
    16 #define _INCLUDE_SOURCEMOD_CLOGGER_H_
    17 
    18 #include <sh_string.h>
    19 #include "sm_globals.h"
    20 
    21 using namespace SourceHook;
    22 
    23 enum LogType
    24 {
    25 	LogType_Normal,
    26 	LogType_Error
    27 };
    28 
    29 enum LoggingMode
    30 {
    31 	LoggingMode_Daily,
    32 	LoggingMode_PerMap,
    33 	LoggingMode_Game
    34 };
    35 
    36 class Logger : public SMGlobalClass
    37 {
    38 public:
    39 	Logger() : m_Mode(LoggingMode_Daily), m_ErrMapStart(false), 
    40 		m_Active(false), m_DelayedStart(false), m_DailyPrintHdr(false), 
    41 		m_InitialState(true)
    42 	{
    43 	}
    44 public: //SMGlobalClass
    45 	ConfigResult OnSourceModConfigChanged(const char *key, 
    46 		const char *value, 
    47 		ConfigSource source,
    48 		char *error, 
    49 		size_t maxlength);
    50 	void OnSourceModStartup(bool late);
    51 	void OnSourceModAllShutdown();
    52 	void OnSourceModLevelChange(const char *mapName);
    53 public:
    54 	void InitLogger(LoggingMode mode);
    55 	void CloseLogger();
    56 	void EnableLogging();
    57 	void DisableLogging();
    58 	void LogMessage(const char *msg, ...);
    59 	void LogError(const char *msg, ...);
    60 	void LogFatal(const char *msg, ...);
    61 	void MapChange(const char *mapname);
    62 	const char *GetLogFileName(LogType type) const;
    63 	LoggingMode GetLoggingMode() const;
    64 private:
    65 	void _CloseFile();
    66 	void _NewMapFile();
    67 	void _PrintToGameLog(const char *fmt, va_list ap);
    68 private:
    69 	String m_NrmFileName;
    70 	String m_ErrFileName;
    71 	String m_CurMapName;
    72 	LoggingMode m_Mode;
    73 	int m_CurDay;
    74 	bool m_ErrMapStart;
    75 	bool m_Active;
    76 	bool m_DelayedStart;
    77 	bool m_DailyPrintHdr;
    78 	bool m_InitialState;
    79 };
    80 
    81 extern Logger g_Logger;
    82 
    83 #endif // _INCLUDE_SOURCEMOD_CLOGGER_H_