-rw-r--r-- | libopie2/opiecore/odebug.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp index b4eaf2d..b2a37bc 100644 --- a/libopie2/opiecore/odebug.cpp +++ b/libopie2/opiecore/odebug.cpp @@ -31,193 +31,197 @@ */ // Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo // functions inlined to noops (which would then conflict with their definition here). #include <opie2/odebug.h> #ifdef OPIE_NO_DEBUG #undef odDebug #undef odBacktrace #endif /* OPIE */ #include <opie2/oapplication.h> #include <opie2/oglobalsettings.h> #include <opie2/oconfig.h> /* QT */ #include <qbrush.h> #include <qdatetime.h> #include <qfile.h> #include <qhostaddress.h> #include <qmessagebox.h> #include <qintdict.h> #include <qpoint.h> #include <qrect.h> #include <qregion.h> #include <qsize.h> #include <qsocketdevice.h> #include <qstring.h> #include <qstringlist.h> #include <qtextstream.h> /* UNIX */ #include <stdlib.h> // abort #include <unistd.h> // getpid #include <stdarg.h> // vararg stuff #include <ctype.h> // isprint #include <syslog.h> #include <errno.h> #include <string.h> #ifndef OPIE_NO_BACKTRACE #include <execinfo.h> #endif /*====================================================================================== * debug levels *======================================================================================*/ enum DebugLevels { ODEBUG_INFO = 0, ODEBUG_WARN = 1, ODEBUG_ERROR = 2, ODEBUG_FATAL = 3 }; /*====================================================================================== * oDebug private data *======================================================================================*/ /*====================================================================================== * the main debug function *======================================================================================*/ static void oDebugBackend( unsigned short level, unsigned int area, const char *data) { //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an // ML: example use. I think it's not necessary to implement such a strategy here. // ML: Comments? int priority = 0; QString caption; QString lev; switch( level ) { case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; } short output = OGlobalSettings::debugMode(); if (!oApp && (output == 1)) { qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); output = 2; // need an application object to use MsgBox } - QString areaName = (oApp) ? oApp->appName() : "<unknown>"; + // gcc 2.9x is dumb and sucks... can you hear it? + //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; + QString areaName; + if ( oApp ) areaName = oApp->appName(); + else areaName = "<unknown>"; // Output switch( output ) { case -1: // ignore { return; } case 0: // File { QString outputFilename = OGlobalSettings::debugOutput(); const int BUFSIZE = 4096; char buf[BUFSIZE] = ""; buf[BUFSIZE-1] = '\0'; int nSize; nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); QFile outputFile( outputFilename ); if ( outputFile.open( IO_WriteOnly | IO_Append ) ) { if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) { outputFile.writeBlock( buf, BUFSIZE-1 ); } else { outputFile.writeBlock( buf, nSize ); } } else { qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); } break; } // automatic close of file here case 1: // Message Box { // Since we are in opiecore here, we cannot use OMsgBox and use // QMessageBox instead caption += QString("(") + areaName + ")"; QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? break; } case 2: // Shell { FILE *output = stderr; fprintf( output, "%s: ", (const char*) areaName ); fputs( data, output); break; } case 3: // syslog { syslog( priority, "%s", data); break; } case 4: // socket { QString destination = OGlobalSettings::debugOutput(); if ( destination && destination.find(":") != -1 ) { QString host = destination.left( destination.find(":") ); QString port = destination.right( destination.length()-host.length()-1 ); QHostAddress addr; addr.setAddress( host ); // TODO: sanity check the address QString line; line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); QSocketDevice s( QSocketDevice::Datagram ); int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); if ( result == -1 ) { qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); } } break; } } // check if we should abort /* if( ( nLevel == ODEBUG_FATAL ) && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) abort(); */ } |