code reorg
[csql.git] / src / server / Debug.cxx
blobdfaaaab44ec8151cd89b3c32831cd88d420dfb54
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>
18 int DebugDM_Alloc = 0;
19 int DebugDM_VarAlloc = 0;
20 int DebugDM_Lock = 0;
21 int DebugDM_Transaction = 0;
22 int DebugDM_UndoLog = 0;
23 int DebugDM_RedoLog = 0;
24 int DebugDM_Index = 0;
25 int DebugDM_HashIndex = 0;
26 int DebugDM_SystemDatabase = 0;
27 int DebugDM_Database = 0;
28 int DebugDM_Table = 0;
29 int DebugDM_Predicate = 0;
30 int DebugDM_TableIterator = 0;
31 int DebugDM_Process=0;
32 int DebugDM_Network=0;
33 int DebugDM_Gateway=0;
34 int DebugDM_Adapter=0;
35 int DebugDM_SqlLog=0;
37 int printError1(DbRetVal val, char* fname, int lno, char *format, ...)
39 va_list ap;
40 char mesgBuf[1024];
42 sprintf(mesgBuf, "%d:%lu:%s:%d:",
43 os::getpid(), os::getthrid(), fname, lno);
44 os::write(2, mesgBuf, strlen(mesgBuf));
46 va_start(ap, format);
48 int err = ::vsnprintf(mesgBuf, sizeof(mesgBuf), format,ap);
49 if(err < 0) {
50 return err;
52 os::write(2, mesgBuf, strlen(mesgBuf));
53 strcpy(mesgBuf,"\n");
54 os::write(2, mesgBuf, strlen(mesgBuf));
55 //2->stderr
56 return 0;
61 int printDebug1(int module, char *fname, int lno, char *format, ...)
63 switch(module) {
64 case DM_Alloc: { if (!DebugDM_Alloc) return 1; break; }
65 case DM_VarAlloc: { if (!DebugDM_VarAlloc) return 1; break; }
66 case DM_Lock: { if (!DebugDM_Lock) return 1; break; }
67 case DM_Transaction: { if (!DebugDM_Transaction) return 1; break; }
68 case DM_UndoLog: { if (!DebugDM_UndoLog) return 1; break; }
69 case DM_RedoLog: { if (!DebugDM_RedoLog) return 1; break; }
70 case DM_HashIndex: { if (!DebugDM_HashIndex) return 1; break; }
71 case DM_SystemDatabase: { if (!DebugDM_SystemDatabase) return 1; break; }
72 case DM_Database: { if (!DebugDM_Database) return 1; break; }
73 case DM_Table: { if (!DebugDM_Table) return 1; break; }
74 case DM_Iterator: { if (!DebugDM_TableIterator) return 1; break; }
75 case DM_Predicate: { if (!DebugDM_Predicate) return 1; break; }
76 case DM_Process: { if (!DebugDM_Process) return 1; break; }
77 case DM_Network: { if (!DebugDM_Network) return 1; break; }
78 case DM_Gateway: { if (!DebugDM_Gateway) return 1; break; }
79 case DM_Adapter: { if (!DebugDM_Adapter) return 1; break; }
80 case DM_SqlLog: { if (!DebugDM_SqlLog) return 1; break; }
84 va_list ap;
85 char mesgBuf[1024];
87 sprintf(mesgBuf, "D:%s:%d:%lu:%s:%d:", moduleNames[module],
88 os::getpid(), os::getthrid(), fname, lno);
89 os::write(1, mesgBuf, strlen(mesgBuf));
91 va_start(ap, format);
93 int err = ::vsnprintf(mesgBuf, sizeof(mesgBuf), format,ap);
94 if(err < 0) {
95 return err;
97 os::write(1, mesgBuf, strlen(mesgBuf));
98 strcpy(mesgBuf,"\n");
99 os::write(1, mesgBuf, strlen(mesgBuf));
100 //1->stdout
101 return 0;