Planeshift
log.h
Go to the documentation of this file.
1 /*
2 * pslog.h -- Christophe Painchaud aka Atanor, DaSH <dash@ionblast.net>
3 *
4 * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * 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.
17 *
18 */
19 
20 #ifndef __PSUTIL_LOG_H__
21 #define __PSUTIL_LOG_H__
22 
23 #include "util/singleton.h"
24 #include "ivaria/reporter.h"
25 #include <iutil/vfs.h>
26 
27 struct iConfigManager;
28 struct iObjectRegistry;
29 
35 {
37 
38  // Lights update, time of the day, snow, fog, rain, lightning messages
40 
41  // Item spawned, hunt location added, NPCs spawned or killed
43 
44  // Entities and gemobjects added/removed (NPCs, items, action locations)
46 
47  // UI widget loading, and interaction
49 
50  // player added to a group
52 
53  // PaladinJr, speed cheat detection, item cheat detection
55 
56  // Player movement and falling down
58 
59  // casting spell and success rate
61 
62  // Character creation messages
64 
65  // Bunch of actions sent to superclient: new entities, sit, die, spell casting, switch player mode, crafting
67 
68  // Bank, storage, exchange of items between players
70 
71  // GM Commands
73 
74  // Messages on how many objects have been loaded at server startup
76 
77  // Traits, sockets, material change on meshes
79 
80  // server connections, login, authentication request, disconnects
82 
83  // players chat
85 
86  // Mix of everything, needs a rework. npcclient messages, authentication, malformed messages
88 
89  // Loading screen between zones, sector crossing
91 
92  // NPCClient perceptions handling. NPC Dialogues resolution
94 
95  // Crafting
97 
98  // server side and clien side handling of sounds
100 
101  // combat resolution, damage, loot, stances, animations
103 
104  // gaining XP, spending XP and training
106 
107  // Startup quest parsing. In game assign, discard, complete quests. Dialogues on quests
109 
110  // mathscript (rarely used)
112 
113  // Buddy list, marriage, alliances
115 
116  // server <-> client low level communication (very verbose!)
118 
119  // addeding/deleting objects from CacheManager
121 
122  // Pets management. Rarely used.
124 
125  // Mix of user/item actions. may need rework.
127 
128  // Random treasure generation
130 
131  // Minigames, boards
133 
134  // Dead reckoning positional/navigation data (very verbose)
136 
137  // Action Locations, puzzles and mechanisms
139 
140  // Log item related transactions
142 
143  // Log Hire related transaction
145 
146 // NOTE: Remember to update the flagnames and flagsettings tables in log.cpp when adding new entries
148 };
149 
150 enum
151 {
161 };
162 
163 namespace pslog
164 {
165 
166 extern iObjectRegistry* logger;
167 extern bool disp_flag[MAX_FLAGS];
168 
169 bool DoLog(int severity, LOG_TYPES type, uint32 filter_id);
170 void LogMessage (const char* file, int line, const char* function,
171  int severity, LOG_TYPES type, uint32 filter_id, const char* msg, ...) CS_GNUC_PRINTF (7, 8);
172 void Initialize(iObjectRegistry* object_reg);
173 void SetFlag(const char *name,bool flag, uint32 filter);
174 void DisplayFlags(const char *name=NULL);
175 bool GetValue(const char* name);
176 const char* GetName(int id);
177 const char* GetSettingName(int id);
178 
179 
180 // Check log macros
181 //
182 // Use this to prevent processing of preparation of args to the other macros:
183 //
184 // if (DoLogDebug(LOG_NET))
185 // {
186 // int arg = <Work that use much CPU>
187 // Debug1(LOG_NET,...,arg,...)
188 // }
189 //
190 #define DoLogDebug(type) pslog::DoLog( CS_REPORTER_SEVERITY_DEBUG, type, 0)
191 #define DoLogDebug2(type,filter_id) pslog::DoLog( CS_REPORTER_SEVERITY_DEBUG, type, filter_id)
192 #define DoLogNotify(type) pslog::DoLog( CS_REPORTER_SEVERITY_NOTIFY, type, 0)
193 #define DoLogError(type) pslog::DoLog( CS_REPORTER_SEVERITY_ERROR, type, 0)
194 #define DoLogWarning(type) pslog::DoLog( CS_REPORTER_SEVERITY_WARNING, type, 0)
195 #define DoLogBug(type) pslog::DoLog( CS_REPORTER_SEVERITY_BUG, type, 0)
196 
197 // Debug macros
198 
199 #define Debug(type, filter_id, ...) \
200  { if (DoLogDebug2(type,filter_id)){ \
201  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, __VA_ARGS__ ); }}
202 #define Debug1(type, filter_id, a) \
203  { if (DoLogDebug2(type,filter_id)){ \
204  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a); }}
205 #define Debug2(type, filter_id, a,b) \
206  { if (DoLogDebug2(type,filter_id)){ \
207  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b); }}
208 #define Debug3(type, filter_id, a,b,c) \
209  { if (DoLogDebug2(type,filter_id)){ \
210  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c); }}
211 #define Debug4(type, filter_id, a,b,c,d) \
212  { if (DoLogDebug2(type,filter_id)){ \
213  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d); }}
214 #define Debug5(type, filter_id, a,b,c,d,e) \
215  { if (DoLogDebug2(type,filter_id)){ \
216  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e); }}
217 #define Debug6(type, filter_id, a,b,c,d,e,f) \
218  { if (DoLogDebug2(type,filter_id)){ \
219  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e, f); }}
220 #define Debug7(type, filter_id, a,b,c,d,e,f,g) \
221  { if (DoLogDebug2(type,filter_id)){ \
222  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e, f, g); }}
223 #define Debug8(type, filter_id, a,b,c,d,e,f,g,h) \
224  { if (DoLogDebug2(type,filter_id)){ \
225  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e, f, g, h); }}
226 
227 #define Notify1(type, a) \
228  { if (DoLogNotify(type)){ \
229  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a); }}
230 #define Notify2(type, a,b) \
231  { if (DoLogNotify(type)){ \
232  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b); }}
233 #define Notify3(type, a,b,c) \
234  { if (DoLogNotify(type)){ \
235  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c); }}
236 #define Notify4(type, a,b,c,d) \
237  { if (DoLogNotify(type)){ \
238  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d); }}
239 #define Notify5(type, a,b,c,d,e) \
240  { if (DoLogNotify(type)){ \
241  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e); }}
242 #define Notify6(type, a,b,c,d,e,f) \
243  { if (DoLogNotify(type)){ \
244  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f); }}
245 #define Notify7(type, a,b,c,d,e,f,g) \
246  { if (DoLogNotify(type)){ \
247  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f, g); }}
248 #define Notify8(type, a,b,c,d,e,f,g,h) \
249  { if (DoLogNotify(type)){ \
250  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f, g, h, i); }}
251 #define Notify9(type, a,b,c,d,e,f,g,h,i) \
252  { if (DoLogNotify(type)){ \
253  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f, g, h, i); }}
254 
255 #define Warning1(type, a) \
256  { if (DoLogWarning(type)){ \
257  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a); }}
258 #define Warning2(type, a,b) \
259  { if (DoLogWarning(type)){ \
260  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b); }}
261 #define Warning3(type, a,b,c) \
262  { if (DoLogWarning(type)){ \
263  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c); }}
264 #define Warning4(type, a,b,c,d) \
265  { if (DoLogWarning(type)){ \
266  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c, d); }}
267 #define Warning5(type, a,b,c,d,e) \
268  { if (DoLogWarning(type)){ \
269  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c, d, e); }}
270 #define Warning6(type, a,b,c,d,e,f) \
271  { if (DoLogWarning(type)){ \
272  pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c, d, e, f); }}
273 
274 #define Error1(a) \
275  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a); }
276 #define Error2(a,b) \
277  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b); }
278 #define Error3(a,b,c) \
279  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c); }
280 #define Error4(a,b,c,d) \
281  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c, d); }
282 #define Error5(a,b,c,d,e) \
283  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c, d, e); }
284 #define Error6(a,b,c,d,e,f) \
285  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c, d, e, f); }
286 
287 #define Bug1(a) \
288  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a); }
289 #define Bug2(a,b) \
290  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b); }
291 #define Bug3(a,b,c) \
292  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c); }
293 #define Bug4(a,b,c,d) \
294  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c, d); }
295 #define Bug5(a,b,c,d,e) \
296  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c, d, e); }
297 #define Bug6(a,b,c,d,e,f) \
298  { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c, d, e, f); }
299 
300 } // end of namespace pslog
301 
302 // Used to create Comma Seperated Value files for general logging
303 // and takes advantage of ConfigManager and VFS which pslog cannot.
304 // This should be used only for day-to-day information needed in a
305 // consistent, readable format. Warnings and errors should go through pslog.
306 class LogCSV : public Singleton<LogCSV>
307 {
308  csRef<iFile> csvFile[MAX_CSV];
309  void StartLog(const char* logfile, iVFS* vfs, const char* header, size_t maxSize, csRef<iFile>& csvFile);
310 
311 public:
312  LogCSV(iConfigManager* configmanager, iVFS* vfs);
313  void Write(int type, csString& text);
314 };
315 
318 #endif
bool DoLog(int severity, LOG_TYPES type, uint32 filter_id)
Definition: log.h:42
Definition: log.h:158
bool disp_flag[MAX_FLAGS]
const char * GetSettingName(int id)
const char * GetName(int id)
Definition: log.h:120
Definition: log.h:99
Definition: log.h:126
void SetFlag(const char *name, bool flag, uint32 filter)
LOG_TYPES
Definition: log.h:34
Definition: log.h:159
Definition: log.h:93
Definition: log.h:129
Definition: log.h:96
Definition: log.h:306
Definition: log.h:72
Definition: log.h:141
Definition: log.h:144
Definition: log.h:54
Definition: log.h:87
Definition: log.h:36
void void Initialize(iObjectRegistry *object_reg)
void DisplayFlags(const char *name=NULL)
Definition: log.h:160
Definition: log.h:123
bool GetValue(const char *name)
void LogMessage(const char *file, int line, const char *function, int severity, LOG_TYPES type, uint32 filter_id, const char *msg,...) CS_GNUC_PRINTF(7
iObjectRegistry * logger
Definition: log.h:147
Definition: log.h:51
Definition: log.h:163
Definition: log.h:90
Definition: log.h:48
Definition: log.h:84
Definition: log.h:60