3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/28/2010 Added this text. :-)
22 Debug * Debug::uniqueInstance = NULL;
25 * Gets the one and only Debug instance (creates a new one on first call only)
27 * @return Pointer to the single instance of this singleton class
29 Debug * Debug::instance()
31 if (uniqueInstance == NULL)
33 QDateTime now = QDateTime::currentDateTime();
35 nowStr = now.toString("yyyyMMdd_hhmmss");
36 QString fName = QString("debug_%1.log").arg(nowStr);
38 uniqueInstance = new Debug;
39 // uniqueInstance->stream = fopen(fName.toAscii().data(), "wt");
40 // uniqueInstance->stream = stderr;
41 uniqueInstance->stream = stdout;
44 return uniqueInstance;
48 * Deletes the one and only Debug instance.
50 void Debug::deleteInstance()
54 fclose(uniqueInstance->stream);
55 delete uniqueInstance;
60 * Constructor for a point with default coordinates.
64 debugLevel = D_DEBUGGING;
68 * Sets the debugging level.
70 void Debug::setLevel(DebugLevel level)
73 print("DEBUG: Warnings", D_WARNING);
74 print("DEBUG: Errors", D_ERROR);
75 print("DEBUG: Notice", D_NOTICE);
76 print("DEBUG: Informational", D_INFORMATIONAL);
77 print("DEBUG: Debugging", D_DEBUGGING);
81 * Gets the current debugging level.
83 Debug::DebugLevel Debug::getLevel()
89 * Prints the given message to stdout.
91 void Debug::print(const char * format ...)
93 if (debugLevel == D_DEBUGGING)
97 vfprintf(stream, format, ap);
98 fprintf(stream, "\n");
105 * Prints the given message to stdout if the current debug level
106 * is lower then the given level
108 * @param level Debug level.
110 void Debug::print(DebugLevel level, const char * format ...)
112 if (debugLevel >= level)
115 va_start(ap, format);
116 vfprintf(stream, format, ap);
117 fprintf(stream, "\n");
124 * Prints a time stamp in the format yyyyMMdd_hhmmss.
126 void Debug::timestamp()
128 QDateTime now = QDateTime::currentDateTime();
129 QString nowStr = now.toString("yyyyMMdd_hh:mm:ss:zzz ");
130 fprintf(stream, "%s", nowStr.toAscii().data());
131 fprintf(stream, "\n");
136 * Prints the unicode for every character in the given string.
138 void Debug::printUnicode(const QString & text)
140 for(int i=0; i<(int)text.length(); i++)
141 print("[%X] %c", text.at(i).unicode(), text.at(i).toAscii());
144 void Debug::setStream(FILE * s)