windows changes
[csql.git] / include / Debug.h
blobe39b171e681f230a3c352509ed0bde195033796d
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef DEBUG_H
8 #define DEBUG_H
9 #include<os.h>
10 #include<ErrorType.h>
11 #include<FaultTest.h>
12 #define DEBUG 1
13 extern int DebugDM_Alloc;
14 extern int DebugDM_VarAlloc;
15 extern int DebugDM_Lock;
16 extern int DebugDM_Transaction;
17 extern int DebugDM_UndoLog;
18 extern int DebugDM_RedoLog;
19 extern int DebugDM_Recovery;
20 extern int DebugDM_Index;
21 extern int DebugDM_HashIndex;
22 extern int DebugDM_TreeIndex;
23 extern int DebugDM_TrieIndex;
24 extern int DebugDM_SystemDatabase;
25 extern int DebugDM_Database;
26 extern int DebugDM_Table;
27 extern int DebugDM_Predicate;
28 extern int DebugDM_Iterator;
29 extern int DebugDM_Process;
30 extern int DebugDM_Network;
31 extern int DebugDM_Gateway;
32 extern int DebugDM_Adapter;
33 extern int DebugDM_SqlLog;
34 extern int DebugDM_CacheServer;
35 extern int DebugDM_TEST;
36 extern int DebugDM_Warning;
38 int printStackTrace();
39 #ifdef WINNT
40 DllExport int printError1(DbRetVal val, char* fname, int lno, char *format, ...);
41 #else
42 extern int printError1(DbRetVal val, char* fname, int lno, const char *format, ...);
43 #endif
44 #define printError(a, ...) printError1(a, __FILE__, __LINE__, __VA_ARGS__)
46 enum DebugModule
48 DM_Alloc = 0,
49 DM_VarAlloc,
50 DM_Lock,
51 DM_Transaction,
52 DM_UndoLog,
53 DM_RedoLog,
54 DM_Recovery,
55 DM_Index,
56 DM_HashIndex,
57 DM_TreeIndex,
58 DM_TrieIndex,
59 DM_SystemDatabase,
60 DM_Database,
61 DM_Table,
62 DM_Predicate,
63 DM_Iterator,
64 DM_Process,
65 DM_Network,
66 DM_Gateway,
67 DM_Adapter,
68 DM_SqlLog,
69 DM_CacheServer,
70 DM_TEST,
71 DM_Warning
73 static char moduleNames[][20] =
75 "Alloc", "VariableAlloc", "Lock", "Trans", "UndoLog", "RedoLog", "Recovery", "Index",
76 "HashIndex", "TreeIndex", "TrieIndex", "SysDb", "Db", "Table", "Predicate", "Iter",
77 "Procmgmt", "Network", "Gateway", "Adapter", "SqlLog",
78 "CacheServer", "TEST", "Warning"
80 #ifdef WINNT
81 DllExport int printDebug1(int module, char* fname, int lno, char *format, ...);
82 #else
83 extern int printDebug1(int module, char *fname, int lineno, char *format, ...);
84 #endif
86 #ifdef DEBUG
87 #define printDebug(a, ...) printDebug1(a, __FILE__, __LINE__, __VA_ARGS__)
88 #else
89 #define printDebug(...) ;
90 #endif
92 //Logging
94 #define MAX_TRACE_LOG_LENGTH 1024
96 enum LogLevel
98 LogOff = 0,
99 LogFine,
100 LogFiner,
101 LogFinest
104 static char levelNames[][10] =
106 "OFF", "FINE", "FINER", "FINEST"
108 #include<Mutex.h>
109 class DllExport Logger
111 int fdLog; //file descriptor
112 LogLevel configLevel; //configuration file setting is cached here.
113 void rollOverIfRequired();
114 public:
115 int log(LogLevel level, char* filename, int lineNo, char *format, ...);
116 int createLogRecord(LogLevel level, char* filename, int lineNo, char* message, char **in);
117 DbRetVal startLogger(char *filename, bool isCreate = false);
118 void stopLogger();
121 #define logFinest(logger, ...) \
123 (logger).log(LogFinest, __FILE__, __LINE__, __VA_ARGS__);\
126 #define logFiner(logger, ...) \
128 (logger).log(LogFiner, __FILE__, __LINE__, __VA_ARGS__);\
131 #define logFine(logger, ...) \
133 (logger).log(LogFine, __FILE__, __LINE__, __VA_ARGS__);\
137 #endif