Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tools/3dsmaxExport/LEXIExporter/SharedUtilities/Sources/LogSystem.h @ 6

Last change on this file since 6 was 6, checked in by anonymous, 17 years ago

=…

File size: 3.8 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of LEXIExporter
4
5Copyright 2006 NDS Limited
6
7Author(s):
8Lasse Tassing
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25
26#ifndef __LOGSYSTEM__
27#define __LOGSYSTEM__
28
29// The basic loglevels
30enum ELogLevel
31{
32        LOG_INFO=0,
33        LOG_DEBUG=1,
34        LOG_WARNING=2,
35        LOG_ERROR=3,
36        LOG_MSG_CUSTOM_BEGIN=0x10
37};
38
39// The LogReceiver interface - implement this interface and call CLogSystem::AddReceiver() to receive
40// log messages.
41class ILogReceiver : public CRefCount
42{
43public:
44        virtual ~ILogReceiver(void) {};
45
46        // Called when a log message is received.
47        virtual void    ReceiveLogMessage(SYSTEMTIME &LogTime, const char *pszTimeStr, int iLevel, const char *pszMessage)=0;
48};
49
50// The logsystem is a singleton class - the instance will be created at the first Get() call.
51// Please note: By default there is no LogReceivers associated with the logsystem.
52class CLogSystem
53{
54public:
55        // Constructor/Destructor
56        CLogSystem(void);
57        ~CLogSystem(void);
58
59        // Static get function - so we can reach the logsystem
60        static CLogSystem *Get(void);
61
62        // Set min. log level
63        void    SetMinLogLevel(ELogLevel eLevel) { m_eMinLogLevel=eLevel; }
64
65        // Add a message to log
66        void    LogMessage(const void *pModule, int iLevel, const char *pszText, ...);
67
68        // Register a system module
69        void    RegisterModule(const void *pModulePointer, const char *pszModuleDesc);
70
71        // Register a system module
72        void    UnregisterModule(const void *pModulePointer);
73
74        // Add a log receiver
75        void    AddReceiver(ILogReceiver *pReceiver);
76
77        // Remove a log receiver
78        void    RemoveReceiver(ILogReceiver *pReceiver);
79
80private:
81        // Pointer to the instance of the log system
82        static CLogSystem *m_pThis;
83
84        // Minimum logging level
85        ELogLevel               m_eMinLogLevel;
86
87        // Map of registered modules
88        fastintmap< char* >     m_lModules;
89
90        // List of registered receivers
91        fastvector< ILogReceiver* >     m_lReceivers;
92
93        CRITICAL_SECTION        m_Crit;
94};
95
96/*
97        LOG SYSTEM MACROS
98*/
99#ifndef _DISABLE_LOGGING
100       
101        // Module registration
102        #define REGISTER_MODULE(pszDesc)        CLogSystem::Get()->RegisterModule(this, pszDesc);
103        #define UNREGISTER_MODULE                       CLogSystem::Get()->UnregisterModule(this);
104
105        // Low priority log macros
106        #ifndef _DISABLE_LOWPRIOLOG
107                #define LOGINFO         CLogSystem::Get()->LogMessage(this, LOG_INFO,
108                #define LOGDEBUG        CLogSystem::Get()->LogMessage(this, LOG_DEBUG,
109        #else
110                #define LOGINFO         (
111                #define LOGDEBUG        (
112        #endif
113
114        // High priority log macros
115        #define LOGWARNING      CLogSystem::Get()->LogMessage(this, LOG_WARNING,
116        #define LOGERROR        CLogSystem::Get()->LogMessage(this, LOG_ERROR,
117        #define LOGCUSTOM       CLogSystem::Get()->LogMessage(this,
118
119        // Macros for static / thread functions
120        #define LOGSTATIC       CLogSystem::Get()->LogMessage(NULL,
121        #define LOGTHREAD       CLogSystem::Get()->LogMessage( 
122#else
123       
124        // Logging is disabled; all macros will create blank code
125        #define REGISTER_MODULE(pThisPointer, pszDesc)
126        #define UNREGISTER_MODULE(pThisPointer)
127        #define LOGINFO         (
128        #define LOGDEBUG        (
129        #define LOGWARNING      (
130        #define LOGERROR        (
131        #define LOGSTATIC       (       
132#endif
133
134#endif
Note: See TracBrowser for help on using the repository browser.