diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2019-04-27 14:58:19 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2019-04-27 16:03:56 +0900 |
commit | d17480bf1d20c0a1429bf124c159a4f70716513e (patch) | |
tree | da0c3ae35a7073f40ecc8e6b9df5aa73f43c26ae /src | |
parent | 2fd4dcbf56b321dcbaf2a76dd51fd4d18bdd4e28 (diff) | |
download | qt3-d17480bf1d20c0a1429bf124c159a4f70716513e.tar.gz qt3-d17480bf1d20c0a1429bf124c159a4f70716513e.zip |
Added timestamp to debug functions (qDebug, qWarning, qFatal).
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 3ae061484d7a4098029d54af72963a163f421312)
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/qglobal.cpp | 107 |
1 files changed, 13 insertions, 94 deletions
diff --git a/src/tools/qglobal.cpp b/src/tools/qglobal.cpp index 47986e1..5eeb854 100644 --- a/src/tools/qglobal.cpp +++ b/src/tools/qglobal.cpp @@ -41,6 +41,7 @@ #include "qplatformdefs.h" #include "qasciidict.h" +#include <qdatetime.h> #include <limits.h> #include <stdio.h> #include <limits.h> @@ -464,42 +465,17 @@ static void mac_default_handler( const char *msg ) #endif - void qDebug( const char *msg, ... ) { char buf[QT_BUFFER_LENGTH]; + strcpy( buf, QDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").ascii() ); + int len = strlen(buf); va_list ap; va_start( ap, msg ); // use variable arg list #if defined(QT_VSNPRINTF) - QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); -#else - vsprintf( buf, msg, ap ); -#endif - va_end( ap ); - if ( handler ) { - (*handler)( QtDebugMsg, buf ); - } else { -#if defined(Q_CC_MWERKS) - mac_default_handler(buf); -#elif defined(Q_OS_TEMP) - QString fstr( buf ); - OutputDebugString( (fstr + "\n").ucs2() ); -#else - fprintf( stderr, "%s\n", buf ); // add newline -#endif - } -} - -// copied... this looks really bad. -void debug( const char *msg, ... ) -{ - char buf[QT_BUFFER_LENGTH]; - va_list ap; - va_start( ap, msg ); // use variable arg list -#if defined(QT_VSNPRINTF) - QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); + QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH, msg, ap ); #else - vsprintf( buf, msg, ap ); + vsprintf( &buf[len], msg, ap ); #endif va_end( ap ); if ( handler ) { @@ -519,39 +495,14 @@ void debug( const char *msg, ... ) void qWarning( const char *msg, ... ) { char buf[QT_BUFFER_LENGTH]; + strcpy( buf, QDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").ascii() ); + int len = strlen(buf); va_list ap; va_start( ap, msg ); // use variable arg list #if defined(QT_VSNPRINTF) - QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); -#else - vsprintf( buf, msg, ap ); -#endif - va_end( ap ); - if ( handler ) { - (*handler)( QtWarningMsg, buf ); - } else { -#if defined(Q_CC_MWERKS) - mac_default_handler(buf); -#elif defined(Q_OS_TEMP) - QString fstr( buf ); - OutputDebugString( (fstr + "\n").ucs2() ); -#else - fprintf( stderr, "%s\n", buf ); // add newline -#endif - } -} - - -// again, copied -void warning( const char *msg, ... ) -{ - char buf[QT_BUFFER_LENGTH]; - va_list ap; - va_start( ap, msg ); // use variable arg list -#if defined(QT_VSNPRINTF) - QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); + QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH, msg, ap ); #else - vsprintf( buf, msg, ap ); + vsprintf( &buf[len], msg, ap ); #endif va_end( ap ); if ( handler ) { @@ -571,46 +522,14 @@ void warning( const char *msg, ... ) void qFatal( const char *msg, ... ) { char buf[QT_BUFFER_LENGTH]; + strcpy( buf, QDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").ascii() ); + int len = strlen(buf); va_list ap; va_start( ap, msg ); // use variable arg list #if defined(QT_VSNPRINTF) - QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); -#else - vsprintf( buf, msg, ap ); -#endif - va_end( ap ); - if ( handler ) { - (*handler)( QtFatalMsg, buf ); - } else { -#if defined(Q_CC_MWERKS) - mac_default_handler(buf); -#else - fprintf( stderr, "%s\n", buf ); // add newline -#endif -#if defined(Q_OS_UNIX) && defined(QT_DEBUG) - abort(); // trap; generates core dump -#elif defined(Q_OS_TEMP) && defined(QT_DEBUG) - QString fstr; - fstr.sprintf( "%s:%s %s %s\n", __FILE__, __LINE__, QT_VERSION_STR, buf ); - OutputDebugString( fstr.ucs2() ); -#elif defined(_CRT_ERROR) && defined(_DEBUG) - _CrtDbgReport( _CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, buf ); -#else - exit( 1 ); // goodbye cruel world -#endif - } -} - -// yet again, copied -void fatal( const char *msg, ... ) -{ - char buf[QT_BUFFER_LENGTH]; - va_list ap; - va_start( ap, msg ); // use variable arg list -#if defined(QT_VSNPRINTF) - QT_VSNPRINTF( buf, QT_BUFFER_LENGTH, msg, ap ); + QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH, msg, ap ); #else - vsprintf( buf, msg, ap ); + vsprintf( &buf[len], msg, ap ); #endif va_end( ap ); if ( handler ) { |