Files
TCPlayerbotCore/src/server/shared/Logging/Log.cpp
T

1080 lines
26 KiB
C++
Raw Normal View History

/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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 MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the 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, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
#include "Log.h"
#include "Configuration/Config.h"
2008-10-02 16:23:55 -05:00
#include "Util.h"
2009-10-17 15:51:44 -07:00
2010-09-03 00:04:14 +02:00
#include "Implementation/LoginDatabase.h" // For logging
extern LoginDatabaseWorkerPool LoginDatabase;
2008-10-02 16:23:55 -05:00
#include <stdarg.h>
2009-03-19 21:13:52 +01:00
#include <stdio.h>
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
Log::Log() :
raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL),
dberLogfile(NULL), chatLogfile(NULL), arenaLogFile(NULL), sqlLogFile(NULL), sqlDevLogFile(NULL), wardenLogFile(NULL),
2010-09-12 01:40:27 +02:00
m_gmlog_per_account(false), m_enableLogDBLater(false),
2010-08-21 20:08:47 +02:00
m_enableLogDB(false), m_colored(false)
2008-11-25 16:36:50 -06:00
{
Initialize();
}
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
Log::~Log()
2008-10-02 16:23:55 -05:00
{
2011-09-29 12:43:05 +02:00
if ( logfile != NULL )
2009-03-19 21:13:52 +01:00
fclose(logfile);
logfile = NULL;
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if ( gmLogfile != NULL )
2009-03-19 21:13:52 +01:00
fclose(gmLogfile);
gmLogfile = NULL;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
if (charLogfile != NULL)
fclose(charLogfile);
charLogfile = NULL;
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if ( dberLogfile != NULL )
2009-03-19 21:13:52 +01:00
fclose(dberLogfile);
dberLogfile = NULL;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
if (raLogfile != NULL)
fclose(raLogfile);
raLogfile = NULL;
2009-10-17 15:51:44 -07:00
2009-03-27 16:52:27 +01:00
if (chatLogfile != NULL)
fclose(chatLogfile);
chatLogfile = NULL;
2009-10-17 15:51:44 -07:00
2009-06-01 15:53:03 -05:00
if (arenaLogFile != NULL)
fclose(arenaLogFile);
arenaLogFile = NULL;
2010-08-26 21:50:54 +02:00
if (sqlLogFile != NULL)
fclose(sqlLogFile);
sqlLogFile = NULL;
if (sqlDevLogFile != NULL)
fclose(sqlDevLogFile);
sqlDevLogFile = NULL;
if (wardenLogFile != NULL)
fclose(wardenLogFile);
wardenLogFile = NULL;
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void Log::SetLogLevel(char *Level)
{
int32 NewLevel =atoi((char*)Level);
if ( NewLevel <0 )
NewLevel = 0;
m_logLevel = NewLevel;
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
outString( "LogLevel is %u", m_logLevel );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void Log::SetLogFileLevel(char *Level)
{
int32 NewLevel =atoi((char*)Level);
if ( NewLevel <0 )
NewLevel = 0;
m_logFileLevel = NewLevel;
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
outString( "LogFileLevel is %u", m_logFileLevel );
2009-03-19 21:13:52 +01:00
}
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
void Log::SetDBLogLevel(char *Level)
{
int32 NewLevel = atoi((char*)Level);
if ( NewLevel < 0 )
NewLevel = 0;
m_dbLogLevel = NewLevel;
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
outString( "DBLogLevel is %u", m_dbLogLevel );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void Log::Initialize()
{
2009-03-26 16:46:08 +01:00
/// Check whether we'll log GM commands/RA events/character outputs/chat stuffs
m_dbChar = ConfigMgr::GetBoolDefault("LogDB.Char", false);
m_dbRA = ConfigMgr::GetBoolDefault("LogDB.RA", false);
m_dbGM = ConfigMgr::GetBoolDefault("LogDB.GM", false);
m_dbChat = ConfigMgr::GetBoolDefault("LogDB.Chat", false);
2009-10-17 15:51:44 -07:00
2009-03-26 16:46:08 +01:00
/// Realm must be 0 by default
SetRealmID(0);
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
/// Common log files data
m_logsDir = ConfigMgr::GetStringDefault("LogsDir", "");
if (!m_logsDir.empty())
if ((m_logsDir.at(m_logsDir.length() - 1) != '/') && (m_logsDir.at(m_logsDir.length() - 1) != '\\'))
m_logsDir.push_back('/');
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
m_logsTimestamp = "_" + GetTimestampStr();
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
/// Open specific log files
2011-04-29 20:47:02 +02:00
logfile = openLogFile("LogFile", "LogTimestamp", "w");
InitColors(ConfigMgr::GetStringDefault("LogColors", ""));
2009-10-17 15:51:44 -07:00
m_gmlog_per_account = ConfigMgr::GetBoolDefault("GmLogPerAccount", false);
2011-09-29 12:43:05 +02:00
if (!m_gmlog_per_account)
2011-04-29 20:47:02 +02:00
gmLogfile = openLogFile("GMLogFile", "GmLogTimestamp", "a");
2008-11-25 16:36:50 -06:00
else
2008-10-02 16:23:55 -05:00
{
2008-11-25 16:36:50 -06:00
// GM log settings for per account case
m_gmlog_filename_format = ConfigMgr::GetStringDefault("GMLogFile", "");
2011-09-29 12:43:05 +02:00
if (!m_gmlog_filename_format.empty())
2008-10-02 16:23:55 -05:00
{
bool m_gmlog_timestamp = ConfigMgr::GetBoolDefault("GmLogTimestamp", false);
2009-10-17 15:51:44 -07:00
2011-10-18 14:59:23 +02:00
size_t dot_pos = m_gmlog_filename_format.find_last_of('.');
2011-09-29 12:43:05 +02:00
if (dot_pos!=m_gmlog_filename_format.npos)
2008-11-25 16:36:50 -06:00
{
2011-09-29 12:43:05 +02:00
if (m_gmlog_timestamp)
2011-04-29 20:47:02 +02:00
m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp);
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
m_gmlog_filename_format.insert(dot_pos, "_#%u");
2008-11-25 16:36:50 -06:00
}
2008-10-02 16:23:55 -05:00
else
2008-11-25 16:36:50 -06:00
{
m_gmlog_filename_format += "_#%u";
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if (m_gmlog_timestamp)
2008-11-25 16:36:50 -06:00
m_gmlog_filename_format += m_logsTimestamp;
}
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
m_gmlog_filename_format = m_logsDir + m_gmlog_filename_format;
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
2010-08-26 21:50:54 +02:00
charLogfile = openLogFile("CharLogFile", "CharLogTimestamp", "a");
dberLogfile = openLogFile("DBErrorLogFile", NULL, "a");
raLogfile = openLogFile("RaLogFile", NULL, "a");
chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a");
2011-04-29 20:47:02 +02:00
arenaLogFile = openLogFile("ArenaLogFile", NULL, "a");
2010-08-26 21:50:54 +02:00
sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a");
sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a");
wardenLogFile = openLogFile("Warden.LogFile",NULL,"a");
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
// Main log file settings
m_logLevel = ConfigMgr::GetIntDefault("LogLevel", LOGL_NORMAL);
m_logFileLevel = ConfigMgr::GetIntDefault("LogFileLevel", LOGL_NORMAL);
m_dbLogLevel = ConfigMgr::GetIntDefault("DBLogLevel", LOGL_NORMAL);
m_sqlDriverQueryLogging = ConfigMgr::GetBoolDefault("SQLDriverQueryLogging", false);
2009-10-17 15:51:44 -07:00
m_DebugLogMask = DebugLogFilters(ConfigMgr::GetIntDefault("DebugLogMask", LOG_FILTER_NONE));
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
// Char log settings
m_charLog_Dump = ConfigMgr::GetBoolDefault("CharLogDump", false);
m_charLog_Dump_Separate = ConfigMgr::GetBoolDefault("CharLogDump.Separate", false);
if (m_charLog_Dump_Separate)
{
m_dumpsDir = ConfigMgr::GetStringDefault("CharLogDump.SeparateDir", "");
if (!m_dumpsDir.empty())
if ((m_dumpsDir.at(m_dumpsDir.length() - 1) != '/') && (m_dumpsDir.at(m_dumpsDir.length() - 1) != '\\'))
m_dumpsDir.push_back('/');
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-08 23:00:26 -03:00
void Log::ReloadConfig()
{
m_logLevel = ConfigMgr::GetIntDefault("LogLevel", LOGL_NORMAL);
m_logFileLevel = ConfigMgr::GetIntDefault("LogFileLevel", LOGL_NORMAL);
m_dbLogLevel = ConfigMgr::GetIntDefault("DBLogLevel", LOGL_NORMAL);
2011-09-08 23:00:26 -03:00
m_DebugLogMask = DebugLogFilters(ConfigMgr::GetIntDefault("DebugLogMask", LOG_FILTER_NONE));
2011-09-08 23:00:26 -03:00
}
2011-04-29 20:47:02 +02:00
FILE* Log::openLogFile(char const* configFileName, char const* configTimeStampFlag, char const* mode)
2008-11-25 16:36:50 -06:00
{
std::string logfn=ConfigMgr::GetStringDefault(configFileName, "");
2011-09-29 12:43:05 +02:00
if (logfn.empty())
2008-11-25 16:36:50 -06:00
return NULL;
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if (configTimeStampFlag && ConfigMgr::GetBoolDefault(configTimeStampFlag, false))
2008-11-25 16:36:50 -06:00
{
size_t dot_pos = logfn.find_last_of(".");
2011-09-29 12:43:05 +02:00
if (dot_pos!=logfn.npos)
2011-04-29 20:47:02 +02:00
logfn.insert(dot_pos, m_logsTimestamp);
2008-11-25 16:36:50 -06:00
else
logfn += m_logsTimestamp;
}
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
return fopen((m_logsDir+logfn).c_str(), mode);
}
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
FILE* Log::openGmlogPerAccount(uint32 account)
{
2011-09-29 12:43:05 +02:00
if (m_gmlog_filename_format.empty())
2008-11-25 16:36:50 -06:00
return NULL;
2009-10-17 15:51:44 -07:00
2008-11-26 14:23:50 -06:00
char namebuf[TRINITY_PATH_MAX];
2011-04-29 20:47:02 +02:00
snprintf(namebuf, TRINITY_PATH_MAX, m_gmlog_filename_format.c_str(), account);
2008-11-25 16:36:50 -06:00
return fopen(namebuf, "a");
}
2009-10-17 15:51:44 -07:00
void Log::outTimestamp(FILE* file)
{
time_t t = time(NULL);
tm* aTm = localtime(&t);
// YYYY year
// MM month (2 digits 01-12)
// DD day (2 digits 01-31)
// HH hour (2 digits 00-23)
// MM minutes (2 digits 00-59)
// SS seconds (2 digits 00-59)
2011-04-29 20:47:02 +02:00
fprintf(file, "%-4d-%02d-%02d %02d:%02d:%02d ", aTm->tm_year+1900, aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec);
}
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
void Log::InitColors(const std::string& str)
{
2011-09-29 12:43:05 +02:00
if (str.empty())
2009-03-20 18:16:36 +01:00
{
m_colored = false;
return;
}
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
int color[4];
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
std::istringstream ss(str);
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (uint8 i = 0; i < LogLevels; ++i)
2009-03-20 18:16:36 +01:00
{
ss >> color[i];
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if (!ss)
2009-03-20 18:16:36 +01:00
return;
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if (color[i] < 0 || color[i] >= Colors)
2009-03-20 18:16:36 +01:00
return;
}
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for (uint8 i = 0; i < LogLevels; ++i)
2009-03-20 18:16:36 +01:00
m_colors[i] = ColorTypes(color[i]);
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
m_colored = true;
}
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
void Log::SetColor(bool stdout_stream, ColorTypes color)
{
#if PLATFORM == PLATFORM_WINDOWS
static WORD WinColorFG[Colors] =
{
0, // BLACK
FOREGROUND_RED, // RED
FOREGROUND_GREEN, // GREEN
FOREGROUND_RED | FOREGROUND_GREEN, // BROWN
FOREGROUND_BLUE, // BLUE
2011-04-29 20:47:02 +02:00
FOREGROUND_RED | FOREGROUND_BLUE, // MAGENTA
2009-03-20 18:16:36 +01:00
FOREGROUND_GREEN | FOREGROUND_BLUE, // CYAN
2011-04-29 20:47:02 +02:00
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE, // WHITE
2009-03-20 18:16:36 +01:00
// YELLOW
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
// RED_BOLD
FOREGROUND_RED | FOREGROUND_INTENSITY,
// GREEN_BOLD
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
FOREGROUND_BLUE | FOREGROUND_INTENSITY, // BLUE_BOLD
// MAGENTA_BOLD
FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
// CYAN_BOLD
FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
// WHITE_BOLD
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
};
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE );
SetConsoleTextAttribute(hConsole, WinColorFG[color]);
#else
enum ANSITextAttr
{
TA_NORMAL=0,
TA_BOLD=1,
TA_BLINK=5,
TA_REVERSE=7
};
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
enum ANSIFgTextAttr
{
FG_BLACK=30, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
FG_MAGENTA, FG_CYAN, FG_WHITE, FG_YELLOW
};
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
enum ANSIBgTextAttr
{
BG_BLACK=40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
BG_MAGENTA, BG_CYAN, BG_WHITE
};
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
static uint8 UnixColorFG[Colors] =
{
FG_BLACK, // BLACK
FG_RED, // RED
FG_GREEN, // GREEN
FG_BROWN, // BROWN
FG_BLUE, // BLUE
FG_MAGENTA, // MAGENTA
FG_CYAN, // CYAN
FG_WHITE, // WHITE
FG_YELLOW, // YELLOW
FG_RED, // LRED
FG_GREEN, // LGREEN
FG_BLUE, // LBLUE
FG_MAGENTA, // LMAGENTA
FG_CYAN, // LCYAN
FG_WHITE // LWHITE
};
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm", UnixColorFG[color], (color >= YELLOW && color < Colors ? ";1" : ""));
#endif
}
2009-10-17 15:51:44 -07:00
2009-03-20 18:16:36 +01:00
void Log::ResetColor(bool stdout_stream)
{
#if PLATFORM == PLATFORM_WINDOWS
HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE );
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED );
#else
fprintf(( stdout_stream ? stdout : stderr ), "\x1b[0m");
#endif
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
std::string Log::GetTimestampStr()
{
time_t t = time(NULL);
tm* aTm = localtime(&t);
// YYYY year
// MM month (2 digits 01-12)
// DD day (2 digits 01-31)
// HH hour (2 digits 00-23)
// MM minutes (2 digits 00-59)
// SS seconds (2 digits 00-59)
char buf[20];
2011-04-29 20:47:02 +02:00
snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm->tm_year+1900, aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec);
2008-10-02 16:23:55 -05:00
return std::string(buf);
}
2009-10-17 15:51:44 -07:00
void Log::outDB(LogTypes type, const char * str)
2008-10-02 16:23:55 -05:00
{
if (!str || type >= MAX_LOG_TYPES)
return;
2009-10-17 15:51:44 -07:00
std::string logStr(str);
if (logStr.empty())
return;
2009-10-17 15:51:44 -07:00
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_LOG);
stmt->setInt32(0, realm);
stmt->setInt32(1, type);
stmt->setString(2, logStr);
LoginDatabase.Execute(stmt);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
void Log::outString(const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!str)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
if (m_enableLogDB)
{
// we don't want empty strings in the DB
std::string s(str);
if (s.empty() || s == " ")
2009-03-19 21:13:52 +01:00
return;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_STRING, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(true, m_colors[LOGL_NORMAL]);
2009-10-17 15:51:44 -07:00
va_list ap;
2009-10-17 15:51:44 -07:00
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (m_colored)
2009-03-20 18:16:36 +01:00
ResetColor(true);
2009-10-17 15:51:44 -07:00
printf("\n");
2011-09-29 12:43:05 +02:00
if (logfile)
2008-10-02 16:23:55 -05:00
{
outTimestamp(logfile);
2008-10-02 16:23:55 -05:00
va_start(ap, str);
vfprintf(logfile, str, ap);
fprintf(logfile, "\n");
2008-10-02 16:23:55 -05:00
va_end(ap);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fflush(logfile);
}
fflush(stdout);
}
2009-10-17 15:51:44 -07:00
void Log::outString()
{
printf("\n");
if (logfile)
{
outTimestamp(logfile);
fprintf(logfile, "\n");
fflush(logfile);
}
fflush(stdout);
}
2009-10-17 15:51:44 -07:00
void Log::outCrash(const char * err, ...)
{
if (!err)
return;
2009-10-17 15:51:44 -07:00
if (m_enableLogDB)
{
va_list ap2;
va_start(ap2, err);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, err, ap2);
outDB(LOG_TYPE_CRASH, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(false, LRED);
2009-10-17 15:51:44 -07:00
va_list ap;
2009-10-17 15:51:44 -07:00
va_start(ap, err);
vutf8printf(stderr, err, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (m_colored)
ResetColor(false);
2009-10-17 15:51:44 -07:00
fprintf(stderr, "\n");
if (logfile)
{
outTimestamp(logfile);
fprintf(logfile, "CRASH ALERT: ");
2009-10-17 15:51:44 -07:00
va_start(ap, err);
vfprintf(logfile, err, ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
fprintf(logfile, "\n");
fflush(logfile);
}
fflush(stderr);
}
2009-10-17 15:51:44 -07:00
void Log::outError(const char * err, ...)
2008-10-02 16:23:55 -05:00
{
if (!err)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
if (m_enableLogDB)
{
va_list ap2;
va_start(ap2, err);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, err, ap2);
outDB(LOG_TYPE_ERROR, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(false, LRED);
2009-10-17 15:51:44 -07:00
va_list ap;
2009-10-17 15:51:44 -07:00
va_start(ap, err);
vutf8printf(stderr, err, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (m_colored)
2009-03-20 18:16:36 +01:00
ResetColor(false);
2009-10-17 15:51:44 -07:00
fprintf( stderr, "\n");
if (logfile)
2008-10-02 16:23:55 -05:00
{
outTimestamp(logfile);
fprintf(logfile, "ERROR: ");
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
va_start(ap, err);
vfprintf(logfile, err, ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
fprintf(logfile, "\n");
2008-10-02 16:23:55 -05:00
fflush(logfile);
}
fflush(stderr);
}
2009-10-17 15:51:44 -07:00
void Log::outArena(const char * str, ...)
{
if (!str)
return;
2009-10-17 15:51:44 -07:00
if (arenaLogFile)
{
va_list ap;
outTimestamp(arenaLogFile);
va_start(ap, str);
vfprintf(arenaLogFile, str, ap);
fprintf(arenaLogFile, "\n");
va_end(ap);
fflush(arenaLogFile);
}
}
2009-10-17 15:51:44 -07:00
2010-08-26 21:50:54 +02:00
void Log::outSQLDriver(const char* str, ...)
{
if (!str)
return;
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
printf("\n");
2010-08-26 21:50:54 +02:00
if (sqlLogFile)
{
outTimestamp(sqlLogFile);
va_list apSQL;
va_start(apSQL, str);
vfprintf(sqlLogFile, str, apSQL);
va_end(apSQL);
2010-08-26 21:50:54 +02:00
fprintf(sqlLogFile, "\n");
2010-08-26 21:50:54 +02:00
fflush(sqlLogFile);
}
2010-08-26 21:50:54 +02:00
fflush(stdout);
}
void Log::outErrorDb(const char * err, ...)
2008-10-02 16:23:55 -05:00
{
if (!err)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(false, LRED);
2009-10-17 15:51:44 -07:00
va_list ap;
2009-10-17 15:51:44 -07:00
va_start(ap, err);
vutf8printf(stderr, err, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (m_colored)
2009-03-20 18:16:36 +01:00
ResetColor(false);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fprintf( stderr, "\n" );
2009-10-17 15:51:44 -07:00
if (logfile)
2008-10-02 16:23:55 -05:00
{
outTimestamp(logfile);
2009-03-24 14:34:50 +01:00
fprintf(logfile, "ERROR: " );
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
va_start(ap, err);
vfprintf(logfile, err, ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fprintf(logfile, "\n" );
fflush(logfile);
}
2009-10-17 15:51:44 -07:00
if (dberLogfile)
2008-10-02 16:23:55 -05:00
{
outTimestamp(dberLogfile);
2008-10-02 16:23:55 -05:00
va_start(ap, err);
vfprintf(dberLogfile, err, ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fprintf(dberLogfile, "\n" );
fflush(dberLogfile);
}
fflush(stderr);
}
2009-10-17 15:51:44 -07:00
void Log::outBasic(const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!str)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
if (m_enableLogDB && m_dbLogLevel > LOGL_NORMAL)
2008-10-02 16:23:55 -05:00
{
2009-03-19 21:13:52 +01:00
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_BASIC, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (m_logLevel > LOGL_NORMAL)
2009-03-19 21:13:52 +01:00
{
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(true, m_colors[LOGL_BASIC]);
2009-10-17 15:51:44 -07:00
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (m_colored)
2009-03-20 18:16:36 +01:00
ResetColor(true);
2009-10-17 15:51:44 -07:00
printf("\n");
2009-10-17 15:51:44 -07:00
if (logfile)
{
outTimestamp(logfile);
va_list ap2;
va_start(ap2, str);
vfprintf(logfile, str, ap2);
fprintf(logfile, "\n" );
va_end(ap2);
fflush(logfile);
}
2008-10-02 16:23:55 -05:00
}
fflush(stdout);
}
2009-10-17 15:51:44 -07:00
void Log::outDetail(const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!str)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2009-03-21 12:13:32 +01:00
if (m_enableLogDB && m_dbLogLevel > LOGL_BASIC)
2008-10-02 16:23:55 -05:00
{
2009-03-19 21:13:52 +01:00
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_DETAIL, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (m_logLevel > LOGL_BASIC)
2009-03-19 21:13:52 +01:00
{
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(true, m_colors[LOGL_DETAIL]);
2009-10-17 15:51:44 -07:00
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (m_colored)
2009-03-20 18:16:36 +01:00
ResetColor(true);
2009-10-17 15:51:44 -07:00
printf("\n");
2009-10-17 15:51:44 -07:00
if (logfile)
{
outTimestamp(logfile);
va_list ap2;
va_start(ap2, str);
vfprintf(logfile, str, ap2);
va_end(ap2);
2009-10-17 15:51:44 -07:00
fprintf(logfile, "\n");
fflush(logfile);
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fflush(stdout);
}
2009-10-17 15:51:44 -07:00
void Log::outDebugInLine(const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!str)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
if (m_logLevel > LOGL_DETAIL)
2008-10-02 16:23:55 -05:00
{
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
//if (m_colored)
// ResetColor(true);
2009-10-17 15:51:44 -07:00
if (logfile)
{
va_list ap2;
va_start(ap2, str);
vfprintf(logfile, str, ap2);
va_end(ap2);
}
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
void Log::outSQLDev(const char* str, ...)
{
if (!str)
return;
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
printf("\n");
if (sqlDevLogFile)
{
va_list ap2;
va_start(ap2, str);
vfprintf(sqlDevLogFile, str, ap2);
va_end(ap2);
fprintf(sqlDevLogFile, "\n");
fflush(sqlDevLogFile);
}
fflush(stdout);
}
void Log::outDebug(DebugLogFilters f, const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!(m_DebugLogMask & f))
return;
if (!str)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2009-03-21 12:13:32 +01:00
if (m_enableLogDB && m_dbLogLevel > LOGL_DETAIL)
2009-03-19 21:13:52 +01:00
{
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_DEBUG, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if ( m_logLevel > LOGL_DETAIL )
2009-03-19 21:13:52 +01:00
{
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(true, m_colors[LOGL_DEBUG]);
2009-10-17 15:51:44 -07:00
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
if (m_colored)
2009-03-20 18:16:36 +01:00
ResetColor(true);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
printf( "\n" );
2009-10-17 15:51:44 -07:00
if (logfile)
{
outTimestamp(logfile);
va_list ap2;
va_start(ap2, str);
vfprintf(logfile, str, ap2);
va_end(ap2);
2009-10-17 15:51:44 -07:00
fprintf(logfile, "\n" );
fflush(logfile);
}
2008-10-02 16:23:55 -05:00
}
fflush(stdout);
}
2009-10-17 15:51:44 -07:00
void Log::outStaticDebug(const char * str, ...)
{
if (!str)
return;
if (m_enableLogDB && m_dbLogLevel > LOGL_DETAIL)
{
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_DEBUG, nnew_str);
va_end(ap2);
}
2011-09-29 12:43:05 +02:00
if ( m_logLevel > LOGL_DETAIL )
{
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(true, m_colors[LOGL_DEBUG]);
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2011-09-29 12:43:05 +02:00
if (m_colored)
ResetColor(true);
printf( "\n" );
if (logfile)
{
outTimestamp(logfile);
va_list ap2;
va_start(ap2, str);
vfprintf(logfile, str, ap2);
va_end(ap2);
fprintf(logfile, "\n" );
fflush(logfile);
}
}
fflush(stdout);
}
void Log::outStringInLine(const char * str, ...)
2009-08-11 10:53:29 -05:00
{
if (!str)
2009-08-11 10:53:29 -05:00
return;
2009-10-17 15:51:44 -07:00
va_list ap;
2009-10-17 15:51:44 -07:00
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (logfile)
2009-08-11 10:53:29 -05:00
{
va_start(ap, str);
vfprintf(logfile, str, ap);
va_end(ap);
}
}
2009-10-17 15:51:44 -07:00
void Log::outCommand(uint32 account, const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!str)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
// TODO: support accountid
if (m_enableLogDB && m_dbGM)
2008-10-02 16:23:55 -05:00
{
2009-03-19 21:13:52 +01:00
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_GM, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (m_logLevel > LOGL_NORMAL)
2009-03-19 21:13:52 +01:00
{
if (m_colored)
2011-04-29 20:47:02 +02:00
SetColor(true, m_colors[LOGL_BASIC]);
2009-10-17 15:51:44 -07:00
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
2009-10-17 15:51:44 -07:00
if (m_colored)
2009-03-20 18:16:36 +01:00
ResetColor(true);
2009-10-17 15:51:44 -07:00
printf("\n");
2009-10-17 15:51:44 -07:00
if (logfile)
{
outTimestamp(logfile);
va_list ap2;
va_start(ap2, str);
vfprintf(logfile, str, ap2);
fprintf(logfile, "\n" );
va_end(ap2);
fflush(logfile);
}
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
if (m_gmlog_per_account)
{
if (FILE* per_file = openGmlogPerAccount (account))
{
outTimestamp(per_file);
2008-11-25 16:36:50 -06:00
va_list ap;
va_start(ap, str);
vfprintf(per_file, str, ap);
fprintf(per_file, "\n" );
va_end(ap);
fclose(per_file);
}
}
else if (gmLogfile)
2008-10-02 16:23:55 -05:00
{
outTimestamp(gmLogfile);
2008-10-02 16:23:55 -05:00
va_list ap;
va_start(ap, str);
vfprintf(gmLogfile, str, ap);
fprintf(gmLogfile, "\n" );
va_end(ap);
fflush(gmLogfile);
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
fflush(stdout);
}
2009-10-17 15:51:44 -07:00
void Log::outChar(const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!str)
return;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
if (m_enableLogDB && m_dbChar)
{
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_CHAR, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (charLogfile)
2008-10-02 16:23:55 -05:00
{
outTimestamp(charLogfile);
2008-10-02 16:23:55 -05:00
va_list ap;
va_start(ap, str);
vfprintf(charLogfile, str, ap);
fprintf(charLogfile, "\n" );
va_end(ap);
fflush(charLogfile);
}
}
2009-10-17 15:51:44 -07:00
void Log::outCharDump(const char * str, uint32 account_id, uint32 guid, const char * name)
2008-10-02 16:23:55 -05:00
{
FILE* file = NULL;
if (m_charLog_Dump_Separate)
{
char fileName[29]; // Max length: name(12) + guid(11) + _.log (5) + \0
snprintf(fileName, 29, "%d_%s.log", guid, name);
std::string sFileName(m_dumpsDir);
sFileName.append(fileName);
file = fopen((m_logsDir + sFileName).c_str(), "w");
}
else
file = charLogfile;
if (file)
{
fprintf(file, "== START DUMP == (account: %u guid: %u name: %s )\n%s\n== END DUMP ==\n",
account_id, guid, name, str);
fflush(file);
if (m_charLog_Dump_Separate)
fclose(file);
2008-10-02 16:23:55 -05:00
}
}
2009-10-17 15:51:44 -07:00
void Log::outRemote(const char * str, ...)
2008-10-02 16:23:55 -05:00
{
if (!str)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2009-03-19 21:13:52 +01:00
if (m_enableLogDB && m_dbRA)
2008-10-02 16:23:55 -05:00
{
2009-03-19 21:13:52 +01:00
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_RA, nnew_str);
va_end(ap2);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
if (raLogfile)
{
outTimestamp(raLogfile);
2009-03-19 21:13:52 +01:00
va_list ap;
2008-10-02 16:23:55 -05:00
va_start(ap, str);
vfprintf(raLogfile, str, ap);
fprintf(raLogfile, "\n" );
va_end(ap);
fflush(raLogfile);
}
}
2009-10-17 15:51:44 -07:00
void Log::outChat(const char * str, ...)
{
if (!str)
return;
2009-10-17 15:51:44 -07:00
if (m_enableLogDB && m_dbChat)
{
va_list ap2;
va_start(ap2, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap2);
outDB(LOG_TYPE_CHAT, nnew_str);
va_end(ap2);
}
2009-10-17 15:51:44 -07:00
if (chatLogfile)
{
2009-03-27 17:03:06 +01:00
outTimestamp(chatLogfile);
va_list ap;
va_start(ap, str);
2009-04-07 16:18:48 -05:00
vfprintf(chatLogfile, str, ap);
fprintf(chatLogfile, "\n" );
fflush(chatLogfile);
va_end(ap);
}
2008-10-02 16:23:55 -05:00
}
void Log::outErrorST(const char * str, ...)
{
va_list ap;
va_start(ap, str);
char nnew_str[MAX_QUERY_LEN];
vsnprintf(nnew_str, MAX_QUERY_LEN, str, ap);
va_end(ap);
ACE_Stack_Trace st;
outError("%s [Stacktrace: %s]", nnew_str, st.c_str());
}
void Log::outWarden(const char * str, ...)
{
if (!str)
return;
if (wardenLogFile)
{
outTimestamp(wardenLogFile);
va_list ap;
va_start(ap, str);
vfprintf(wardenLogFile, str, ap);
fprintf(wardenLogFile, "\n" );
fflush(wardenLogFile);
va_end(ap);
}
}