]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: Add "show startup-logs" command
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 24 Oct 2017 10:00:51 +0000 (12:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 10:36:13 +0000 (11:36 +0100)
This command will dump all startup_logs buffer containing all alerts and
warnings emitted during HAProxy startup.

src/log.c

index ff1ab9a8163e9350304ee222c45a040daf9be3a5..0d6e7fd33fcf0dcfc249e456f20bbf46aba3be23 100644 (file)
--- a/src/log.c
+++ b/src/log.c
 #include <common/standard.h>
 #include <common/time.h>
 
+#include <types/cli.h>
 #include <types/global.h>
 #include <types/log.h>
 
+#include <proto/applet.h>
+#include <proto/cli.h>
 #include <proto/frontend.h>
 #include <proto/proto_http.h>
 #include <proto/log.h>
@@ -2380,6 +2383,31 @@ void strm_log(struct stream *s)
        }
 }
 
+static int cli_io_handler_show_startup_logs(struct appctx *appctx)
+{
+       struct stream_interface *si = appctx->owner;
+       const char *msg = (startup_logs ? startup_logs : "No startup alerts/warnings.\n");
+
+       if (ci_putstr(si_ic(si), msg) == -1) {
+               si_applet_cant_put(si);
+               return 0;
+       }
+       return 1;
+}
+
+/* register cli keywords */
+static struct cli_kw_list cli_kws = {{ },{
+       { { "show", "startup-logs",  NULL },
+         "show startup-logs : report logs emitted during HAProxy startup",
+         NULL, cli_io_handler_show_startup_logs },
+       {{},}
+}};
+
+__attribute__((constructor))
+static void __log_init(void)
+{
+       cli_register_kw(&cli_kws);
+}
 /*
  * Local variables:
  *  c-indent-level: 8