Merge branch 'master' into 303
[getmangos.git] / src / shared / Log.h
blob1040e63e5a4ce7ca25a21a36c42e1b0e25f59eba
1 /*
2 * Copyright (C) 2005-2008 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() : raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL), dberLogfile(NULL), m_colored(false) { Initialize(); }
60 ~Log()
62 if( logfile != NULL )
63 fclose(logfile);
64 logfile = NULL;
66 if( gmLogfile != NULL )
67 fclose(gmLogfile);
68 gmLogfile = NULL;
70 if (charLogfile != NULL)
71 fclose(charLogfile);
72 charLogfile = NULL;
74 if( dberLogfile != NULL )
75 fclose(dberLogfile);
76 dberLogfile = NULL;
78 if (raLogfile != NULL)
79 fclose(raLogfile);
80 raLogfile = NULL;
82 public:
83 void Initialize();
84 void InitColors(std::string init_str);
85 void outTitle( const char * str);
86 void outCommand( const char * str, ...) ATTR_PRINTF(2,3);
87 void outString(); // any log level
88 // any log level
89 void outString( const char * str, ... ) ATTR_PRINTF(2,3);
90 // any log level
91 void outError( const char * err, ... ) ATTR_PRINTF(2,3);
92 // log level >= 1
93 void outBasic( const char * str, ... ) ATTR_PRINTF(2,3);
94 // log level >= 2
95 void outDetail( const char * str, ... ) ATTR_PRINTF(2,3);
96 // log level >= 3
97 void outDebugInLine( const char * str, ... ) ATTR_PRINTF(2,3);
98 // log level >= 3
99 void outDebug( const char * str, ... ) ATTR_PRINTF(2,3);
100 // any log level
101 void outMenu( const char * str, ... ) ATTR_PRINTF(2,3);
102 // any log level
103 void outErrorDb( const char * str, ... ) ATTR_PRINTF(2,3);
104 // any log level
105 void outChar( const char * str, ... ) ATTR_PRINTF(2,3);
106 // any log level
107 void outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name );
108 void outRALog( const char * str, ... ) ATTR_PRINTF(2,3);
109 void SetLogLevel(char * Level);
110 void SetLogFileLevel(char * Level);
111 void SetColor(bool stdout_stream, Color color);
112 void ResetColor(bool stdout_stream);
113 void outTime();
114 static void outTimestamp(FILE* file);
115 static std::string GetTimestampStr();
116 uint32 getLogFilter() const { return m_logFilter; }
117 bool IsOutDebug() const { return m_logLevel > 2 || (m_logFileLevel > 2 && logfile); }
118 bool IsOutCharDump() const { return m_charLog_Dump; }
119 bool IsIncludeTime() const { return m_includeTime; }
120 private:
121 FILE* raLogfile;
122 FILE* logfile;
123 FILE* gmLogfile;
124 FILE* charLogfile;
125 FILE* dberLogfile;
127 // log/console control
128 uint32 m_logLevel;
129 uint32 m_logFileLevel;
130 bool m_colored;
131 bool m_includeTime;
132 Color m_colors[4];
133 uint32 m_logFilter;
135 // char log control
136 bool m_charLog_Dump;
140 #define sLog MaNGOS::Singleton<Log>::Instance()
142 #ifdef MANGOS_DEBUG
143 #define DEBUG_LOG MaNGOS::Singleton<Log>::Instance().outDebug
144 #else
145 #define DEBUG_LOG
146 #endif
148 // primary for script library
149 void MANGOS_DLL_SPEC outstring_log(const char * str, ...) ATTR_PRINTF(1,2);
150 void MANGOS_DLL_SPEC detail_log(const char * str, ...) ATTR_PRINTF(1,2);
151 void MANGOS_DLL_SPEC debug_log(const char * str, ...) ATTR_PRINTF(1,2);
152 void MANGOS_DLL_SPEC error_log(const char * str, ...) ATTR_PRINTF(1,2);
153 void MANGOS_DLL_SPEC error_db_log(const char * str, ...) ATTR_PRINTF(1,2);
154 #endif