windows changes
[csql.git] / src / storage / Debug.cxx
blob6878a11bb9836ae500b808173dc8715036cade37
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include<Debug.h>
17 #include<Config.h>
19 int DebugDM_Alloc = 0;
20 int DebugDM_VarAlloc = 0;
21 int DebugDM_Lock = 0;
22 int DebugDM_Transaction = 0;
23 int DebugDM_UndoLog = 0;
24 int DebugDM_RedoLog = 0;
25 int DebugDM_Recovery = 0;
26 int DebugDM_Index = 0;
27 int DebugDM_HashIndex = 0;
28 int DebugDM_TreeIndex = 0;
29 int DebugDM_TrieIndex = 0;
30 int DebugDM_SystemDatabase = 0;
31 int DebugDM_Database = 0;
32 int DebugDM_Table = 0;
33 int DebugDM_Predicate = 0;
34 int DebugDM_TableIterator = 0;
35 int DebugDM_Process=0;
36 int DebugDM_Network=0;
37 int DebugDM_Gateway=0;
38 int DebugDM_Adapter=0;
39 int DebugDM_SqlLog=0;
40 int DebugDM_CacheServer=0;
41 int DebugDM_TEST=1;
42 int DebugDM_Warning=0;
43 int printStackTrace()
45 #ifdef LINUX
46 void *array[10];
47 size_t size = backtrace(array, 10);
48 backtrace_symbols_fd(array, size, 2);
49 #endif
50 return 0;
53 int printError1(DbRetVal val, char* fname, int lno, char *format, ...)
55 va_list ap;
56 int fd = -1;
57 char tempBuffer[64];
58 struct timeval timeStamp;
59 char mesgBuf[1024];
60 #if defined(SOLARIS) && defined(REMOTE_SOLARIS)
61 os::gettimeofday(&timeStamp);
62 struct tm *tempTm = os::localtime(&timeStamp.tv_sec);
63 strftime(tempBuffer, 64, "%d/%m/%Y %H:%M:%S", (struct std::tm*) tempTm);
64 #elif defined WINNT
65 time_t ltime;
66 struct tm today;
67 time( &ltime);
68 _localtime64_s( &today, &ltime );
69 strftime(tempBuffer, 64, "%d/%m/%Y %H:%M:%S", &today);
70 #else
71 os::gettimeofday(&timeStamp);
72 struct tm *tempTm = os::localtime(&timeStamp.tv_sec);
73 trftime(tempBuffer, 64, "%d/%m/%Y %H:%M:%S", tempTm);
74 #endif
76 if (strncasecmp(Conf::config.getStderrFile(),"stderr", 6) == 0) fd = 2;
77 else {
78 fd = os::openFileForAppend(Conf::config.getStderrFile(), O_CREAT);
79 if (fd == -1) fd = 2;
82 snprintf(mesgBuf, MAX_TRACE_LOG_LENGTH, "%s.%6d:%5d:%10lu:%s:%d:",
83 tempBuffer, timeStamp.tv_usec, os::getpid(), os::getthrid(), fname, lno);
85 os::write(fd, mesgBuf, strlen(mesgBuf));
87 va_start(ap, format);
89 int err = ::vsnprintf(mesgBuf, sizeof(mesgBuf), format,ap);
90 if (err < 0) { return err; }
92 os::write(fd, mesgBuf, strlen(mesgBuf));
93 strcpy(mesgBuf,"\n");
94 os::write(fd, mesgBuf, strlen(mesgBuf));
95 //2->stderr
96 return 0;
99 int printDebug1(int module, char *fname, int lno, char *format, ...)
101 switch(module) {
102 case DM_Alloc: { if (!DebugDM_Alloc) return 1; break; }
103 case DM_VarAlloc: { if (!DebugDM_VarAlloc) return 1; break; }
104 case DM_Lock: { if (!DebugDM_Lock) return 1; break; }
105 case DM_Transaction: { if (!DebugDM_Transaction) return 1; break; }
106 case DM_UndoLog: { if (!DebugDM_UndoLog) return 1; break; }
107 case DM_RedoLog: { if (!DebugDM_RedoLog) return 1; break; }
108 case DM_Recovery: { if (!DebugDM_Recovery) return 1; break; }
109 case DM_HashIndex: { if (!DebugDM_HashIndex) return 1; break; }
110 case DM_TrieIndex: { if (!DebugDM_TrieIndex) return 1; break; }
111 case DM_TreeIndex: { if (!DebugDM_TreeIndex) return 1; break; }
112 case DM_SystemDatabase: { if (!DebugDM_SystemDatabase) return 1; break; }
113 case DM_Database: { if (!DebugDM_Database) return 1; break; }
114 case DM_Table: { if (!DebugDM_Table) return 1; break; }
115 case DM_Iterator: { if (!DebugDM_TableIterator) return 1; break; }
116 case DM_Predicate: { if (!DebugDM_Predicate) return 1; break; }
117 case DM_Process: { if (!DebugDM_Process) return 1; break; }
118 case DM_Network: { if (!DebugDM_Network) return 1; break; }
119 case DM_Gateway: { if (!DebugDM_Gateway) return 1; break; }
120 case DM_Adapter: { if (!DebugDM_Adapter) return 1; break; }
121 case DM_SqlLog: { if (!DebugDM_SqlLog) return 1; break; }
122 case DM_CacheServer: { if (!DebugDM_CacheServer) return 1; break; }
123 case DM_TEST: { if (!DebugDM_TEST) return 1; break; }
124 case DM_Warning: { if (!DebugDM_Warning) return 1; break; }
128 va_list ap;
129 char mesgBuf[1024];
131 sprintf(mesgBuf, "D:%s:%d:%lu:%s:%d:", moduleNames[module],
132 os::getpid(), os::getthrid(), fname, lno);
133 os::write(1, mesgBuf, strlen(mesgBuf));
135 va_start(ap, format);
137 int err = ::vsnprintf(mesgBuf, sizeof(mesgBuf), format,ap);
138 if(err < 0) {
139 return err;
141 os::write(1, mesgBuf, strlen(mesgBuf));
142 strcpy(mesgBuf,"\n");
143 os::write(1, mesgBuf, strlen(mesgBuf));
144 //1->stdout
145 return 0;