Statistics
| Revision:

root / tags / gvsig_sextante-0.2.0-1231 / libraries / libjni-ecwcompress / include / NCSLog.h @ 34606

History | View | Annotate | Download (4.59 KB)

1 1429 igbrotru
/********************************************************
2
** Copyright 1999 Earth Resource Mapping Pty Ltd.
3
** This document contains unpublished source code of
4
** Earth Resource Mapping Pty Ltd. This notice does
5
** not indicate any intention to publish the source
6
** code contained herein.
7
**
8
** FILE:           NCSLog.h
9
** CREATED:        Mon May 31 09:19:00 WST 1999
10
** AUTHOR:         Doug Mansell
11
** PURPOSE:        NCS server logging interface
12
** EDITS:
13
** [01] 06-06-02 Changed the Registry key names to match IWS 1.7
14
 *******************************************************/
15
16
17
#ifndef NCSLOG_H
18
#define NCSLOG_H
19
20
#ifndef NCSTYPES_H
21
#include "NCSTypes.h"
22
#endif // NCSTYPES_H
23
24
#ifdef __cplusplus
25
extern "C" {
26
#endif
27
28
#define NCS_SERVER_LOG_FILE_NAME_PREF                "Log Filename"                //[01]
29
#define NCS_SERVER_LOG_FILE_LEVEL_PREF                "Log Level"                        //[01]
30
#define NCS_LOG_FILE_NAME_PREF                                "IWS Log Filename"
31
#define NCS_LOG_FILE_LEVEL_PREF                                "IWS Log Level"
32
33
typedef enum
34
{
35
        LOG_LOW = 0,                // lowest log level
36
        LOG_MED,                        // more informational
37
        LOG_HIGH,                        // and more
38
39
        LOG_HIGHER
40
                                                // ... with room for even more
41
} ENCSLogLevel;
42
43
44
void NCSLogGetConfig(char **pLogName, ENCSLogLevel *pLogLevel);
45
void NCSLog(ENCSLogLevel eLevel, char *szFormat, ...);
46
void NCSLogSetServer(BOOLEAN bValue);
47
48
void NCSLogInit();
49
void NCSLogFini();
50
51
#ifdef __cplusplus
52
53
#ifndef NCSOBJECT_H
54
#include "NCSObject.h"
55
#endif // NCSOBJECT_H
56
57
#ifndef NCSMUTEX_H
58
#include "NCSMutex.h"
59
#endif // NCSMUTEX_H
60
61
#ifndef NCSTHREAD_H
62
#include "NCSThread.h"
63
#endif // NCSTHREAD_H
64
65
/**
66
 * Logging utility class for server.
67
 *
68
 * @author       Simon Cope
69
 * @version      $Revision$ $Author$ $Date$
70
 */
71
class NCS_EXPORT CNCSLog: public CNCSObject {
72
public:
73
        /**
74
         * Enum of the different log levels available.  LOG_DEBUG only appears in the log file for a DEBUG build.
75
         */
76
        typedef enum {
77
                LOG_LEVEL0        = LOG_LOW,                // Always logged
78
                LOG_LEVEL1        = LOG_MED,                // Level 1 messages
79
                LOG_LEVEL2        = LOG_HIGH,                // Level 2 messages
80
                LOG_LEVEL3        = LOG_HIGHER,        // Level 3 messages
81
82
                LOG_DEBUG                                        // DEBUG build only
83
        } NCSLogLevel;
84
85
        /**
86
         * Default Constructor.
87
         */
88
        CNCSLog();
89
        virtual ~CNCSLog();
90
91
        /**
92
         * Log a string to the log file.  String is also written out using OutputDebugString()
93
         * (on WIN32) or fprintf(stderr) (other platforms) under a DEBUG build
94
         *
95
         * @param                 pBuf                        String to log to the log file
96
         */
97
        static void Log(char *pBuf);
98
        /**
99
         * Log a formatted error if the loggin level meets the specified one.
100
         *
101
         * @param        eLevel                        Log level that must be met before message should be logged.
102
         * @param                 pFormat                printf() style format string to log
103
         * @param                 ...                        Argument list to match pFormat format string
104
         */
105
        static void Log(NCSLogLevel eLevel, char *pFormat, ...);
106
        /**
107
         * Lof a formatted error and file/line entry to the log file if the logging level meets the specified one.
108
         *
109
         * @param        pFile                        File name where Log() is called (usually __FILE__ is used)
110
         * @param                 nLine                        Line number in file where Log() is called (usually __LINE__ is used)
111
         * @param        eLevel                        Log level that must be met before message should be logged.
112
         * @param                 pFormat                printf() style format string to log
113
         * @param                 ...                        Argument list to match pFormat format string
114
         */
115
        static void Log(char *pFile, int nLine, NCSLogLevel eLevel, char *pFormat, ...);
116
        /**
117
         * Get the current log level.
118
         *
119
         * @return       NCSLogLevel        Current log level as set in the registry
120
         */
121
        static NCSLogLevel GetLogLevel(void);
122
        /**
123
         * Update the current log level and log file name from the registry (WIN32).
124
         *
125
         */
126
        static void UpdateLogConfig(void);
127
128
private:
129
        /**
130
         * Mutex for accessing the log level and log file name, which can change at runtime.
131
         *
132
         * @see                                #sm_eLogLevel
133
         * @see                                #sm_szLogFile
134
         */
135
        static CNCSMutex        sm_Mutex;
136
        /**
137
         * Current log level.
138
         */
139
        static NCSLogLevel        sm_eLogLevel;
140
        /**
141
         * Current log file name.
142
         */
143
        static char                        sm_szLogFile[MAX_PATH];
144
        //static int                        sm_nRefCount;
145
146
public:
147
        class NCS_EXPORT CNCSUpdateLogConfigThread: public CNCSThread {
148
        public:
149
                CNCSUpdateLogConfigThread() {
150
                        //Spawn(this, false);
151
                }
152
153
                virtual ~CNCSUpdateLogConfigThread() {
154
                        Stop();
155
                }
156
157
                void Work( void *pData );
158
        };
159
160
        static CNCSUpdateLogConfigThread *pUpdateLogConfigThread;
161
162
        /**
163
         * CNCSThread Work() function, used to update config from registry.
164
         *
165
         * @param        pParameter        (UNUSED)
166
         */
167
        //void                                Work(void *pParameter);
168
};
169
170
#define LOGERROR0( t, e )        CNCSLog::Log(__FILE__, __LINE__, CNCSLog::LOG_LEVEL0, "Error: %s %s(%ld)", t, NCSGetErrorText(e), e)
171
#define LOGERROR1( t, e )        CNCSLog::Log(__FILE__, __LINE__, CNCSLog::LOG_LEVEL1, "Error: %s %s(%ld)", t, NCSGetErrorText(e), e)
172
173
}
174
#endif
175
176
#endif