core/Logger.h
author Borja Ferrer <faluco@alliedmods.net>
Sat Feb 23 20:18:49 2008 +0000 (2008-02-23)
changeset 1894 e6efc8ffa47a
parent 1378 115ba755bcdf
child 1914 0751a6430f15
permissions -rw-r--r--
Executable memory is now provided by MM:S's allocator, this should reduce virtual memory usage.
dvander@592
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 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@592
    77
	void LogError(const char *msg, ...);
dvander@663
    78
	void LogFatal(const char *msg, ...);
dvander@1378
    79
	void LogToOpenFile(FILE *fp, const char *msg, ...);
dvander@1378
    80
	void LogToOpenFileEx(FILE *fp, const char *msg, va_list ap);
dvander@592
    81
	void MapChange(const char *mapname);
dvander@592
    82
	const char *GetLogFileName(LogType type) const;
dvander@592
    83
	LoggingMode GetLoggingMode() const;
dvander@592
    84
private:
dvander@592
    85
	void _CloseFile();
dvander@592
    86
	void _NewMapFile();
ds@661
    87
	void _PrintToGameLog(const char *fmt, va_list ap);
dvander@592
    88
private:
dvander@592
    89
	String m_NrmFileName;
dvander@592
    90
	String m_ErrFileName;
dvander@592
    91
	String m_CurMapName;
ds@661
    92
	LoggingMode m_Mode;
dvander@592
    93
	int m_CurDay;
dvander@592
    94
	bool m_ErrMapStart;
dvander@592
    95
	bool m_Active;
dvander@592
    96
	bool m_DelayedStart;
dvander@592
    97
	bool m_DailyPrintHdr;
ds@661
    98
	bool m_InitialState;
dvander@592
    99
};
dvander@592
   100
dvander@616
   101
extern Logger g_Logger;
dvander@592
   102
dvander@592
   103
#endif // _INCLUDE_SOURCEMOD_CLOGGER_H_