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 RS_Debug * RS_Debug::uniqueInstance = NULL;
25 * Gets the one and only RS_Debug instance
26 * (creates a new one on first call only)
28 * @return Pointer to the single instance of this
31 RS_Debug * RS_Debug::instance()
33 if (uniqueInstance == NULL)
35 QDateTime now = QDateTime::currentDateTime();
37 nowStr = now.toString("yyyyMMdd_hhmmss");
38 QString fName = QString("debug_%1.log").arg(nowStr);
40 uniqueInstance = new RS_Debug;
41 //uniqueInstance->stream = fopen(fName.latin1(), "wt");
42 // uniqueInstance->stream = stderr;
43 uniqueInstance->stream = stdout;
46 return uniqueInstance;
50 * Deletes the one and only RS_Debug instance.
52 void RS_Debug::deleteInstance()
54 if (uniqueInstance != NULL)
56 fclose(uniqueInstance->stream);
57 delete uniqueInstance;
62 * Constructor for a point with default coordinates.
66 debugLevel = D_DEBUGGING;
70 * Sets the debugging level.
72 void RS_Debug::setLevel(RS_DebugLevel level)
75 print("RS_DEBUG: Warnings", D_WARNING);
76 print("RS_DEBUG: Errors", D_ERROR);
77 print("RS_DEBUG: Notice", D_NOTICE);
78 print("RS_DEBUG: Informational", D_INFORMATIONAL);
79 print("RS_DEBUG: Debugging", D_DEBUGGING);
83 * Gets the current debugging level.
85 RS_Debug::RS_DebugLevel RS_Debug::getLevel()
91 * Prints the given message to stdout.
93 void RS_Debug::print(const char * format ...)
95 if (debugLevel == D_DEBUGGING)
99 vfprintf(stream, format, ap);
100 fprintf(stream, "\n");
107 * Prints the given message to stdout if the current debug level
108 * is lower then the given level
110 * @param level Debug level.
112 void RS_Debug::print(RS_DebugLevel level, const char * format ...)
114 if (debugLevel >= level)
117 va_start(ap, format);
118 vfprintf(stream, format, ap);
119 fprintf(stream, "\n");
126 * Prints a time stamp in the format yyyyMMdd_hhmmss.
128 void RS_Debug::timestamp()
130 QDateTime now = QDateTime::currentDateTime();
131 QString nowStr = now.toString("yyyyMMdd_hh:mm:ss:zzz ");
132 fprintf(stream, "%s", nowStr.toLatin1().data());
133 fprintf(stream, "\n");
138 * Prints the unicode for every character in the given string.
140 void RS_Debug::printUnicode(const QString & text)
142 for(int i=0; i<(int)text.length(); i++)
143 print("[%X] %c", text.at(i).unicode(), text.at(i).toLatin1());
146 void RS_Debug::setStream(FILE * s)