core/Logger.h
author Drifter <drifter01620@gmail.com>
Wed Jul 31 22:11:15 2013 -0400 (2013-07-31)
changeset 3965 86dedf4462d8
parent 3926 ff7231bfdd0b
permissions -rw-r--r--
Added CS_IsValidWeaponID native and validity checks to other natives (bug 5566, r=psychonic).
dvander@592
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@592
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@592
    28
 *
dvander@592
    29
 * Version: $Id$
dvander@592
    30
 */
dvander@592
    31
dvander@592
    32
#ifndef _INCLUDE_SOURCEMOD_CLOGGER_H_
dvander@592
    33
#define _INCLUDE_SOURCEMOD_CLOGGER_H_
dvander@592
    34
dvander@1378
    35
#include <stdio.h>
dvander@592
    36
#include <sh_string.h>
dvander@592
    37
#include "sm_globals.h"
dvander@592
    38
dvander@592
    39
using namespace SourceHook;
dvander@592
    40
dvander@592
    41
enum LogType
dvander@592
    42
{
dvander@592
    43
	LogType_Normal,
dvander@592
    44
	LogType_Error
dvander@592
    45
};
dvander@592
    46
dvander@592
    47
enum LoggingMode
dvander@592
    48
{
dvander@592
    49
	LoggingMode_Daily,
dvander@592
    50
	LoggingMode_PerMap,
ds@661
    51
	LoggingMode_Game
dvander@592
    52
};
dvander@592
    53
dvander@616
    54
class Logger : public SMGlobalClass
dvander@592
    55
{
dvander@592
    56
public:
dvander@663
    57
	Logger() : m_Mode(LoggingMode_Daily), m_ErrMapStart(false), 
dvander@663
    58
		m_Active(false), m_DelayedStart(false), m_DailyPrintHdr(false), 
dvander@663
    59
		m_InitialState(true)
dvander@663
    60
	{
dvander@663
    61
	}
dvander@592
    62
public: //SMGlobalClass
dvander@663
    63
	ConfigResult OnSourceModConfigChanged(const char *key, 
dvander@663
    64
		const char *value, 
dvander@663
    65
		ConfigSource source,
dvander@663
    66
		char *error, 
dvander@663
    67
		size_t maxlength);
dvander@592
    68
	void OnSourceModStartup(bool late);
dvander@592
    69
	void OnSourceModAllShutdown();
dvander@673
    70
	void OnSourceModLevelChange(const char *mapName);
dvander@592
    71
public:
dvander@663
    72
	void InitLogger(LoggingMode mode);
dvander@592
    73
	void CloseLogger();
dvander@592
    74
	void EnableLogging();
dvander@592
    75
	void DisableLogging();
dvander@592
    76
	void LogMessage(const char *msg, ...);
dvander@3791
    77
	void LogMessageEx(const char *msg, va_list ap);
dvander@592
    78
	void LogError(const char *msg, ...);
dvander@2726
    79
	void LogErrorEx(const char *msg, va_list ap); 
dvander@663
    80
	void LogFatal(const char *msg, ...);
dvander@3872
    81
	void LogFatalEx(const char *msg, va_list ap);
dvander@1378
    82
	void LogToOpenFile(FILE *fp, const char *msg, ...);
dvander@1378
    83
	void LogToOpenFileEx(FILE *fp, const char *msg, va_list ap);
dvander@2475
    84
	/* This version does not print to console, and is thus thread-safe */
dvander@2475
    85
	void LogToFileOnly(FILE *fp, const char *msg, ...);
dvander@2475
    86
	void LogToFileOnlyEx(FILE *fp, const char *msg, va_list ap);
dvander@592
    87
	void MapChange(const char *mapname);
dvander@592
    88
	const char *GetLogFileName(LogType type) const;
dvander@592
    89
	LoggingMode GetLoggingMode() const;
dvander@592
    90
private:
dvander@592
    91
	void _CloseFile();
dvander@592
    92
	void _NewMapFile();
ds@661
    93
	void _PrintToGameLog(const char *fmt, va_list ap);
dvander@592
    94
private:
dvander@592
    95
	String m_NrmFileName;
dvander@592
    96
	String m_ErrFileName;
dvander@592
    97
	String m_CurMapName;
ds@661
    98
	LoggingMode m_Mode;
matheusavs3@3926
    99
	int m_NrmCurDay;
matheusavs3@3926
   100
	int m_ErrCurDay;
dvander@592
   101
	bool m_ErrMapStart;
dvander@592
   102
	bool m_Active;
dvander@592
   103
	bool m_DelayedStart;
dvander@592
   104
	bool m_DailyPrintHdr;
ds@661
   105
	bool m_InitialState;
dvander@592
   106
};
dvander@592
   107
dvander@1914
   108
void Engine_LogPrintWrapper(const char *msg);
dvander@1914
   109
dvander@1914
   110
extern bool g_in_game_log_hook;
dvander@616
   111
extern Logger g_Logger;
dvander@592
   112
dvander@592
   113
#endif // _INCLUDE_SOURCEMOD_CLOGGER_H_