]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: provide a function to emit a log for a session
authorWilly Tarreau <w@1wt.eu>
Wed, 5 Sep 2018 17:51:10 +0000 (19:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 6 Sep 2018 07:43:41 +0000 (09:43 +0200)
The new function sess_log() only needs a session to emit a log. It will
ignore the parts that depend on the stream. It is usable to emit a log
to report early errors in muxes. These ones will typically mention
"<BADREQ>" for the request and 0 for the HTTP status code.

include/proto/log.h
src/log.c

index 419e0b31bb38ff89b7944e8ac76fffcd92b67369..7fb1f04df89bc3f3e5143ae230ae8055b11ba2da 100644 (file)
@@ -78,6 +78,7 @@ static inline int build_logline(struct stream *s, char *dst, size_t maxsize, str
  * Will not log if the frontend has no log defined.
  */
 void strm_log(struct stream *s);
+void sess_log(struct session *sess);
 
 /*
  * add to the logformat linked list
index 8e1453044ac995fc7c73ab7fb223e2c12db4ceb7..3bd22858337facb56f39363791a07cb4515ee11b 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2620,6 +2620,39 @@ void strm_log(struct stream *s)
        }
 }
 
+/*
+ * send a minimalist log for the session. Will not log if the frontend has no
+ * log defined. It is assumed that this is only used to report anomalies that
+ * cannot lead to the creation of a regular stream. Because of this the log
+ * level is LOG_INFO or LOG_ERR depending on the "log-separate-error" setting
+ * in the frontend. The caller must simply know that it should not call this
+ * function to report unimportant events.
+ */
+void sess_log(struct session *sess)
+{
+       int size, level;
+       int sd_size = 0;
+
+       if (LIST_ISEMPTY(&sess->fe->logsrvs))
+               return;
+
+       level = LOG_INFO;
+       if (sess->fe->options2 & PR_O2_LOGERRORS)
+               level = LOG_ERR;
+
+       if (!LIST_ISEMPTY(&sess->fe->logformat_sd)) {
+               sd_size = sess_build_logline(sess, NULL,
+                                            logline_rfc5424, global.max_syslog_len,
+                                            &sess->fe->logformat_sd);
+       }
+
+       size = sess_build_logline(sess, NULL, logline, global.max_syslog_len, &sess->fe->logformat);
+       if (size > 0) {
+               HA_ATOMIC_ADD(&sess->fe->log_count, 1);
+               __send_log(sess->fe, level, logline, size + 1, logline_rfc5424, sd_size);
+       }
+}
+
 static int cli_io_handler_show_startup_logs(struct appctx *appctx)
 {
        struct stream_interface *si = appctx->owner;