core/Logger.h
author Scott Ehlert <ds@alliedmods.net>
Wed Aug 15 06:19:30 2007 +0000 (2007-08-15)
changeset 1330 ab94316bb52b
parent 1231 17badaf66ce4
child 1378 115ba755bcdf
permissions -rw-r--r--
Updated license headers on virtually all files with extremely minor changes in the name of some sort of strange consistency.
All plugin and include file headers also have been changed to say about GPL3 instead of GPL2.

(This day shall henceforth be known as the Eighty Column Massacre of '07)
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@592
    35
#include <sh_string.h>
dvander@592
    36
#include "sm_globals.h"
dvander@592
    37
dvander@592
    38
using namespace SourceHook;
dvander@592
    39
dvander@592
    40
enum LogType
dvander@592
    41
{
dvander@592
    42
	LogType_Normal,
dvander@592
    43
	LogType_Error
dvander@592
    44
};
dvander@592
    45
dvander@592
    46
enum LoggingMode
dvander@592
    47
{
dvander@592
    48
	LoggingMode_Daily,
dvander@592
    49
	LoggingMode_PerMap,
ds@661
    50
	LoggingMode_Game
dvander@592
    51
};
dvander@592
    52
dvander@616
    53
class Logger : public SMGlobalClass
dvander@592
    54
{
dvander@592
    55
public:
dvander@663
    56
	Logger() : m_Mode(LoggingMode_Daily), m_ErrMapStart(false), 
dvander@663
    57
		m_Active(false), m_DelayedStart(false), m_DailyPrintHdr(false), 
dvander@663
    58
		m_InitialState(true)
dvander@663
    59
	{
dvander@663
    60
	}
dvander@592
    61
public: //SMGlobalClass
dvander@663
    62
	ConfigResult OnSourceModConfigChanged(const char *key, 
dvander@663
    63
		const char *value, 
dvander@663
    64
		ConfigSource source,
dvander@663
    65
		char *error, 
dvander@663
    66
		size_t maxlength);
dvander@592
    67
	void OnSourceModStartup(bool late);
dvander@592
    68
	void OnSourceModAllShutdown();
dvander@673
    69
	void OnSourceModLevelChange(const char *mapName);
dvander@592
    70
public:
dvander@663
    71
	void InitLogger(LoggingMode mode);
dvander@592
    72
	void CloseLogger();
dvander@592
    73
	void EnableLogging();
dvander@592
    74
	void DisableLogging();
dvander@592
    75
	void LogMessage(const char *msg, ...);
dvander@592
    76
	void LogError(const char *msg, ...);
dvander@663
    77
	void LogFatal(const char *msg, ...);
dvander@592
    78
	void MapChange(const char *mapname);
dvander@592
    79
	const char *GetLogFileName(LogType type) const;
dvander@592
    80
	LoggingMode GetLoggingMode() const;
dvander@592
    81
private:
dvander@592
    82
	void _CloseFile();
dvander@592
    83
	void _NewMapFile();
ds@661
    84
	void _PrintToGameLog(const char *fmt, va_list ap);
dvander@592
    85
private:
dvander@592
    86
	String m_NrmFileName;
dvander@592
    87
	String m_ErrFileName;
dvander@592
    88
	String m_CurMapName;
ds@661
    89
	LoggingMode m_Mode;
dvander@592
    90
	int m_CurDay;
dvander@592
    91
	bool m_ErrMapStart;
dvander@592
    92
	bool m_Active;
dvander@592
    93
	bool m_DelayedStart;
dvander@592
    94
	bool m_DailyPrintHdr;
ds@661
    95
	bool m_InitialState;
dvander@592
    96
};
dvander@592
    97
dvander@616
    98
extern Logger g_Logger;
dvander@592
    99
dvander@592
   100
#endif // _INCLUDE_SOURCEMOD_CLOGGER_H_