From dab5885b02a167db38641bc08644bd87dd18d39b Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 15 May 2022 12:41:24 +0800 Subject: [PATCH] opt: debug log message convert GDPRINTF macro to gdDebug internal --- gddebug.cc | 24 ++++++++++++------------ gddebug.hh | 2 +- mdictparser.cc | 2 +- mdx.cc | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/gddebug.cc b/gddebug.cc index 157ff5c4..a295c93b 100644 --- a/gddebug.cc +++ b/gddebug.cc @@ -42,23 +42,23 @@ void gdDebug(const char *msg, ...) { va_list ap; va_start(ap, msg); -QTextCodec *localeCodec = 0; +// QTextCodec *localeCodec = 0; - if( logFilePtr && logFilePtr->isOpen() ) - { - if( utf8Codec == 0 ) - utf8Codec = QTextCodec::codecForName( "UTF8" ); + // if( logFilePtr && logFilePtr->isOpen() ) + // { + // if( utf8Codec == 0 ) + // utf8Codec = QTextCodec::codecForName( "UTF8" ); - localeCodec = QTextCodec::codecForLocale(); - QTextCodec::setCodecForLocale( utf8Codec ); - } + // localeCodec = QTextCodec::codecForLocale(); + // QTextCodec::setCodecForLocale( utf8Codec ); + // } qDebug()<< QString().vasprintf( msg, ap ); - if( logFilePtr && logFilePtr->isOpen() ) - { - QTextCodec::setCodecForLocale( localeCodec ); - } + // if( logFilePtr && logFilePtr->isOpen() ) + // { + // QTextCodec::setCodecForLocale( localeCodec ); + // } va_end(ap); } diff --git a/gddebug.hh b/gddebug.hh index e8148e0d..5e1dfe26 100644 --- a/gddebug.hh +++ b/gddebug.hh @@ -7,7 +7,7 @@ #define GD_DPRINTF(...) do {} while( 0 ) #define GD_FDPRINTF(...) do {} while( 0 ) #else -#define GD_DPRINTF(...) printf(__VA_ARGS__) +#define GD_DPRINTF(...) gdDebug(__VA_ARGS__) #define GD_FDPRINTF(...) fprintf(__VA_ARGS__) #endif diff --git a/mdictparser.cc b/mdictparser.cc index d2366f7a..f3124a46 100644 --- a/mdictparser.cc +++ b/mdictparser.cc @@ -120,7 +120,7 @@ bool MdictParser::open( const char * filename ) filename_ = QString::fromUtf8( filename ); file_ = new QFile( filename_ ); - GD_DPRINTF( "MdictParser: open %s\n", filename ); + gdDebug( "MdictParser: open %s", filename ); if ( file_.isNull() || !file_->exists() ) return false; diff --git a/mdx.cc b/mdx.cc index 69271c86..b19558f5 100644 --- a/mdx.cc +++ b/mdx.cc @@ -523,7 +523,7 @@ void MdxDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration if( firstIteration && getArticleCount() > FTS::MaxDictionarySizeForFastSearch ) return; - gdDebug( "MDict: Building the full-text index for dictionary: %s\n", + gdDebug( "MDict: Building the full-text index for dictionary: %s", getName().c_str() ); try @@ -533,7 +533,7 @@ void MdxDictionary::makeFTSIndex( QAtomicInt & isCancelled, bool firstIteration } catch( std::exception &ex ) { - gdWarning( "MDict: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() ); + gdWarning( "MDict: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); QFile::remove( FsEncoding::decode( ftsIdxName.c_str() ) ); } } @@ -550,7 +550,7 @@ void MdxDictionary::getArticleText( uint32_t articleAddress, QString & headword, } catch( std::exception &ex ) { - gdWarning( "MDict: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() ); + gdWarning( "MDict: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); } }