Re: reduce debug logging from slowcgi

2021-08-31 Thread Florian Obser
OK florian

On 2021-08-31 16:24 +02, Paul de Weerd  wrote:
> Hi all,
>
> On a busy-ish site, I found that slowcgi is doing quite excessive
> logging: every single environment variable is logged on a separate
> logline.  There's at least 17 variables per hit, but I've seen it go
> up to 35.  If you're writing debug logs from syslog, that adds up
> rather quickly.  Of course you can argue "don't do that", but why have
> the system do all this work of sending stuff through syslog when
> you're not going to anything with it anyway?
>
> Anyway, after a hint from Florian, I added a -v flag to slowcgi to
> only log syslog events at the DEBUG level when it's given and not
> always / by default.  It's good to be able to log these when you're
> debugging issues, but then you'll have to add '-v' to the
> slowcgi_flags in /etc/rc.conf.local using rcctl(8).
>
> I've tested this on that busy-ish setup - works for me (tm).
>
> Cheers,
>
> Paul 'WEiRD' de Weerd
>
> Index: slowcgi.8
> ===
> RCS file: /home/OpenBSD/cvs/src/usr.sbin/slowcgi/slowcgi.8,v
> retrieving revision 1.14
> diff -u -p -r1.14 slowcgi.8
> --- slowcgi.8 13 Aug 2018 16:54:50 -  1.14
> +++ slowcgi.8 31 Aug 2021 13:10:42 -
> @@ -27,6 +27,7 @@
>  .Op Fl s Ar socket
>  .Op Fl U Ar user
>  .Op Fl u Ar user
> +.Op Fl v
>  .Sh DESCRIPTION
>  .Nm
>  is a server which implements the FastCGI Protocol to execute CGI scripts.
> @@ -90,6 +91,8 @@ instead of default user www and
>  to
>  the home directory of
>  .Ar user .
> +.It Fl v
> +Enable more verbose (debug) logging.
>  .El
>  .Sh SEE ALSO
>  .Xr httpd 8
> Index: slowcgi.c
> ===
> RCS file: /home/OpenBSD/cvs/src/usr.sbin/slowcgi/slowcgi.c,v
> retrieving revision 1.60
> diff -u -p -r1.60 slowcgi.c
> --- slowcgi.c 20 Apr 2021 07:35:42 -  1.60
> +++ slowcgi.c 31 Aug 2021 13:08:37 -
> @@ -260,6 +260,7 @@ usage(void)
>  struct timeval   timeout = { TIMEOUT_DEFAULT, 0 };
>  struct slowcgi_proc  slowcgi_proc;
>  int  debug = 0;
> +int  verbose = 0;
>  int  on = 1;
>  char *fcgi_socket = "/var/www/run/slowcgi.sock";
>  
> @@ -292,7 +293,7 @@ main(int argc, char *argv[])
>   }
>   }
>  
> - while ((c = getopt(argc, argv, "dp:s:U:u:")) != -1) {
> + while ((c = getopt(argc, argv, "dp:s:U:u:v")) != -1) {
>   switch (c) {
>   case 'd':
>   debug++;
> @@ -309,6 +310,9 @@ main(int argc, char *argv[])
>   case 'u':
>   slowcgi_user = optarg;
>   break;
> + case 'v':
> + verbose++;
> + break;
>   default:
>   usage();
>   /* NOTREACHED */
> @@ -1261,9 +1265,10 @@ syslog_info(const char *fmt, ...)
>  void
>  syslog_debug(const char *fmt, ...)
>  {
> - va_list ap;
> -
> - va_start(ap, fmt);
> - vsyslog(LOG_DEBUG, fmt, ap);
> - va_end(ap);
> + if (verbose > 0) {
> + va_list ap;
> + va_start(ap, fmt);
> + vsyslog(LOG_DEBUG, fmt, ap);
> + va_end(ap);
> + }
>  }
>
>
> -- 
>>[<++>-]<+++.>+++[<-->-]<.>+++[<+
> +++>-]<.>++[<>-]<+.--.[-]
>  http://www.weirdnet.nl/ 
>

-- 
I'm not entirely sure you are real.



reduce debug logging from slowcgi

2021-08-31 Thread Paul de Weerd
Hi all,

On a busy-ish site, I found that slowcgi is doing quite excessive
logging: every single environment variable is logged on a separate
logline.  There's at least 17 variables per hit, but I've seen it go
up to 35.  If you're writing debug logs from syslog, that adds up
rather quickly.  Of course you can argue "don't do that", but why have
the system do all this work of sending stuff through syslog when
you're not going to anything with it anyway?

Anyway, after a hint from Florian, I added a -v flag to slowcgi to
only log syslog events at the DEBUG level when it's given and not
always / by default.  It's good to be able to log these when you're
debugging issues, but then you'll have to add '-v' to the
slowcgi_flags in /etc/rc.conf.local using rcctl(8).

I've tested this on that busy-ish setup - works for me (tm).

Cheers,

Paul 'WEiRD' de Weerd

Index: slowcgi.8
===
RCS file: /home/OpenBSD/cvs/src/usr.sbin/slowcgi/slowcgi.8,v
retrieving revision 1.14
diff -u -p -r1.14 slowcgi.8
--- slowcgi.8   13 Aug 2018 16:54:50 -  1.14
+++ slowcgi.8   31 Aug 2021 13:10:42 -
@@ -27,6 +27,7 @@
 .Op Fl s Ar socket
 .Op Fl U Ar user
 .Op Fl u Ar user
+.Op Fl v
 .Sh DESCRIPTION
 .Nm
 is a server which implements the FastCGI Protocol to execute CGI scripts.
@@ -90,6 +91,8 @@ instead of default user www and
 to
 the home directory of
 .Ar user .
+.It Fl v
+Enable more verbose (debug) logging.
 .El
 .Sh SEE ALSO
 .Xr httpd 8
Index: slowcgi.c
===
RCS file: /home/OpenBSD/cvs/src/usr.sbin/slowcgi/slowcgi.c,v
retrieving revision 1.60
diff -u -p -r1.60 slowcgi.c
--- slowcgi.c   20 Apr 2021 07:35:42 -  1.60
+++ slowcgi.c   31 Aug 2021 13:08:37 -
@@ -260,6 +260,7 @@ usage(void)
 struct timeval timeout = { TIMEOUT_DEFAULT, 0 };
 struct slowcgi_procslowcgi_proc;
 intdebug = 0;
+intverbose = 0;
 inton = 1;
 char   *fcgi_socket = "/var/www/run/slowcgi.sock";
 
@@ -292,7 +293,7 @@ main(int argc, char *argv[])
}
}
 
-   while ((c = getopt(argc, argv, "dp:s:U:u:")) != -1) {
+   while ((c = getopt(argc, argv, "dp:s:U:u:v")) != -1) {
switch (c) {
case 'd':
debug++;
@@ -309,6 +310,9 @@ main(int argc, char *argv[])
case 'u':
slowcgi_user = optarg;
break;
+   case 'v':
+   verbose++;
+   break;
default:
usage();
/* NOTREACHED */
@@ -1261,9 +1265,10 @@ syslog_info(const char *fmt, ...)
 void
 syslog_debug(const char *fmt, ...)
 {
-   va_list ap;
-
-   va_start(ap, fmt);
-   vsyslog(LOG_DEBUG, fmt, ap);
-   va_end(ap);
+   if (verbose > 0) {
+   va_list ap;
+   va_start(ap, fmt);
+   vsyslog(LOG_DEBUG, fmt, ap);
+   va_end(ap);
+   }
 }


-- 
>[<++>-]<+++.>+++[<-->-]<.>+++[<+
+++>-]<.>++[<>-]<+.--.[-]
 http://www.weirdnet.nl/