Fossil SCM
Condense each backoffice log entry into a single line.
Commit
e05a97aebe1b92d5249038956354812bdf3806947b3af86d62f7b7573d3b225d
Parent
5911f4b0c63c2ad…
1 file changed
+39
-25
+39
-25
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -136,18 +136,18 @@ | ||
| 136 | 136 | ** the "backoffice-logfile" setting is used instead. |
| 137 | 137 | */ |
| 138 | 138 | static const char *backofficeLogfile = 0; |
| 139 | 139 | |
| 140 | 140 | /* |
| 141 | -** Write backoffice log messages to this connection: | |
| 141 | +** Write the log message into this open file. | |
| 142 | 142 | */ |
| 143 | -static FILE *backofficeLog = 0; | |
| 143 | +static FILE *backofficeFILE = 0; | |
| 144 | 144 | |
| 145 | 145 | /* |
| 146 | -** Prefix for backoffice log messages | |
| 146 | +** Write backoffice log messages on this BLOB. to this connection: | |
| 147 | 147 | */ |
| 148 | -static char *backofficeLogPrefix = 0; | |
| 148 | +static Blob *backofficeBlob = 0; | |
| 149 | 149 | |
| 150 | 150 | /* End of state variables |
| 151 | 151 | ****************************************************************************/ |
| 152 | 152 | |
| 153 | 153 | /* |
| @@ -541,29 +541,34 @@ | ||
| 541 | 541 | /* |
| 542 | 542 | ** Append to a message to the backoffice log, if the log is open. |
| 543 | 543 | */ |
| 544 | 544 | void backoffice_log(const char *zFormat, ...){ |
| 545 | 545 | va_list ap; |
| 546 | - if( backofficeLog==0 ) return; | |
| 547 | - fprintf(backofficeLog, "%s ", backofficeLogPrefix); | |
| 546 | + if( backofficeBlob==0 ) return; | |
| 547 | + blob_append_char(backofficeBlob, ' '); | |
| 548 | 548 | va_start(ap, zFormat); |
| 549 | - vfprintf(backofficeLog, zFormat, ap); | |
| 550 | - fflush(backofficeLog); | |
| 549 | + blob_vappendf(backofficeBlob, zFormat, ap); | |
| 551 | 550 | va_end(ap); |
| 552 | 551 | } |
| 553 | 552 | |
| 554 | 553 | #if !defined(_WIN32) |
| 555 | 554 | /* |
| 556 | 555 | ** Capture routine for signals while running backoffice. |
| 557 | 556 | */ |
| 558 | 557 | static void backoffice_signal_handler(int sig){ |
| 559 | - const char *zSig = "(unk)"; | |
| 558 | + const char *zSig = 0; | |
| 560 | 559 | if( sig==SIGSEGV ) zSig = "SIGSEGV"; |
| 561 | 560 | if( sig==SIGFPE ) zSig = "SIGFPE"; |
| 562 | 561 | if( sig==SIGABRT ) zSig = "SIGABRT"; |
| 563 | 562 | if( sig==SIGILL ) zSig = "SIGILL"; |
| 564 | - backoffice_log("caught signal %d %s\n", sig, zSig); | |
| 563 | + if( zSig==0 ){ | |
| 564 | + backoffice_log("signal-%d", sig); | |
| 565 | + }else{ | |
| 566 | + backoffice_log("%s", zSig); | |
| 567 | + } | |
| 568 | + fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); | |
| 569 | + fflush(backofficeFILE); | |
| 565 | 570 | exit(1); |
| 566 | 571 | } |
| 567 | 572 | #endif |
| 568 | 573 | |
| 569 | 574 | #if !defined(_WIN32) |
| @@ -583,43 +588,48 @@ | ||
| 583 | 588 | void backoffice_work(void){ |
| 584 | 589 | /* Log the backoffice run for testing purposes. For production deployments |
| 585 | 590 | ** the "backoffice-logfile" property should be unset and the following code |
| 586 | 591 | ** should be a no-op. */ |
| 587 | 592 | const char *zLog = backofficeLogfile; |
| 588 | - int nAlert = 0; | |
| 589 | - int nSmtp = 0; | |
| 593 | + Blob log; | |
| 594 | + int nThis; | |
| 595 | + int nTotal = 0; | |
| 590 | 596 | #if !defined(_WIN32) |
| 591 | 597 | struct timeval sStart, sEnd; |
| 592 | 598 | #endif |
| 593 | 599 | if( zLog==0 ) zLog = db_get("backoffice-logfile",0); |
| 594 | - if( zLog && zLog[0] ){ | |
| 595 | - backofficeLog = fossil_fopen(zLog, "a"); | |
| 596 | - backofficeLogPrefix = mprintf("%d %s", | |
| 597 | - GETPID(), db_get("project-name","???")); | |
| 598 | - backoffice_log("start %s\n", db_text(0, "SELECT datetime('now');")); | |
| 600 | + if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){ | |
| 601 | + int i; | |
| 602 | + char *zName = db_get("project-name",""); | |
| 599 | 603 | #if !defined(_WIN32) |
| 600 | 604 | gettimeofday(&sStart, 0); |
| 601 | 605 | signal(SIGSEGV, backoffice_signal_handler); |
| 602 | 606 | signal(SIGABRT, backoffice_signal_handler); |
| 603 | 607 | signal(SIGFPE, backoffice_signal_handler); |
| 604 | 608 | signal(SIGILL, backoffice_signal_handler); |
| 605 | 609 | #endif |
| 610 | + /* Convert all spaces in the "project-name" into dashes */ | |
| 611 | + for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; } | |
| 612 | + blob_init(&log, 0, 0); | |
| 613 | + backofficeBlob = &log; | |
| 614 | + blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName); | |
| 606 | 615 | } |
| 607 | 616 | |
| 608 | 617 | /* Here is where the actual work of the backoffice happens */ |
| 609 | - nAlert = alert_backoffice(0); | |
| 610 | - if( nAlert ) backoffice_log("%d alerts sent\n", nAlert); | |
| 611 | - nSmtp = smtp_cleanup(); | |
| 612 | - if( nSmtp ) backoffice_log("%d SMTP cleanup ops\n", nSmtp); | |
| 618 | + nTotal += nThis = alert_backoffice(0); | |
| 619 | + if( nThis ) backoffice_log("%d alerts", nThis); | |
| 620 | + nTotal += nThis = smtp_cleanup(); | |
| 621 | + if( nThis ) backoffice_log("%d SMTPs", nThis); | |
| 613 | 622 | |
| 614 | 623 | /* Close the log */ |
| 615 | - if( backofficeLog ){ | |
| 624 | + if( backofficeFILE ){ | |
| 625 | + if( nTotal==0 ) backoffice_log("no-op"); | |
| 616 | 626 | #if !defined(_WIN32) |
| 617 | 627 | gettimeofday(&sEnd,0); |
| 618 | - backoffice_log("elapse time %d us\n", tvms(&sEnd) - tvms(&sStart)); | |
| 628 | + backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart)); | |
| 619 | 629 | #endif |
| 620 | - fclose(backofficeLog); | |
| 630 | + fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); | |
| 621 | 631 | } |
| 622 | 632 | } |
| 623 | 633 | |
| 624 | 634 | /* |
| 625 | 635 | ** COMMAND: backoffice* |
| @@ -732,11 +742,15 @@ | ||
| 732 | 742 | if( g.argc==3 ){ |
| 733 | 743 | g.zRepositoryOption = g.argv[2]; |
| 734 | 744 | g.argc--; |
| 735 | 745 | } |
| 736 | 746 | db_find_and_open_repository(0,0); |
| 737 | - backoffice_thread(); | |
| 747 | + if( bDebug ){ | |
| 748 | + backoffice_work(); | |
| 749 | + }else{ | |
| 750 | + backoffice_thread(); | |
| 751 | + } | |
| 738 | 752 | } |
| 739 | 753 | } |
| 740 | 754 | |
| 741 | 755 | /* |
| 742 | 756 | ** This is the main interface to backoffice from the rest of the system. |
| 743 | 757 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -136,18 +136,18 @@ | |
| 136 | ** the "backoffice-logfile" setting is used instead. |
| 137 | */ |
| 138 | static const char *backofficeLogfile = 0; |
| 139 | |
| 140 | /* |
| 141 | ** Write backoffice log messages to this connection: |
| 142 | */ |
| 143 | static FILE *backofficeLog = 0; |
| 144 | |
| 145 | /* |
| 146 | ** Prefix for backoffice log messages |
| 147 | */ |
| 148 | static char *backofficeLogPrefix = 0; |
| 149 | |
| 150 | /* End of state variables |
| 151 | ****************************************************************************/ |
| 152 | |
| 153 | /* |
| @@ -541,29 +541,34 @@ | |
| 541 | /* |
| 542 | ** Append to a message to the backoffice log, if the log is open. |
| 543 | */ |
| 544 | void backoffice_log(const char *zFormat, ...){ |
| 545 | va_list ap; |
| 546 | if( backofficeLog==0 ) return; |
| 547 | fprintf(backofficeLog, "%s ", backofficeLogPrefix); |
| 548 | va_start(ap, zFormat); |
| 549 | vfprintf(backofficeLog, zFormat, ap); |
| 550 | fflush(backofficeLog); |
| 551 | va_end(ap); |
| 552 | } |
| 553 | |
| 554 | #if !defined(_WIN32) |
| 555 | /* |
| 556 | ** Capture routine for signals while running backoffice. |
| 557 | */ |
| 558 | static void backoffice_signal_handler(int sig){ |
| 559 | const char *zSig = "(unk)"; |
| 560 | if( sig==SIGSEGV ) zSig = "SIGSEGV"; |
| 561 | if( sig==SIGFPE ) zSig = "SIGFPE"; |
| 562 | if( sig==SIGABRT ) zSig = "SIGABRT"; |
| 563 | if( sig==SIGILL ) zSig = "SIGILL"; |
| 564 | backoffice_log("caught signal %d %s\n", sig, zSig); |
| 565 | exit(1); |
| 566 | } |
| 567 | #endif |
| 568 | |
| 569 | #if !defined(_WIN32) |
| @@ -583,43 +588,48 @@ | |
| 583 | void backoffice_work(void){ |
| 584 | /* Log the backoffice run for testing purposes. For production deployments |
| 585 | ** the "backoffice-logfile" property should be unset and the following code |
| 586 | ** should be a no-op. */ |
| 587 | const char *zLog = backofficeLogfile; |
| 588 | int nAlert = 0; |
| 589 | int nSmtp = 0; |
| 590 | #if !defined(_WIN32) |
| 591 | struct timeval sStart, sEnd; |
| 592 | #endif |
| 593 | if( zLog==0 ) zLog = db_get("backoffice-logfile",0); |
| 594 | if( zLog && zLog[0] ){ |
| 595 | backofficeLog = fossil_fopen(zLog, "a"); |
| 596 | backofficeLogPrefix = mprintf("%d %s", |
| 597 | GETPID(), db_get("project-name","???")); |
| 598 | backoffice_log("start %s\n", db_text(0, "SELECT datetime('now');")); |
| 599 | #if !defined(_WIN32) |
| 600 | gettimeofday(&sStart, 0); |
| 601 | signal(SIGSEGV, backoffice_signal_handler); |
| 602 | signal(SIGABRT, backoffice_signal_handler); |
| 603 | signal(SIGFPE, backoffice_signal_handler); |
| 604 | signal(SIGILL, backoffice_signal_handler); |
| 605 | #endif |
| 606 | } |
| 607 | |
| 608 | /* Here is where the actual work of the backoffice happens */ |
| 609 | nAlert = alert_backoffice(0); |
| 610 | if( nAlert ) backoffice_log("%d alerts sent\n", nAlert); |
| 611 | nSmtp = smtp_cleanup(); |
| 612 | if( nSmtp ) backoffice_log("%d SMTP cleanup ops\n", nSmtp); |
| 613 | |
| 614 | /* Close the log */ |
| 615 | if( backofficeLog ){ |
| 616 | #if !defined(_WIN32) |
| 617 | gettimeofday(&sEnd,0); |
| 618 | backoffice_log("elapse time %d us\n", tvms(&sEnd) - tvms(&sStart)); |
| 619 | #endif |
| 620 | fclose(backofficeLog); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | ** COMMAND: backoffice* |
| @@ -732,11 +742,15 @@ | |
| 732 | if( g.argc==3 ){ |
| 733 | g.zRepositoryOption = g.argv[2]; |
| 734 | g.argc--; |
| 735 | } |
| 736 | db_find_and_open_repository(0,0); |
| 737 | backoffice_thread(); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | ** This is the main interface to backoffice from the rest of the system. |
| 743 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -136,18 +136,18 @@ | |
| 136 | ** the "backoffice-logfile" setting is used instead. |
| 137 | */ |
| 138 | static const char *backofficeLogfile = 0; |
| 139 | |
| 140 | /* |
| 141 | ** Write the log message into this open file. |
| 142 | */ |
| 143 | static FILE *backofficeFILE = 0; |
| 144 | |
| 145 | /* |
| 146 | ** Write backoffice log messages on this BLOB. to this connection: |
| 147 | */ |
| 148 | static Blob *backofficeBlob = 0; |
| 149 | |
| 150 | /* End of state variables |
| 151 | ****************************************************************************/ |
| 152 | |
| 153 | /* |
| @@ -541,29 +541,34 @@ | |
| 541 | /* |
| 542 | ** Append to a message to the backoffice log, if the log is open. |
| 543 | */ |
| 544 | void backoffice_log(const char *zFormat, ...){ |
| 545 | va_list ap; |
| 546 | if( backofficeBlob==0 ) return; |
| 547 | blob_append_char(backofficeBlob, ' '); |
| 548 | va_start(ap, zFormat); |
| 549 | blob_vappendf(backofficeBlob, zFormat, ap); |
| 550 | va_end(ap); |
| 551 | } |
| 552 | |
| 553 | #if !defined(_WIN32) |
| 554 | /* |
| 555 | ** Capture routine for signals while running backoffice. |
| 556 | */ |
| 557 | static void backoffice_signal_handler(int sig){ |
| 558 | const char *zSig = 0; |
| 559 | if( sig==SIGSEGV ) zSig = "SIGSEGV"; |
| 560 | if( sig==SIGFPE ) zSig = "SIGFPE"; |
| 561 | if( sig==SIGABRT ) zSig = "SIGABRT"; |
| 562 | if( sig==SIGILL ) zSig = "SIGILL"; |
| 563 | if( zSig==0 ){ |
| 564 | backoffice_log("signal-%d", sig); |
| 565 | }else{ |
| 566 | backoffice_log("%s", zSig); |
| 567 | } |
| 568 | fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); |
| 569 | fflush(backofficeFILE); |
| 570 | exit(1); |
| 571 | } |
| 572 | #endif |
| 573 | |
| 574 | #if !defined(_WIN32) |
| @@ -583,43 +588,48 @@ | |
| 588 | void backoffice_work(void){ |
| 589 | /* Log the backoffice run for testing purposes. For production deployments |
| 590 | ** the "backoffice-logfile" property should be unset and the following code |
| 591 | ** should be a no-op. */ |
| 592 | const char *zLog = backofficeLogfile; |
| 593 | Blob log; |
| 594 | int nThis; |
| 595 | int nTotal = 0; |
| 596 | #if !defined(_WIN32) |
| 597 | struct timeval sStart, sEnd; |
| 598 | #endif |
| 599 | if( zLog==0 ) zLog = db_get("backoffice-logfile",0); |
| 600 | if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){ |
| 601 | int i; |
| 602 | char *zName = db_get("project-name",""); |
| 603 | #if !defined(_WIN32) |
| 604 | gettimeofday(&sStart, 0); |
| 605 | signal(SIGSEGV, backoffice_signal_handler); |
| 606 | signal(SIGABRT, backoffice_signal_handler); |
| 607 | signal(SIGFPE, backoffice_signal_handler); |
| 608 | signal(SIGILL, backoffice_signal_handler); |
| 609 | #endif |
| 610 | /* Convert all spaces in the "project-name" into dashes */ |
| 611 | for(i=0; zName[i]; i++){ if( zName[i]==' ' ) zName[i] = '-'; } |
| 612 | blob_init(&log, 0, 0); |
| 613 | backofficeBlob = &log; |
| 614 | blob_appendf(&log, "%s %s", db_text(0, "SELECT datetime('now')"), zName); |
| 615 | } |
| 616 | |
| 617 | /* Here is where the actual work of the backoffice happens */ |
| 618 | nTotal += nThis = alert_backoffice(0); |
| 619 | if( nThis ) backoffice_log("%d alerts", nThis); |
| 620 | nTotal += nThis = smtp_cleanup(); |
| 621 | if( nThis ) backoffice_log("%d SMTPs", nThis); |
| 622 | |
| 623 | /* Close the log */ |
| 624 | if( backofficeFILE ){ |
| 625 | if( nTotal==0 ) backoffice_log("no-op"); |
| 626 | #if !defined(_WIN32) |
| 627 | gettimeofday(&sEnd,0); |
| 628 | backoffice_log("elapse-time %d us", tvms(&sEnd) - tvms(&sStart)); |
| 629 | #endif |
| 630 | fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob)); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /* |
| 635 | ** COMMAND: backoffice* |
| @@ -732,11 +742,15 @@ | |
| 742 | if( g.argc==3 ){ |
| 743 | g.zRepositoryOption = g.argv[2]; |
| 744 | g.argc--; |
| 745 | } |
| 746 | db_find_and_open_repository(0,0); |
| 747 | if( bDebug ){ |
| 748 | backoffice_work(); |
| 749 | }else{ |
| 750 | backoffice_thread(); |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | ** This is the main interface to backoffice from the rest of the system. |
| 757 |