[9133] Fixes in talent 11129 work.
[getmangos.git] / src / shared / Log.h
blob9d08d66b35d3a7a0bc9c6ef54430be2b1223a9f1
1 /*
2 * Copyright (C) 2005-2010 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
22 #include "Common.h"
23 #include "Policies/Singleton.h"
25 class Config;
26 class ByteBuffer;
28 // bitmask
29 enum LogFilters
31 LOG_FILTER_TRANSPORT_MOVES = 1,
32 LOG_FILTER_CREATURE_MOVES = 2,
33 LOG_FILTER_VISIBILITY_CHANGES = 4,
34 LOG_FILTER_ACHIEVEMENT_UPDATES= 8
37 enum Color
39 BLACK,
40 RED,
41 GREEN,
42 BROWN,
43 BLUE,
44 MAGENTA,
45 CYAN,
46 GREY,
47 YELLOW,
48 LRED,
49 LGREEN,
50 LBLUE,
51 LMAGENTA,
52 LCYAN,
53 WHITE
56 const int Color_count = int(WHITE)+1;
58 class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Thread_Mutex> >
60 friend class MaNGOS::OperatorNew<Log>;
61 Log();
63 ~Log()
65 if( logfile != NULL )
66 fclose(logfile);
67 logfile = NULL;
69 if( gmLogfile != NULL )
70 fclose(gmLogfile);
71 gmLogfile = NULL;
73 if (charLogfile != NULL)
74 fclose(charLogfile);
75 charLogfile = NULL;
77 if( dberLogfile != NULL )
78 fclose(dberLogfile);
79 dberLogfile = NULL;
81 if (raLogfile != NULL)
82 fclose(raLogfile);
83 raLogfile = NULL;
85 if (worldLogfile != NULL)
86 fclose(worldLogfile);
87 worldLogfile = NULL;
89 public:
90 void Initialize();
91 void InitColors(const std::string& init_str);
92 void outTitle( const char * str);
93 void outCommand( uint32 account, const char * str, ...) ATTR_PRINTF(3,4);
94 void outString(); // any log level
95 // any log level
96 void outString( const char * str, ... ) ATTR_PRINTF(2,3);
97 // any log level
98 void outError( const char * err, ... ) ATTR_PRINTF(2,3);
99 // log level >= 1
100 void outBasic( const char * str, ... ) ATTR_PRINTF(2,3);
101 // log level >= 2
102 void outDetail( const char * str, ... ) ATTR_PRINTF(2,3);
103 // log level >= 3
104 void outDebugInLine( const char * str, ... ) ATTR_PRINTF(2,3);
105 // log level >= 3
106 void outDebug( const char * str, ... ) ATTR_PRINTF(2,3);
107 // any log level
108 void outMenu( const char * str, ... ) ATTR_PRINTF(2,3);
109 // any log level
110 void outErrorDb( const char * str, ... ) ATTR_PRINTF(2,3);
111 // any log level
112 void outChar( const char * str, ... ) ATTR_PRINTF(2,3);
113 // any log level
114 void outWorldPacketDump( uint32 socket, uint32 opcode, char const* opcodeName, ByteBuffer const* packet, bool incoming );
115 // any log level
116 void outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name );
117 void outRALog( const char * str, ... ) ATTR_PRINTF(2,3);
118 void SetLogLevel(char * Level);
119 void SetLogFileLevel(char * Level);
120 void SetColor(bool stdout_stream, Color color);
121 void ResetColor(bool stdout_stream);
122 void outTime();
123 static void outTimestamp(FILE* file);
124 static std::string GetTimestampStr();
125 uint32 getLogFilter() const { return m_logFilter; }
126 bool IsOutDebug() const { return m_logLevel > 2 || (m_logFileLevel > 2 && logfile); }
127 bool IsOutCharDump() const { return m_charLog_Dump; }
128 bool IsIncludeTime() const { return m_includeTime; }
129 private:
130 FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode);
131 FILE* openGmlogPerAccount(uint32 account);
133 FILE* raLogfile;
134 FILE* logfile;
135 FILE* gmLogfile;
136 FILE* charLogfile;
137 FILE* dberLogfile;
138 FILE* worldLogfile;
140 // log/console control
141 uint32 m_logLevel;
142 uint32 m_logFileLevel;
143 bool m_colored;
144 bool m_includeTime;
145 Color m_colors[4];
146 uint32 m_logFilter;
148 // cache values for after initilization use (like gm log per account case)
149 std::string m_logsDir;
150 std::string m_logsTimestamp;
152 // char log control
153 bool m_charLog_Dump;
155 // gm log control
156 bool m_gmlog_per_account;
157 std::string m_gmlog_filename_format;
160 #define sLog MaNGOS::Singleton<Log>::Instance()
162 #ifdef MANGOS_DEBUG
163 #define DEBUG_LOG sLog.outDebug
164 #else
165 #define DEBUG_LOG
166 #endif
168 // primary for script library
169 void MANGOS_DLL_SPEC outstring_log(const char * str, ...) ATTR_PRINTF(1,2);
170 void MANGOS_DLL_SPEC detail_log(const char * str, ...) ATTR_PRINTF(1,2);
171 void MANGOS_DLL_SPEC debug_log(const char * str, ...) ATTR_PRINTF(1,2);
172 void MANGOS_DLL_SPEC error_log(const char * str, ...) ATTR_PRINTF(1,2);
173 void MANGOS_DLL_SPEC error_db_log(const char * str, ...) ATTR_PRINTF(1,2);
174 #endif