Planeshift

log.h

Go to the documentation of this file.
00001 /*
00002 * pslog.h -- Christophe Painchaud aka Atanor, DaSH <[email protected]>
00003 *
00004 * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org)
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef __PSUTIL_LOG_H__
00021 #define __PSUTIL_LOG_H__
00022 
00023 #include "util/singleton.h"
00024 #include "ivaria/reporter.h"
00025 #include <iutil/vfs.h>
00026 
00027 struct iConfigManager;
00028 struct iObjectRegistry;
00029 
00034 enum LOG_TYPES
00035 {
00036     LOG_ANY,
00037 
00038     // Lights update, time of the day, snow, fog, rain, lightning messages
00039     LOG_WEATHER,
00040 
00041     // Item spawned, hunt location added, NPCs spawned or killed
00042     LOG_SPAWN,
00043 
00044     // Entities and gemobjects added/removed (NPCs, items, action locations)
00045     LOG_CELPERSIST,
00046 
00047     // UI widget loading, and interaction
00048     LOG_PAWS,
00049 
00050     // player added to a group
00051     LOG_GROUP,
00052 
00053     // PaladinJr, speed cheat detection, item cheat detection
00054     LOG_CHEAT,
00055 
00056     // Player movement and falling down
00057     LOG_LINMOVE,
00058 
00059     // casting spell and success rate
00060     LOG_SPELLS,
00061 
00062     // Character creation messages
00063     LOG_NEWCHAR,
00064 
00065     // Bunch of actions sent to superclient: new entities, sit, die, spell casting, switch player mode, crafting
00066     LOG_SUPERCLIENT,
00067 
00068     // Bank, storage, exchange of items between players
00069     LOG_EXCHANGES,
00070 
00071     // GM Commands
00072     LOG_ADMIN,
00073 
00074     // Messages on how many objects have been loaded at server startup
00075     LOG_STARTUP,
00076 
00077     // Traits, sockets, material change on meshes
00078     LOG_CHARACTER,
00079 
00080     // server connections, login, authentication request, disconnects
00081     LOG_CONNECTIONS,
00082 
00083     // players chat
00084     LOG_CHAT,
00085 
00086     // Mix of everything, needs a rework. npcclient messages, authentication, malformed messages
00087     LOG_NET,
00088 
00089     // Loading screen between zones, sector crossing
00090     LOG_LOAD,
00091 
00092     // NPCClient perceptions handling. NPC Dialogues resolution
00093     LOG_NPC,
00094 
00095     // Crafting
00096     LOG_TRADE,
00097 
00098     // server side and clien side handling of sounds
00099     LOG_SOUND,
00100 
00101     // combat resolution, damage, loot, stances, animations
00102     LOG_COMBAT,
00103 
00104     // gaining XP, spending XP and training
00105     LOG_SKILLXP,
00106 
00107     // Startup quest parsing. In game assign, discard, complete quests. Dialogues on quests
00108     LOG_QUESTS,
00109 
00110     // mathscript (rarely used)
00111     LOG_SCRIPT,
00112 
00113     // Buddy list, marriage, alliances
00114     LOG_RELATIONSHIPS,
00115 
00116     // server <-> client low level communication (very verbose!)
00117     LOG_MESSAGES,
00118 
00119     // addeding/deleting objects from CacheManager
00120     LOG_CACHE,
00121 
00122     // Pets management. Rarely used.
00123     LOG_PETS,
00124 
00125     // Mix of user/item actions. may need rework.
00126     LOG_USER,
00127 
00128     // Random treasure generation
00129     LOG_LOOT,
00130 
00131     // Minigames, boards
00132     LOG_MINIGAMES,
00133 
00134     // Dead reckoning positional/navigation data (very verbose)
00135     LOG_DRDATA,
00136 
00137     // Action Locations, puzzles and mechanisms
00138     LOG_ACTIONLOCATION,
00139 
00140     // Log item related transactions
00141     LOG_ITEM,
00142 
00143     // Log Hire related transaction
00144     LOG_HIRE,
00145 
00146 // NOTE: Remember to update the flagnames and flagsettings tables in log.cpp when adding new entries
00147     MAX_FLAGS
00148 };
00149 
00150 enum
00151 {
00152     CSV_AUTHENT,
00153     CSV_EXCHANGES,
00154     CSV_PALADIN,
00155     CSV_STATUS,
00156     CSV_ADVICE,
00157     CSV_ECONOMY,
00158     CSV_STUCK,
00159     CSV_SQL,
00160     MAX_CSV
00161 };
00162 
00163 namespace pslog
00164 {
00165 
00166 extern iObjectRegistry* logger;
00167 extern bool disp_flag[MAX_FLAGS];
00168  
00169 bool DoLog(int severity, LOG_TYPES type, uint32 filter_id);
00170 void LogMessage (const char* file, int line, const char* function,
00171              int severity, LOG_TYPES type, uint32 filter_id, const char* msg, ...) CS_GNUC_PRINTF (7, 8);
00172 void Initialize(iObjectRegistry* object_reg);
00173 void SetFlag(const char *name,bool flag, uint32 filter);
00174 void DisplayFlags(const char *name=NULL);
00175 bool GetValue(const char* name);
00176 const char* GetName(int id);
00177 const char* GetSettingName(int id);
00178 
00179 
00180 // Check log macros
00181 //
00182 // Use this to prevent processing of preparation of args to the other macros:
00183 // 
00184 // if (DoLogDebug(LOG_NET))
00185 // {
00186 //    int arg = <Work that use much CPU> 
00187 //    Debug1(LOG_NET,...,arg,...)
00188 // } 
00189 // 
00190 #define DoLogDebug(type)              pslog::DoLog( CS_REPORTER_SEVERITY_DEBUG, type, 0)
00191 #define DoLogDebug2(type,filter_id)   pslog::DoLog( CS_REPORTER_SEVERITY_DEBUG, type, filter_id) 
00192 #define DoLogNotify(type)             pslog::DoLog( CS_REPORTER_SEVERITY_NOTIFY, type, 0)
00193 #define DoLogError(type)              pslog::DoLog( CS_REPORTER_SEVERITY_ERROR, type, 0)
00194 #define DoLogWarning(type)            pslog::DoLog( CS_REPORTER_SEVERITY_WARNING, type, 0) 
00195 #define DoLogBug(type)                pslog::DoLog( CS_REPORTER_SEVERITY_BUG, type, 0) 
00196  
00197 // Debug macros
00198 
00199 #define Debug(type, filter_id, ...) \
00200     { if (DoLogDebug2(type,filter_id)){ \
00201         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, __VA_ARGS__ ); }}
00202 #define Debug1(type, filter_id, a) \
00203     { if (DoLogDebug2(type,filter_id)){ \
00204         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a); }}
00205 #define Debug2(type, filter_id, a,b) \
00206     { if (DoLogDebug2(type,filter_id)){ \
00207         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b); }}
00208 #define Debug3(type, filter_id, a,b,c) \
00209     { if (DoLogDebug2(type,filter_id)){ \
00210         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c); }}
00211 #define Debug4(type, filter_id, a,b,c,d) \
00212     { if (DoLogDebug2(type,filter_id)){ \
00213         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d); }}
00214 #define Debug5(type, filter_id, a,b,c,d,e) \
00215     { if (DoLogDebug2(type,filter_id)){ \
00216         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e); }}
00217 #define Debug6(type, filter_id, a,b,c,d,e,f) \
00218     { if (DoLogDebug2(type,filter_id)){ \
00219         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e, f); }}
00220 #define Debug7(type, filter_id, a,b,c,d,e,f,g) \
00221     { if (DoLogDebug2(type,filter_id)){ \
00222         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e, f, g); }}
00223 #define Debug8(type, filter_id, a,b,c,d,e,f,g,h) \
00224     { if (DoLogDebug2(type,filter_id)){ \
00225         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_DEBUG, type, filter_id, a, b, c, d, e, f, g, h); }}
00226 
00227 #define Notify1(type, a) \
00228     { if (DoLogNotify(type)){ \
00229         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a); }}
00230 #define Notify2(type, a,b) \
00231     { if (DoLogNotify(type)){ \
00232         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b); }}
00233 #define Notify3(type, a,b,c) \
00234     { if (DoLogNotify(type)){ \
00235         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c); }}
00236 #define Notify4(type, a,b,c,d) \
00237     { if (DoLogNotify(type)){ \
00238         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d); }}
00239 #define Notify5(type, a,b,c,d,e) \
00240     { if (DoLogNotify(type)){ \
00241         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e); }}
00242 #define Notify6(type, a,b,c,d,e,f) \
00243     { if (DoLogNotify(type)){ \
00244         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f); }}
00245 #define Notify7(type, a,b,c,d,e,f,g) \
00246     { if (DoLogNotify(type)){ \
00247         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f, g); }}
00248 #define Notify8(type, a,b,c,d,e,f,g,h) \
00249     { if (DoLogNotify(type)){ \
00250         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f, g, h, i); }}
00251 #define Notify9(type, a,b,c,d,e,f,g,h,i) \
00252     { if (DoLogNotify(type)){ \
00253         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_NOTIFY, type, 0, a, b, c, d, e, f, g, h, i); }}
00254 
00255 #define Warning1(type, a) \
00256     { if (DoLogWarning(type)){ \
00257         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a); }}
00258 #define Warning2(type, a,b) \
00259     { if (DoLogWarning(type)){ \
00260         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b); }}
00261 #define Warning3(type, a,b,c) \
00262     { if (DoLogWarning(type)){ \
00263         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c); }}
00264 #define Warning4(type, a,b,c,d) \
00265     { if (DoLogWarning(type)){ \
00266         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c, d); }}
00267 #define Warning5(type, a,b,c,d,e) \
00268     { if (DoLogWarning(type)){ \
00269         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c, d, e); }}
00270 #define Warning6(type, a,b,c,d,e,f) \
00271     { if (DoLogWarning(type)){ \
00272         pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_WARNING, type, 0, a, b, c, d, e, f); }}
00273 
00274 #define Error1(a) \
00275     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a); }
00276 #define Error2(a,b) \
00277     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b); }
00278 #define Error3(a,b,c) \
00279     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c); }
00280 #define Error4(a,b,c,d) \
00281     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c, d); }
00282 #define Error5(a,b,c,d,e) \
00283     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c, d, e); }
00284 #define Error6(a,b,c,d,e,f) \
00285     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_ERROR, LOG_ANY, 0, a, b, c, d, e, f); }
00286 
00287 #define Bug1(a) \
00288     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a); }
00289 #define Bug2(a,b) \
00290     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b); }
00291 #define Bug3(a,b,c) \
00292     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c); }
00293 #define Bug4(a,b,c,d) \
00294     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c, d); }
00295 #define Bug5(a,b,c,d,e) \
00296     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c, d, e); }
00297 #define Bug6(a,b,c,d,e,f) \
00298     { pslog::LogMessage (__FILE__, __LINE__, __FUNCTION__, CS_REPORTER_SEVERITY_BUG, LOG_ANY, 0, a, b, c, d, e, f); }
00299 
00300 } // end of namespace pslog
00301 
00302 // Used to create Comma Seperated Value files for general logging
00303 // and takes advantage of ConfigManager and VFS which pslog cannot.
00304 // This should be used only for day-to-day information needed in a
00305 // consistent, readable format. Warnings and errors should go through pslog.
00306 class LogCSV : public Singleton<LogCSV>
00307 {
00308     csRef<iFile> csvFile[MAX_CSV];
00309     void StartLog(const char* logfile, iVFS* vfs, const char* header, size_t maxSize, csRef<iFile>& csvFile);
00310 
00311 public:
00312     LogCSV(iConfigManager* configmanager, iVFS* vfs);
00313     void Write(int type, csString& text);
00314 };
00315 
00318 #endif