OregonCore  revision 3611e8a-git
Your Favourite TBC server
Log.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGONCORE_LOG_H
19 #define OREGONCORE_LOG_H
20 
21 #include "Common.h"
22 #include "Policies/Singleton.h"
23 #include "Database/DatabaseEnv.h"
24 
25 class Config;
26 
29 {
34 
38 
43 
46 
50 
52 
54 };
55 
58 {
63 };
64 
68 {
69  BLACK = 0,
70  RED,
85 
87 };
88 
90 class Log : public Oregon::Singleton<Log, Oregon::ClassLevelLockable<Log, ACE_Thread_Mutex> >
91 {
92  friend class Oregon::OperatorNew<Log>;
93  Log();
94  ~Log();
95 
96  public:
97  void Initialize();
98 
99  void InitColors(const std::string& init_str);
100  void SetColor(ColorTypes color);
101  void ResetColor();
102 
103  void outString(const char* fmt, ...) ATTR_PRINTF(2, 3);
104  void outBasic(const char* fmt, ...) ATTR_PRINTF(2, 3);
105  void outDetail(const char* fmt, ...) ATTR_PRINTF(2, 3);
106  void outDebug(const char* fmt, ...) ATTR_PRINTF(2, 3);
107 
108  void outError(const char* fmt, ...) ATTR_PRINTF(2, 3);
109  void outErrorDb(const char* fmt, ...) ATTR_PRINTF(2, 3);
110  void outSQL(const char* fmt, ...) ATTR_PRINTF(2, 3);
111 
112  void outArena(const char* fmt, ...) ATTR_PRINTF(2, 3);
113  void outWarden(const char* fmt, ...) ATTR_PRINTF(2, 3);
114  void outChat(const char* fmt, ...) ATTR_PRINTF(2, 3);
115  void outCommand(const char* fmt, ...) ATTR_PRINTF(2, 3);
116 
117  void outChar(const char* fmt, ...) ATTR_PRINTF(2, 3);
118  void outRemote(const char* fmt, ...) ATTR_PRINTF(2, 3);
119 
120  void outMap(const char* fmt, ...) ATTR_PRINTF(2, 3);
121  void outVMap(const char* fmt, ...) ATTR_PRINTF(2, 3);
122  void outMMap(const char* fmt, ...) ATTR_PRINTF(2, 3);
123 
124  void outNetwork(const char* fmt, ...) ATTR_PRINTF(2, 3);
125 
126  void outDB( LogTypes type, const char* str );
127  void outString()
128  {
129  outString("");
130  }
131  void outDebugInLine(const char* fmt, ...) ATTR_PRINTF(2, 3);
132  void outFatal( const char* err, ... ) ATTR_PRINTF(2, 3) ATTR_NORETURN;
133  void outCharDump( const char* str, uint32 account_id, uint32 guid, const char* name );
134  void outCommand(uint64 account, const char* fmt, ...) ATTR_PRINTF(3, 4);
135 
136  static void outTimestamp(FILE* file);
137  static std::string GetTimestampStr();
138 
139  void SetLogMask(unsigned long mask);
140  void SetDBLogMask(unsigned long mask);
141 
142  unsigned long GetLogMask() const
143  {
144  return m_logMask;
145  }
146 
147  unsigned long GetDBLogMask() const
148  {
149  return m_logMaskDatabase;
150  }
151 
153  bool IsOutDebug() const
154  {
156  }
157 
158  bool IsLogTypeEnabled(LogTypes type) const
159  {
160  return (m_logMask | m_logMaskDatabase) & (1 << type);
161  }
162 
163  private:
165  void DoLog(LogTypes type, bool newline, const char* prefix, const char* fmt, va_list ap, FILE* file = NULL);
166 
167  FILE* openLogFile(char const* configFileName, char const* configTimeStampFlag, char const* mode);
168 
170  FILE* openGmlogPerAccount(uint64 account);
171 
173 
174  std::string m_logsDir;
175  std::string m_logsTimestamp;
176 
179 
181 
182  unsigned long m_logMask;
183  unsigned long m_logMaskDatabase;
184 };
185 
187 #define sLog Oregon::Singleton<Log>::Instance()
188 
189 #ifndef DEBUG_LOG
190 #ifdef OREGON_DEBUG
191 #define DEBUG_LOG Oregon::Singleton<Log>::Instance().outDebug
193 #else
194 #define DEBUG_LOG(...)
195 # endif // OREGON_DEBUG
196 #endif // DEBUG_LOG
197 
199 #define outstring_log Oregon::Singleton<Log>::Instance().outString
200 #define detail_log Oregon::Singleton<Log>::Instance().outDetail
201 #define debug_log Oregon::Singleton<Log>::Instance().outDebug
202 #define error_log Oregon::Singleton<Log>::Instance().outError
203 #define error_db_log Oregon::Singleton<Log>::Instance().outErrorDb
204 
205 #endif
206 
void SetColor(ColorTypes color)
Sets color for upcoming output.
Definition: Log.cpp:274
unsigned long GetLogMask() const
Definition: Log.h:142
void void outFatal(const char *err,...) ATTR_PRINTF(2
Definition: Log.cpp:468
void void outBasic(const char *fmt,...) ATTR_PRINTF(2
Definition: Log.h:86
bool m_gmlog_per_account
flag: create separate log for every GM account?
Definition: Log.h:177
std::string m_logsDir
directory to put log files in
Definition: Log.h:174
void outDebugInLine(const char *fmt,...) ATTR_PRINTF(2
void void void void void void void outSQL(const char *fmt,...) ATTR_PRINTF(2
Definition: Log.h:62
void outCharDump(const char *str, uint32 account_id, uint32 guid, const char *name)
Definition: Log.cpp:512
LogTypes
LogTypes, each value is bit position in logmask.
Definition: Log.h:28
void void void void void void void void outArena(const char *fmt,...) ATTR_PRINTF(2
void DoLog(LogTypes type, bool newline, const char *prefix, const char *fmt, va_list ap, FILE *file=NULL)
Performs logging.
Definition: Log.cpp:401
unsigned long m_logMask
mask to filter messages sent to console and files
Definition: Log.h:182
std::string m_gmlog_filename_format
format for GM log filename
Definition: Log.h:178
Definition: Log.h:71
static std::string GetTimestampStr()
Definition: Log.cpp:369
STL namespace.
void void void void void void void void void void void void void outRemote(const char *fmt,...) ATTR_PRINTF(2
Main logging class.
Definition: Log.h:90
void static void outTimestamp(FILE *file)
Definition: Log.cpp:241
void void void outDetail(const char *fmt,...) ATTR_PRINTF(2
Definition: Log.h:81
Definition: Log.h:82
void Initialize()
Definition: Log.cpp:86
Definition: Log.h:79
Definition: Config.h:27
bool IsLogTypeEnabled(LogTypes type) const
Definition: Log.h:158
Definition: Log.h:78
Definition: Log.h:72
Log()
Definition: Log.cpp:53
std::string m_logsTimestamp
Definition: Log.h:175
FILE * m_logFiles[MAX_LOG_TYPES]
files for each message type
Definition: Log.h:172
#define ATTR_PRINTF(F, V)
Definition: Define.h:60
Definition: Log.h:60
Definition: Log.h:69
Definition: Log.h:74
Definition: Log.h:84
ColorTypes
Definition: Log.h:67
Definition: Log.h:80
ColorTypes m_colors[MAX_LOG_TYPES]
colors assigned to individual message types
Definition: Log.h:180
Definition: Log.h:75
void SetLogMask(unsigned long mask)
Definition: Log.cpp:76
void InitColors(const std::string &init_str)
Definition: Log.cpp:254
bool IsOutDebug() const
Checks whether outDebug works.
Definition: Log.h:153
Definition: Log.h:76
Definition: Log.h:73
LogLevel
Presets of bitmasks, exists for backward compatibility.
Definition: Log.h:57
void SetDBLogMask(unsigned long mask)
Definition: Log.cpp:81
void void ATTR_NORETURN
Definition: Log.h:132
void void void void void void outErrorDb(const char *fmt,...) ATTR_PRINTF(2
Definition: Log.h:70
void void void void void void void void void void void void void void void void void outNetwork(const char *fmt,...) ATTR_PRINTF(2
ACE_UINT64 uint64
Definition: Define.h:70
void void void void void void void void void void void void void void void void outMMap(const char *fmt,...) ATTR_PRINTF(2
Definition: Log.h:77
Definition: Log.h:83
void ResetColor()
Resets output color to normal.
Definition: Log.cpp:354
unsigned long GetDBLogMask() const
Definition: Log.h:147
void void void void outDebug(const char *fmt,...) ATTR_PRINTF(2
FILE * openGmlogPerAccount(uint64 account)
opens specific file for account
Definition: Log.cpp:231
void void void void void void void void void void void void outChar(const char *fmt,...) ATTR_PRINTF(2
void void void void void void void void void void void outCommand(const char *fmt,...) ATTR_PRINTF(2
void void void void void void void void void void void void void void void void void void outDB(LogTypes type, const char *str)
Definition: Log.cpp:381
ACE_UINT32 uint32
Definition: Define.h:71
void void void void void outError(const char *fmt,...) ATTR_PRINTF(2
void void void void void void void void void outWarden(const char *fmt,...) ATTR_PRINTF(2
unsigned long m_logMaskDatabase
mask to filter messages sent to db
Definition: Log.h:183
void outString()
Definition: Log.h:127
void void void void void void void void void void outChat(const char *fmt,...) ATTR_PRINTF(2
void void void void void void void void void void void void void void void outVMap(const char *fmt,...) ATTR_PRINTF(2
FILE * openLogFile(char const *configFileName, char const *configTimeStampFlag, char const *mode)
Definition: Log.cpp:208
~Log()
Definition: Log.cpp:61
void void void void void void void void void void void void void void outMap(const char *fmt,...) ATTR_PRINTF(2