[7964] Use NULL instead of 0 for "empty" pointers.
[getmangos.git] / src / shared / Log.h
blobc9c004512fa0cf399ae18d1cc082c7ce69ff6c97
1 /*
2 * Copyright (C) 2005-2009 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;
27 // bitmask
28 enum LogFilters
30 LOG_FILTER_TRANSPORT_MOVES = 1,
31 LOG_FILTER_CREATURE_MOVES = 2,
32 LOG_FILTER_VISIBILITY_CHANGES = 4,
33 LOG_FILTER_ACHIEVEMENT_UPDATES= 8
36 enum Color
38 BLACK,
39 RED,
40 GREEN,
41 BROWN,
42 BLUE,
43 MAGENTA,
44 CYAN,
45 GREY,
46 YELLOW,
47 LRED,
48 LGREEN,
49 LBLUE,
50 LMAGENTA,
51 LCYAN,
52 WHITE
55 const int Color_count = int(WHITE)+1;
57 class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Thread_Mutex> >
59 friend class MaNGOS::OperatorNew<Log>;
60 Log();
62 ~Log()
64 if( logfile != NULL )
65 fclose(logfile);
66 logfile = NULL;
68 if( gmLogfile != NULL )
69 fclose(gmLogfile);
70 gmLogfile = NULL;
72 if (charLogfile != NULL)
73 fclose(charLogfile);
74 charLogfile = NULL;
76 if( dberLogfile != NULL )
77 fclose(dberLogfile);
78 dberLogfile = NULL;
80 if (raLogfile != NULL)
81 fclose(raLogfile);
82 raLogfile = NULL;
84 public:
85 void Initialize();
86 void InitColors(const std::string& init_str);
87 void outTitle( const char * str);
88 void outCommand( uint32 account, const char * str, ...) ATTR_PRINTF(3,4);
89 void outString(); // any log level
90 // any log level
91 void outString( const char * str, ... ) ATTR_PRINTF(2,3);
92 // any log level
93 void outError( const char * err, ... ) ATTR_PRINTF(2,3);
94 // log level >= 1
95 void outBasic( const char * str, ... ) ATTR_PRINTF(2,3);
96 // log level >= 2
97 void outDetail( const char * str, ... ) ATTR_PRINTF(2,3);
98 // log level >= 3
99 void outDebugInLine( const char * str, ... ) ATTR_PRINTF(2,3);
100 // log level >= 3
101 void outDebug( const char * str, ... ) ATTR_PRINTF(2,3);
102 // any log level
103 void outMenu( const char * str, ... ) ATTR_PRINTF(2,3);
104 // any log level
105 void outErrorDb( const char * str, ... ) ATTR_PRINTF(2,3);
106 // any log level
107 void outChar( const char * str, ... ) ATTR_PRINTF(2,3);
108 // any log level
109 void outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name );
110 void outRALog( const char * str, ... ) ATTR_PRINTF(2,3);
111 void SetLogLevel(char * Level);
112 void SetLogFileLevel(char * Level);
113 void SetColor(bool stdout_stream, Color color);
114 void ResetColor(bool stdout_stream);
115 void outTime();
116 static void outTimestamp(FILE* file);
117 static std::string GetTimestampStr();
118 uint32 getLogFilter() const { return m_logFilter; }
119 bool IsOutDebug() const { return m_logLevel > 2 || (m_logFileLevel > 2 && logfile); }
120 bool IsOutCharDump() const { return m_charLog_Dump; }
121 bool IsIncludeTime() const { return m_includeTime; }
122 private:
123 FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode);
124 FILE* openGmlogPerAccount(uint32 account);
126 FILE* raLogfile;
127 FILE* logfile;
128 FILE* gmLogfile;
129 FILE* charLogfile;
130 FILE* dberLogfile;
132 // log/console control
133 uint32 m_logLevel;
134 uint32 m_logFileLevel;
135 bool m_colored;
136 bool m_includeTime;
137 Color m_colors[4];
138 uint32 m_logFilter;
140 // cache values for after initilization use (like gm log per account case)
141 std::string m_logsDir;
142 std::string m_logsTimestamp;
144 // char log control
145 bool m_charLog_Dump;
147 // gm log control
148 bool m_gmlog_per_account;
149 std::string m_gmlog_filename_format;
152 #define sLog MaNGOS::Singleton<Log>::Instance()
154 #ifdef MANGOS_DEBUG
155 #define DEBUG_LOG MaNGOS::Singleton<Log>::Instance().outDebug
156 #else
157 #define DEBUG_LOG
158 #endif
160 // primary for script library
161 void MANGOS_DLL_SPEC outstring_log(const char * str, ...) ATTR_PRINTF(1,2);
162 void MANGOS_DLL_SPEC detail_log(const char * str, ...) ATTR_PRINTF(1,2);
163 void MANGOS_DLL_SPEC debug_log(const char * str, ...) ATTR_PRINTF(1,2);
164 void MANGOS_DLL_SPEC error_log(const char * str, ...) ATTR_PRINTF(1,2);
165 void MANGOS_DLL_SPEC error_db_log(const char * str, ...) ATTR_PRINTF(1,2);
166 #endif