Files
TCPlayerbotCore/src/shared/Log.h
T

182 lines
5.4 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2008-10-14 11:57:03 -05:00
#ifndef TRINITYCORE_LOG_H
#define TRINITYCORE_LOG_H
2008-10-02 16:23:55 -05:00
#include "Common.h"
#include "Policies/Singleton.h"
#include "Database/DatabaseEnv.h"
2008-10-02 16:23:55 -05:00
class Config;
enum LogFilters
{
2009-03-19 21:13:52 +01:00
LOG_FILTER_TRANSPORT_MOVES = 0x1,
LOG_FILTER_CREATURE_MOVES = 0x2,
LOG_FILTER_VISIBILITY_CHANGES = 0x4,
LOG_FILTER_ACHIEVEMENT_UPDATES = 0x8
2008-10-02 16:23:55 -05:00
};
2009-03-19 21:13:52 +01:00
enum LogTypes
2008-10-02 16:23:55 -05:00
{
2009-03-19 21:13:52 +01:00
LOG_TYPE_STRING = 0,
LOG_TYPE_ERROR = 1,
LOG_TYPE_BASIC = 2,
LOG_TYPE_DETAIL = 3,
LOG_TYPE_DEBUG = 4,
LOG_TYPE_CHAR = 5,
LOG_TYPE_WORLD = 6,
LOG_TYPE_RA = 7,
LOG_TYPE_GM = 8,
LOG_TYPE_PACKET = 9,
LOG_TYPE_CRASH = 10,
2009-03-19 21:13:52 +01:00
MAX_LOG_TYPES
2008-10-02 16:23:55 -05:00
};
2009-03-19 21:13:52 +01:00
enum LogLevel
{
LOGL_NORMAL = 0,
LOGL_BASIC,
LOGL_DETAIL,
LOGL_DEBUG
};
2008-10-02 16:23:55 -05:00
2009-03-20 18:16:36 +01:00
const int LogLevels = int(LOGL_DEBUG)+1;
enum ColorTypes
{
BLACK,
RED,
GREEN,
BROWN,
BLUE,
MAGENTA,
CYAN,
GREY,
YELLOW,
LRED,
LGREEN,
LBLUE,
LMAGENTA,
LCYAN,
WHITE
};
const int Colors = int(WHITE)+1;
2008-10-14 11:57:03 -05:00
class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ZThread::FastMutex> >
2008-10-02 16:23:55 -05:00
{
2008-10-14 11:57:03 -05:00
friend class Trinity::OperatorNew<Log>;
2008-11-25 16:36:50 -06:00
Log();
2009-03-19 21:13:52 +01:00
~Log();
2008-11-25 16:36:50 -06:00
2008-10-02 16:23:55 -05:00
public:
void Initialize();
2009-03-19 21:13:52 +01:00
2009-03-20 18:16:36 +01:00
void InitColors(const std::string& init_str);
void SetColor(bool stdout_stream, ColorTypes color);
void ResetColor(bool stdout_stream);
2009-03-19 21:13:52 +01:00
void outDB( uint8 type, const char * str, ... ) ATTR_PRINTF(3,4);
void outString( const char * str, ... ) ATTR_PRINTF(2,3);
void outError( const char * err, ... ) ATTR_PRINTF(2,3);
void outCrash( const char * err, ... ) ATTR_PRINTF(2,3);
2009-03-19 21:13:52 +01:00
void outBasic( const char * str, ... ) ATTR_PRINTF(2,3);
void outDetail( const char * str, ... ) ATTR_PRINTF(2,3);
void outDebug( const char * str, ... ) ATTR_PRINTF(2,3);
void outDebugInLine( const char * str, ... ) ATTR_PRINTF(2,3);
void outErrorDb( const char * str, ... ) ATTR_PRINTF(2,3);
void outChar( const char * str, ... ) ATTR_PRINTF(2,3);
2008-11-25 16:36:50 -06:00
void outCommand( uint32 account, const char * str, ...) ATTR_PRINTF(3,4);
2009-03-19 21:13:52 +01:00
void outRemote( const char * str, ... ) ATTR_PRINTF(2,3);
2008-10-02 16:23:55 -05:00
void outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name );
2009-03-19 21:13:52 +01:00
static void outTimestamp(FILE* file);
static std::string GetTimestampStr();
2008-10-02 16:23:55 -05:00
void SetLogLevel(char * Level);
void SetLogFileLevel(char * Level);
2009-03-19 21:13:52 +01:00
void SetDBLogLevel(char * Level);
void SetRealmID(uint32 id) { realm = id; }
2008-10-02 16:23:55 -05:00
uint32 getLogFilter() const { return m_logFilter; }
bool IsOutDebug() const { return m_logLevel > 2 || (m_logFileLevel > 2 && logfile); }
bool IsOutCharDump() const { return m_charLog_Dump; }
2009-03-19 21:13:52 +01:00
bool GetLogDB() { return m_enableLogDB; }
bool GetLogDBLater() { return m_enableLogDBLater; }
void SetLogDB(bool enable) { m_enableLogDB = enable; }
void SetLogDBLater(bool value) { m_enableLogDBLater = value; }
2008-10-02 16:23:55 -05:00
private:
2008-11-25 16:36:50 -06:00
FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode);
FILE* openGmlogPerAccount(uint32 account);
2008-10-02 16:23:55 -05:00
FILE* raLogfile;
FILE* logfile;
FILE* gmLogfile;
FILE* charLogfile;
FILE* dberLogfile;
2008-11-25 16:36:50 -06:00
// cache values for after initilization use (like gm log per account case)
std::string m_logsDir;
std::string m_logsTimestamp;
// gm log control
bool m_gmlog_per_account;
std::string m_gmlog_filename_format;
2009-03-19 21:13:52 +01:00
bool m_enableLogDBLater;
bool m_enableLogDB;
uint32 realm;
2009-03-20 18:16:36 +01:00
// log coloring
bool m_colored;
ColorTypes m_colors[4];
2009-03-19 21:13:52 +01:00
// log levels:
// 0 minimum/string, 1 basic/error, 2 detail, 3 full/debug
uint8 m_dbLogLevel;
uint8 m_logLevel;
uint8 m_logFileLevel;
uint8 m_logFilter;
bool m_dbChar;
bool m_dbRA;
bool m_dbGM;
bool m_charLog_Dump;
2008-10-02 16:23:55 -05:00
};
2008-10-14 11:57:03 -05:00
#define sLog Trinity::Singleton<Log>::Instance()
2008-10-02 16:23:55 -05:00
2008-10-14 11:57:03 -05:00
#ifdef TRINITY_DEBUG
#define DEBUG_LOG Trinity::Singleton<Log>::Instance().outDebug
2008-10-02 16:23:55 -05:00
#else
#define DEBUG_LOG
#endif
// primary for script library
2008-10-14 11:57:03 -05:00
void TRINITY_DLL_SPEC outstring_log(const char * str, ...) ATTR_PRINTF(1,2);
void TRINITY_DLL_SPEC detail_log(const char * str, ...) ATTR_PRINTF(1,2);
void TRINITY_DLL_SPEC debug_log(const char * str, ...) ATTR_PRINTF(1,2);
void TRINITY_DLL_SPEC error_log(const char * str, ...) ATTR_PRINTF(1,2);
void TRINITY_DLL_SPEC error_db_log(const char * str, ...) ATTR_PRINTF(1,2);
2008-10-02 16:23:55 -05:00
#endif
2009-02-17 20:07:49 -06:00