2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOSSERVER_LOG_H
20 #define MANGOSSERVER_LOG_H
23 #include "Policies/Singleton.h"
30 LOG_LVL_MINIMAL
= 0, // unconditional and errors
36 // bitmask (not forgot update logFilterData content)
39 LOG_FILTER_TRANSPORT_MOVES
= 0x000001, // 0 any related to transport moves
40 LOG_FILTER_CREATURE_MOVES
= 0x000002, // 1 creature move by cells
41 LOG_FILTER_VISIBILITY_CHANGES
= 0x000004, // 2 update visibility for diff objects and players
42 LOG_FILTER_ACHIEVEMENT_UPDATES
= 0x000008, // 3 achievement update broadcasts
43 LOG_FILTER_WEATHER
= 0x000010, // 4 weather changes
44 LOG_FILTER_PLAYER_STATS
= 0x000020, // 5 player save data
45 LOG_FILTER_SQL_TEXT
= 0x000040, // 6 raw SQL text send to DB engine
46 LOG_FILTER_PLAYER_MOVES
= 0x000080, // 7 player moves by grid/cell
47 LOG_FILTER_PERIODIC_AFFECTS
= 0x000100, // 8 DoT/HoT apply trace
48 LOG_FILTER_AI_AND_MOVEGENSS
= 0x000200, // 9 AI/movement generators debug output
49 LOG_FILTER_DAMAGE
= 0x000400, // 10 Direct/Area damage trace
50 LOG_FILTER_COMBAT
= 0x000800, // 11 attack states/roll attack results/etc
51 LOG_FILTER_SPELL_CAST
= 0x001000, // 12 spell cast/aura apply/spell proc events
52 LOG_FILTER_DB_STRICTED_CHECK
= 0x002000, // 13 stricted DB data checks output (with possible false reports) for DB devs
53 LOG_FILTER_AHBOT_SELLER
= 0x004000, // 14 Auction House Bot seller part
54 LOG_FILTER_AHBOT_BUYER
= 0x008000, // 15 Auction House Bot buyer part
55 LOG_FILTER_PATHFINDING
= 0x010000, // 16 Pathfinding
58 #define LOG_FILTER_COUNT 17
63 char const* configName
;
67 extern LogFilterData logFilterData
[LOG_FILTER_COUNT
];
88 const int Color_count
= int(WHITE
) + 1;
90 class Log
: public MaNGOS::Singleton
<Log
, MaNGOS::ClassLevelLockable
<Log
, ACE_Thread_Mutex
> >
92 friend class MaNGOS::OperatorNew
<Log
>;
101 if (gmLogfile
!= NULL
)
105 if (charLogfile
!= NULL
)
109 if (dberLogfile
!= NULL
)
113 if (raLogfile
!= NULL
)
117 if (worldLogfile
!= NULL
)
118 fclose(worldLogfile
);
123 void InitColors(const std::string
& init_str
);
125 void outCommand(uint32 account
, const char* str
, ...) ATTR_PRINTF(3, 4);
126 void outString(); // any log level
128 void outString(const char* str
, ...) ATTR_PRINTF(2, 3);
130 void outError(const char* err
, ...) ATTR_PRINTF(2, 3);
132 void outBasic(const char* str
, ...) ATTR_PRINTF(2, 3);
134 void outDetail(const char* str
, ...) ATTR_PRINTF(2, 3);
136 void outDebug(const char* str
, ...) ATTR_PRINTF(2, 3);
138 void outErrorDb(); // any log level
140 void outErrorDb(const char* str
, ...) ATTR_PRINTF(2, 3);
142 void outChar(const char* str
, ...) ATTR_PRINTF(2, 3);
144 void outWorldPacketDump(uint32 socket
, uint32 opcode
, char const* opcodeName
, ByteBuffer
const* packet
, bool incoming
);
146 void outCharDump(const char* str
, uint32 account_id
, uint32 guid
, const char* name
);
147 void outRALog(const char* str
, ...) ATTR_PRINTF(2, 3);
148 uint32
GetLogLevel() const { return m_logLevel
; }
149 void SetLogLevel(char* Level
);
150 void SetLogFileLevel(char* Level
);
151 void SetColor(bool stdout_stream
, Color color
);
152 void ResetColor(bool stdout_stream
);
154 static void outTimestamp(FILE* file
);
155 static std::string
GetTimestampStr();
156 bool HasLogFilter(uint32 filter
) const { return m_logFilter
& filter
; }
157 void SetLogFilter(LogFilters filter
, bool on
) { if (on
) m_logFilter
|= filter
; else m_logFilter
&= ~filter
; }
158 bool HasLogLevelOrHigher(LogLevel loglvl
) const { return m_logLevel
>= loglvl
|| (m_logFileLevel
>= loglvl
&& logfile
); }
159 bool IsOutCharDump() const { return m_charLog_Dump
; }
160 bool IsIncludeTime() const { return m_includeTime
; }
162 static void WaitBeforeContinueIfNeed();
164 FILE* openLogFile(char const* configFileName
, char const* configTimeStampFlag
, char const* mode
);
165 FILE* openGmlogPerAccount(uint32 account
);
173 ACE_Thread_Mutex m_worldLogMtx
;
175 // log/console control
177 LogLevel m_logFileLevel
;
183 // cache values for after initilization use (like gm log per account case)
184 std::string m_logsDir
;
185 std::string m_logsTimestamp
;
191 bool m_gmlog_per_account
;
192 std::string m_gmlog_filename_format
;
195 #define sLog MaNGOS::Singleton<Log>::Instance()
197 #define BASIC_LOG(...) \
199 if (sLog.HasLogLevelOrHigher(LOG_LVL_BASIC)) \
200 sLog.outBasic(__VA_ARGS__); \
203 #define BASIC_FILTER_LOG(F,...) \
205 if (sLog.HasLogLevelOrHigher(LOG_LVL_BASIC) && !sLog.HasLogFilter(F)) \
206 sLog.outBasic(__VA_ARGS__); \
209 #define DETAIL_LOG(...) \
211 if (sLog.HasLogLevelOrHigher(LOG_LVL_DETAIL)) \
212 sLog.outDetail(__VA_ARGS__); \
215 #define DETAIL_FILTER_LOG(F,...) \
217 if (sLog.HasLogLevelOrHigher(LOG_LVL_DETAIL) && !sLog.HasLogFilter(F)) \
218 sLog.outDetail(__VA_ARGS__); \
221 #define DEBUG_LOG(...) \
223 if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) \
224 sLog.outDebug(__VA_ARGS__); \
227 #define DEBUG_FILTER_LOG(F,...) \
229 if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG) && !sLog.HasLogFilter(F)) \
230 sLog.outDebug(__VA_ARGS__); \
233 #define ERROR_DB_FILTER_LOG(F,...) \
235 if (!sLog.HasLogFilter(F)) \
236 sLog.outErrorDb(__VA_ARGS__); \
239 #define ERROR_DB_STRICT_LOG(...) \
240 ERROR_DB_FILTER_LOG(LOG_FILTER_DB_STRICTED_CHECK, __VA_ARGS__)
242 // primary for script library
243 void MANGOS_DLL_SPEC
outstring_log(const char* str
, ...) ATTR_PRINTF(1, 2);
244 void MANGOS_DLL_SPEC
detail_log(const char* str
, ...) ATTR_PRINTF(1, 2);
245 void MANGOS_DLL_SPEC
debug_log(const char* str
, ...) ATTR_PRINTF(1, 2);
246 void MANGOS_DLL_SPEC
error_log(const char* str
, ...) ATTR_PRINTF(1, 2);
247 void MANGOS_DLL_SPEC
error_db_log(const char* str
, ...) ATTR_PRINTF(1, 2);