Statistics
| Revision:

root / trunk / libraries / libjni-ecw / include / NCSLog.h @ 6869

History | View | Annotate | Download (4.84 KB)

1
/********************************************************
2
** Copyright 1999 Earth Resource Mapping Ltd.
3
** This document contains proprietary source code of
4
** Earth Resource Mapping Ltd, and can only be used under
5
** one of the three licenses as described in the 
6
** license.txt file supplied with this distribution. 
7
** See separate license.txt file for license details 
8
** and conditions.
9
**
10
** This software is covered by US patent #6,442,298,
11
** #6,102,897 and #6,633,688.  Rights to use these patents 
12
** is included in the license agreements.
13
**
14
** FILE:           NCSLog.h
15
** CREATED:        Mon May 31 09:19:00 WST 1999
16
** AUTHOR:         Doug Mansell
17
** PURPOSE:        NCS server logging interface
18
** EDITS:
19
** [01] 06-06-02 Changed the Registry key names to match IWS 1.7
20
 *******************************************************/
21

    
22

    
23
#ifndef NCSLOG_H
24
#define NCSLOG_H
25

    
26
#ifndef NCSTYPES_H
27
#include "NCSTypes.h"
28
#endif // NCSTYPES_H
29

    
30
#ifdef __cplusplus 
31
extern "C" {
32
#endif
33

    
34
#define NCS_SERVER_LOG_FILE_NAME_PREF                "Log Filename"                //[01]
35
#define NCS_SERVER_LOG_FILE_LEVEL_PREF                "Log Level"                        //[01]
36
#define NCS_LOG_FILE_NAME_PREF                                "IWS Log Filename"
37
#define NCS_LOG_FILE_LEVEL_PREF                                "IWS Log Level"
38

    
39
typedef enum
40
{
41
        LOG_LOW = 0,                // lowest log level
42
        LOG_MED,                        // more informational
43
        LOG_HIGH,                        // and more
44

    
45
        LOG_HIGHER
46
                                                // ... with room for even more
47
} ENCSLogLevel;
48

    
49

    
50
void NCSLogGetConfig(char **pLogName, ENCSLogLevel *pLogLevel);
51
void NCSLog(ENCSLogLevel eLevel, char *szFormat, ...);
52
void NCSLogSetServer(BOOLEAN bValue);
53

    
54
void NCSLogInit();
55
void NCSLogFini();
56

    
57
#ifdef __cplusplus 
58

    
59
#ifndef NCSOBJECT_H
60
#include "NCSObject.h"
61
#endif // NCSOBJECT_H
62

    
63
#ifndef NCSMUTEX_H
64
#include "NCSMutex.h"
65
#endif // NCSMUTEX_H
66

    
67
#ifndef NCSTHREAD_H
68
#include "NCSThread.h"
69
#endif // NCSTHREAD_H
70

    
71
/**
72
 * Logging utility class for server.
73
 * 
74
 * @author       Simon Cope
75
 * @version      $Revision: 3538 $ $Author: nacho $ $Date: 2006-01-09 12:56:54 +0100 (Mon, 09 Jan 2006) $ 
76
 */
77
class NCS_EXPORT CNCSLog: public CNCSObject {
78
public:
79
        /**
80
         * Enum of the different log levels available.  LOG_DEBUG only appears in the log file for a DEBUG build.
81
         */
82
        typedef enum {
83
                LOG_LEVEL0        = LOG_LOW,                // Always logged
84
                LOG_LEVEL1        = LOG_MED,                // Level 1 messages
85
                LOG_LEVEL2        = LOG_HIGH,                // Level 2 messages
86
                LOG_LEVEL3        = LOG_HIGHER,        // Level 3 messages
87

    
88
                LOG_DEBUG                                        // DEBUG build only
89
        } NCSLogLevel;
90

    
91
        /**
92
         * Default Constructor.
93
         */
94
        CNCSLog();
95
        virtual ~CNCSLog();
96

    
97
        /**
98
         * Log a string to the log file.  String is also written out using OutputDebugString() 
99
         * (on WIN32) or fprintf(stderr) (other platforms) under a DEBUG build
100
         * 
101
         * @param                 pBuf                        String to log to the log file
102
         */
103
        static void Log(char *pBuf);
104
        /**
105
         * Log a formatted error if the loggin level meets the specified one.
106
         * 
107
         * @param        eLevel                        Log level that must be met before message should be logged.
108
         * @param                 pFormat                printf() style format string to log
109
         * @param                 ...                        Argument list to match pFormat format string
110
         */
111
        static void Log(NCSLogLevel eLevel, char *pFormat, ...);
112
        /**
113
         * Lof a formatted error and file/line entry to the log file if the logging level meets the specified one.
114
         * 
115
         * @param        pFile                        File name where Log() is called (usually __FILE__ is used)
116
         * @param                 nLine                        Line number in file where Log() is called (usually __LINE__ is used)
117
         * @param        eLevel                        Log level that must be met before message should be logged.
118
         * @param                 pFormat                printf() style format string to log
119
         * @param                 ...                        Argument list to match pFormat format string
120
         */
121
        static void Log(char *pFile, int nLine, NCSLogLevel eLevel, char *pFormat, ...);
122
        /**
123
         * Get the current log level.
124
         * 
125
         * @return       NCSLogLevel        Current log level as set in the registry
126
         */
127
        static NCSLogLevel GetLogLevel(void);
128
        /**
129
         * Update the current log level and log file name from the registry (WIN32).
130
         * 
131
         */
132
        static void UpdateLogConfig(void);
133

    
134
private:
135
        /**
136
         * Mutex for accessing the log level and log file name, which can change at runtime.
137
         * 
138
         * @see                                #sm_eLogLevel
139
         * @see                                #sm_szLogFile
140
         */
141
        static CNCSMutex        sm_Mutex;
142
        /**
143
         * Current log level.
144
         */
145
        static NCSLogLevel        sm_eLogLevel;
146
        /**
147
         * Current log file name.
148
         */
149
        static char                        sm_szLogFile[MAX_PATH];
150
        //static int                        sm_nRefCount;
151
        
152
public:
153
        class NCS_EXPORT CNCSUpdateLogConfigThread: public CNCSThread {
154
        public:
155
                CNCSUpdateLogConfigThread() {
156
                        //Spawn(this, false);
157
                }
158

    
159
                virtual ~CNCSUpdateLogConfigThread() {
160
                        Stop();
161
                }
162

    
163
                void Work( void *pData );
164
        };
165

    
166
        static CNCSUpdateLogConfigThread *pUpdateLogConfigThread;
167

    
168
        /**
169
         * CNCSThread Work() function, used to update config from registry.
170
         * 
171
         * @param        pParameter        (UNUSED)
172
         */
173
        //void                                Work(void *pParameter);
174
};
175

    
176
#define LOGERROR0( t, e )        CNCSLog::Log(__FILE__, __LINE__, CNCSLog::LOG_LEVEL0, "Error: %s %s(%ld)", t, NCSGetErrorText(e), e)
177
#define LOGERROR1( t, e )        CNCSLog::Log(__FILE__, __LINE__, CNCSLog::LOG_LEVEL1, "Error: %s %s(%ld)", t, NCSGetErrorText(e), e)
178

    
179
}
180
#endif
181

    
182
#endif