[7356] Use tabs for indent in Makefiles
[getmangos.git] / src / shared / Log.h
blob85fac5ed32d72e37fabd83a57c7c7431bbecb68d
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
35 enum Color
37 BLACK,
38 RED,
39 GREEN,
40 BROWN,
41 BLUE,
42 MAGENTA,
43 CYAN,
44 GREY,
45 YELLOW,
46 LRED,
47 LGREEN,
48 LBLUE,
49 LMAGENTA,
50 LCYAN,
51 WHITE
54 const int Color_count = int(WHITE)+1;
56 class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ZThread::FastMutex> >
58 friend class MaNGOS::OperatorNew<Log>;
59 Log();
61 ~Log()
63 if( logfile != NULL )
64 fclose(logfile);
65 logfile = NULL;
67 if( gmLogfile != NULL )
68 fclose(gmLogfile);
69 gmLogfile = NULL;
71 if (charLogfile != NULL)
72 fclose(charLogfile);
73 charLogfile = NULL;
75 if( dberLogfile != NULL )
76 fclose(dberLogfile);
77 dberLogfile = NULL;
79 if (raLogfile != NULL)
80 fclose(raLogfile);
81 raLogfile = NULL;
83 public:
84 void Initialize();
85 void InitColors(const std::string& init_str);
86 void outTitle( const char * str);
87 void outCommand( uint32 account, const char * str, ...) ATTR_PRINTF(3,4);
88 void outString(); // any log level
89 // any log level
90 void outString( const char * str, ... ) ATTR_PRINTF(2,3);
91 // any log level
92 void outError( const char * err, ... ) ATTR_PRINTF(2,3);
93 // log level >= 1
94 void outBasic( const char * str, ... ) ATTR_PRINTF(2,3);
95 // log level >= 2
96 void outDetail( const char * str, ... ) ATTR_PRINTF(2,3);
97 // log level >= 3
98 void outDebugInLine( const char * str, ... ) ATTR_PRINTF(2,3);
99 // log level >= 3
100 void outDebug( const char * str, ... ) ATTR_PRINTF(2,3);
101 // any log level
102 void outMenu( const char * str, ... ) ATTR_PRINTF(2,3);
103 // any log level
104 void outErrorDb( const char * str, ... ) ATTR_PRINTF(2,3);
105 // any log level
106 void outChar( const char * str, ... ) ATTR_PRINTF(2,3);
107 // any log level
108 void outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name );
109 void outRALog( const char * str, ... ) ATTR_PRINTF(2,3);
110 void SetLogLevel(char * Level);
111 void SetLogFileLevel(char * Level);
112 void SetColor(bool stdout_stream, Color color);
113 void ResetColor(bool stdout_stream);
114 void outTime();
115 static void outTimestamp(FILE* file);
116 static std::string GetTimestampStr();
117 uint32 getLogFilter() const { return m_logFilter; }
118 bool IsOutDebug() const { return m_logLevel > 2 || (m_logFileLevel > 2 && logfile); }
119 bool IsOutCharDump() const { return m_charLog_Dump; }
120 bool IsIncludeTime() const { return m_includeTime; }
121 private:
122 FILE* openLogFile(char const* configFileName,char const* configTimeStampFlag, char const* mode);
123 FILE* openGmlogPerAccount(uint32 account);
125 FILE* raLogfile;
126 FILE* logfile;
127 FILE* gmLogfile;
128 FILE* charLogfile;
129 FILE* dberLogfile;
131 // log/console control
132 uint32 m_logLevel;
133 uint32 m_logFileLevel;
134 bool m_colored;
135 bool m_includeTime;
136 Color m_colors[4];
137 uint32 m_logFilter;
139 // cache values for after initilization use (like gm log per account case)
140 std::string m_logsDir;
141 std::string m_logsTimestamp;
143 // char log control
144 bool m_charLog_Dump;
146 // gm log control
147 bool m_gmlog_per_account;
148 std::string m_gmlog_filename_format;
151 #define sLog MaNGOS::Singleton<Log>::Instance()
153 #ifdef MANGOS_DEBUG
154 #define DEBUG_LOG MaNGOS::Singleton<Log>::Instance().outDebug
155 #else
156 #define DEBUG_LOG
157 #endif
159 // primary for script library
160 void MANGOS_DLL_SPEC outstring_log(const char * str, ...) ATTR_PRINTF(1,2);
161 void MANGOS_DLL_SPEC detail_log(const char * str, ...) ATTR_PRINTF(1,2);
162 void MANGOS_DLL_SPEC debug_log(const char * str, ...) ATTR_PRINTF(1,2);
163 void MANGOS_DLL_SPEC error_log(const char * str, ...) ATTR_PRINTF(1,2);
164 void MANGOS_DLL_SPEC error_db_log(const char * str, ...) ATTR_PRINTF(1,2);
165 #endif