Fossil SCM

Condense each backoffice log entry into a single line.

drh 2020-07-01 21:12 trunk
Commit e05a97aebe1b92d5249038956354812bdf3806947b3af86d62f7b7573d3b225d
1 file changed +39 -25
+39 -25
--- src/backoffice.c
+++ src/backoffice.c
@@ -136,18 +136,18 @@
136136
** the "backoffice-logfile" setting is used instead.
137137
*/
138138
static const char *backofficeLogfile = 0;
139139
140140
/*
141
-** Write backoffice log messages to this connection:
141
+** Write the log message into this open file.
142142
*/
143
-static FILE *backofficeLog = 0;
143
+static FILE *backofficeFILE = 0;
144144
145145
/*
146
-** Prefix for backoffice log messages
146
+** Write backoffice log messages on this BLOB. to this connection:
147147
*/
148
-static char *backofficeLogPrefix = 0;
148
+static Blob *backofficeBlob = 0;
149149
150150
/* End of state variables
151151
****************************************************************************/
152152
153153
/*
@@ -541,29 +541,34 @@
541541
/*
542542
** Append to a message to the backoffice log, if the log is open.
543543
*/
544544
void backoffice_log(const char *zFormat, ...){
545545
va_list ap;
546
- if( backofficeLog==0 ) return;
547
- fprintf(backofficeLog, "%s ", backofficeLogPrefix);
546
+ if( backofficeBlob==0 ) return;
547
+ blob_append_char(backofficeBlob, ' ');
548548
va_start(ap, zFormat);
549
- vfprintf(backofficeLog, zFormat, ap);
550
- fflush(backofficeLog);
549
+ blob_vappendf(backofficeBlob, zFormat, ap);
551550
va_end(ap);
552551
}
553552
554553
#if !defined(_WIN32)
555554
/*
556555
** Capture routine for signals while running backoffice.
557556
*/
558557
static void backoffice_signal_handler(int sig){
559
- const char *zSig = "(unk)";
558
+ const char *zSig = 0;
560559
if( sig==SIGSEGV ) zSig = "SIGSEGV";
561560
if( sig==SIGFPE ) zSig = "SIGFPE";
562561
if( sig==SIGABRT ) zSig = "SIGABRT";
563562
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);
565570
exit(1);
566571
}
567572
#endif
568573
569574
#if !defined(_WIN32)
@@ -583,43 +588,48 @@
583588
void backoffice_work(void){
584589
/* Log the backoffice run for testing purposes. For production deployments
585590
** the "backoffice-logfile" property should be unset and the following code
586591
** should be a no-op. */
587592
const char *zLog = backofficeLogfile;
588
- int nAlert = 0;
589
- int nSmtp = 0;
593
+ Blob log;
594
+ int nThis;
595
+ int nTotal = 0;
590596
#if !defined(_WIN32)
591597
struct timeval sStart, sEnd;
592598
#endif
593599
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","");
599603
#if !defined(_WIN32)
600604
gettimeofday(&sStart, 0);
601605
signal(SIGSEGV, backoffice_signal_handler);
602606
signal(SIGABRT, backoffice_signal_handler);
603607
signal(SIGFPE, backoffice_signal_handler);
604608
signal(SIGILL, backoffice_signal_handler);
605609
#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);
606615
}
607616
608617
/* 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);
613622
614623
/* Close the log */
615
- if( backofficeLog ){
624
+ if( backofficeFILE ){
625
+ if( nTotal==0 ) backoffice_log("no-op");
616626
#if !defined(_WIN32)
617627
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));
619629
#endif
620
- fclose(backofficeLog);
630
+ fprintf(backofficeFILE, "%s\n", blob_str(backofficeBlob));
621631
}
622632
}
623633
624634
/*
625635
** COMMAND: backoffice*
@@ -732,11 +742,15 @@
732742
if( g.argc==3 ){
733743
g.zRepositoryOption = g.argv[2];
734744
g.argc--;
735745
}
736746
db_find_and_open_repository(0,0);
737
- backoffice_thread();
747
+ if( bDebug ){
748
+ backoffice_work();
749
+ }else{
750
+ backoffice_thread();
751
+ }
738752
}
739753
}
740754
741755
/*
742756
** This is the main interface to backoffice from the rest of the system.
743757
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button