From bb4c595810ccd9b849be2d20f5c16d6076d083bb Mon Sep 17 00:00:00 2001 From: Xavier Roche Date: Mon, 13 May 2013 14:31:20 +0000 Subject: Introducing the hts_log_print() logging function * cleaned up logging --- src/htsparse.c | 573 ++++++++++++++------------------------------------------- 1 file changed, 135 insertions(+), 438 deletions(-) (limited to 'src/htsparse.c') diff --git a/src/htsparse.c b/src/htsparse.c index 41d1797..5a25d88 100644 --- a/src/htsparse.c +++ b/src/htsparse.c @@ -77,8 +77,6 @@ Please visit our Website: http://www.httrack.com #define relativeurlfil ((!parent_relative)?urlfil:parenturlfil) #define relativesavename ((!parent_relative)?savename:parentsavename) -#define test_flush if (opt->flush) { if (opt->log) { fflush(opt->log); } if (opt->log) { fflush(opt->log); } } - // does nothing #define XH_uninit do {} while(0) @@ -163,10 +161,7 @@ Please visit our Website: http://www.httrack.com mbuff[mlen]='\0';\ if ((mlen == 32) && (strcmp(((mbuff!=NULL)?mbuff:""),digest)==0)) {\ ok=1;\ - if ( (opt->debug>1) && (opt->log!=NULL) ) {\ - HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File not re-written (md5): %s"LF,savename);\ - test_flush;\ - }\ + hts_log_print(opt, LOG_DEBUG, "File not re-written (md5): %s",savename);\ } else {\ ok=0;\ } \ @@ -182,13 +177,10 @@ Please visit our Website: http://www.httrack.com opt->state.exit_xh=-1;\ }\ if (opt->log) { \ - int last_errno = errno; \ - HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Unable to write HTML file %s: %s"LF, savename, strerror(last_errno));\ + hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to write HTML file %s", savename);\ if (fcheck) {\ - HTS_LOG(opt,LOG_ERROR);\ - fprintf(opt->log,"* * Fatal write error, giving up"LF);\ + hts_log_print(opt, LOG_ERROR, "* * Fatal write error, giving up");\ }\ - test_flush;\ }\ }\ }\ @@ -198,19 +190,12 @@ Please visit our Website: http://www.httrack.com } else {\ int fcheck;\ if ((fcheck=check_fatal_io_errno())) {\ - HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Mirror aborted: disk full or filesystem problems"LF); \ - test_flush; \ + hts_log_print(opt, LOG_ERROR, "Mirror aborted: disk full or filesystem problems"); \ opt->state.exit_xh=-1;\ }\ - if (opt->log) { \ - int last_errno = errno; \ - HTS_LOG(opt,LOG_ERROR);\ - fprintf(opt->log,"Unable to save file %s : %s"LF, savename, strerror(last_errno));\ - if (fcheck) {\ - HTS_LOG(opt,LOG_ERROR);\ - fprintf(opt->log,"* * Fatal write error, giving up"LF);\ - }\ - test_flush;\ + hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to save file %s", savename);\ + if (fcheck) {\ + hts_log_print(opt, LOG_ERROR, "* * Fatal write error, giving up");\ }\ }\ } else {\ @@ -413,9 +398,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) { { char* cAddr = r->adr; int cSize = (int) r->size; - if ( (opt->debug>0) && (opt->log!=NULL) ) { - HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: preprocess-html: %s%s"LF, urladr, urlfil); - } + hts_log_print(opt, LOG_DEBUG, "engine: preprocess-html: %s%s", urladr, urlfil); if (RUN_CALLBACK4(opt, preprocess, &cAddr, &cSize, urladr, urlfil) == 1) { r->adr = cAddr; r->size = cSize; @@ -425,22 +408,15 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) { FILE* fp=NULL; // fichier écrit localement char* adr=r->adr; // pointeur (on parcourt) char* lastsaved; // adresse du dernier octet sauvé + 1 - if ( (opt->debug>1) && (opt->log!=NULL) ) { - HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"scanning file %s%s (%s).."LF, urladr, urlfil, savename); test_flush; - } - + hts_log_print(opt, LOG_DEBUG, "scanning file %s%s (%s)..", urladr, urlfil, savename); // Indexing! #if HTS_MAKE_KEYWORD_INDEX if (opt->kindex) { if (index_keyword(r->adr,r->size,r->contenttype,savename,StringBuff(opt->path_html_utf8))) { - if ( (opt->debug>1) && (opt->log!=NULL) ) { - HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"indexing file..done"LF); test_flush; - } + hts_log_print(opt, LOG_DEBUG, "indexing file..done"); } else { - if ( (opt->debug>1) && (opt->log!=NULL) ) { - HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"indexing file..error!"LF); test_flush; - } + hts_log_print(opt, LOG_DEBUG, "indexing file..error!"); } } #endif @@ -545,9 +521,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) { inscript_name="script"; intag=1; // because après