1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef TRINITYCORE_LOG_H |
---|
22 | #define TRINITYCORE_LOG_H |
---|
23 | |
---|
24 | #include "Common.h" |
---|
25 | #include "Policies/Singleton.h" |
---|
26 | |
---|
27 | class Config; |
---|
28 | |
---|
29 | // bitmask |
---|
30 | enum LogFilters |
---|
31 | { |
---|
32 | LOG_FILTER_TRANSPORT_MOVES = 1, |
---|
33 | LOG_FILTER_CREATURE_MOVES = 2, |
---|
34 | LOG_FILTER_VISIBILITY_CHANGES = 4 |
---|
35 | }; |
---|
36 | |
---|
37 | enum Color |
---|
38 | { |
---|
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 |
---|
54 | }; |
---|
55 | |
---|
56 | const int Color_count = int(WHITE)+1; |
---|
57 | |
---|
58 | class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ZThread::FastMutex> > |
---|
59 | { |
---|
60 | friend class Trinity::OperatorNew<Log>; |
---|
61 | Log() : raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL), dberLogfile(NULL), m_colored(false) { Initialize(); } |
---|
62 | ~Log() |
---|
63 | { |
---|
64 | if( logfile != NULL ) |
---|
65 | fclose(logfile); |
---|
66 | logfile = NULL; |
---|
67 | |
---|
68 | if( gmLogfile != NULL ) |
---|
69 | fclose(gmLogfile); |
---|
70 | gmLogfile = NULL; |
---|
71 | |
---|
72 | if (charLogfile != NULL) |
---|
73 | fclose(charLogfile); |
---|
74 | charLogfile = NULL; |
---|
75 | |
---|
76 | if( dberLogfile != NULL ) |
---|
77 | fclose(dberLogfile); |
---|
78 | dberLogfile = NULL; |
---|
79 | |
---|
80 | if (raLogfile != NULL) |
---|
81 | fclose(raLogfile); |
---|
82 | raLogfile = NULL; |
---|
83 | } |
---|
84 | public: |
---|
85 | void Initialize(); |
---|
86 | void InitColors(std::string init_str); |
---|
87 | void outTitle( const char * str); |
---|
88 | void outCommand( const char * str, ...) ATTR_PRINTF(2,3); |
---|
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* raLogfile; |
---|
124 | FILE* logfile; |
---|
125 | FILE* gmLogfile; |
---|
126 | FILE* charLogfile; |
---|
127 | FILE* dberLogfile; |
---|
128 | |
---|
129 | // log/console control |
---|
130 | uint32 m_logLevel; |
---|
131 | uint32 m_logFileLevel; |
---|
132 | bool m_colored; |
---|
133 | bool m_includeTime; |
---|
134 | Color m_colors[4]; |
---|
135 | uint32 m_logFilter; |
---|
136 | |
---|
137 | // char log control |
---|
138 | bool m_charLog_Dump; |
---|
139 | |
---|
140 | }; |
---|
141 | |
---|
142 | #define sLog Trinity::Singleton<Log>::Instance() |
---|
143 | |
---|
144 | #ifdef TRINITY_DEBUG |
---|
145 | #define DEBUG_LOG Trinity::Singleton<Log>::Instance().outDebug |
---|
146 | #else |
---|
147 | #define DEBUG_LOG |
---|
148 | #endif |
---|
149 | |
---|
150 | // primary for script library |
---|
151 | void TRINITY_DLL_SPEC outstring_log(const char * str, ...) ATTR_PRINTF(1,2); |
---|
152 | void TRINITY_DLL_SPEC detail_log(const char * str, ...) ATTR_PRINTF(1,2); |
---|
153 | void TRINITY_DLL_SPEC debug_log(const char * str, ...) ATTR_PRINTF(1,2); |
---|
154 | void TRINITY_DLL_SPEC error_log(const char * str, ...) ATTR_PRINTF(1,2); |
---|
155 | void TRINITY_DLL_SPEC error_db_log(const char * str, ...) ATTR_PRINTF(1,2); |
---|
156 | #endif |
---|