]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: add log profile buildlines
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 31 Jan 2024 17:25:09 +0000 (18:25 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 13 Jun 2024 13:43:09 +0000 (15:43 +0200)
Now that we have log-profile parsing done, let's prepare for runtime
log-profile handling by adding the necessary string buffer required to
re-build log strings using sess_build_logline() on the fly without
altering regular loglines content.

Indeed, since a different log-profile may (or may not) be specified for
each logger, we must keep the original string and only rebuild a custom
one when required for the current logger (according to the selected log-
profile).

src/log.c

index eb6a4b4258a8696a08309b2ad02a04a8fdc11600..a2086454565984b945ef6977559ebd4876b928b1 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -339,11 +339,22 @@ unsigned int dropped_logs = 0;
  */
 THREAD_LOCAL char *logline = NULL;
 
+/* Same as logline, but to build profile-specific log message
+ * (when log profiles are used)
+ */
+THREAD_LOCAL char *logline_lpf = NULL;
+
+
 /* A global syslog message buffer, common to all RFC5424 syslog messages.
  * Currently, it is used for generating the structured-data part.
  */
 THREAD_LOCAL char *logline_rfc5424 = NULL;
 
+/* Same as logline_rfc5424, but to build profile-specific log message
+ * (when log profiles are used)
+ */
+THREAD_LOCAL char *logline_rfc5424_lpf = NULL;
+
 struct logformat_node_args {
        char *name;
        int mask;
@@ -3517,6 +3528,12 @@ int init_log_buffers()
        logline_rfc5424 = my_realloc2(logline_rfc5424, global.max_syslog_len + 1);
        if (!logline || !logline_rfc5424)
                return 0;
+       if (!LIST_ISEMPTY(&log_profile_list)) {
+               logline_lpf = my_realloc2(logline_lpf, global.max_syslog_len + 1);
+               logline_rfc5424_lpf = my_realloc2(logline_rfc5424_lpf, global.max_syslog_len + 1);
+               if (!logline_lpf || !logline_rfc5424_lpf)
+                       return 0;
+       }
        return 1;
 }
 
@@ -3524,9 +3541,13 @@ int init_log_buffers()
 void deinit_log_buffers()
 {
        free(logline);
+       free(logline_lpf);
        free(logline_rfc5424);
-       logline           = NULL;
-       logline_rfc5424   = NULL;
+       free(logline_rfc5424_lpf);
+       logline             = NULL;
+       logline_lpf         = NULL;
+       logline_rfc5424     = NULL;
+       logline_rfc5424_lpf = NULL;
 }
 
 /* Deinitialize log forwarder proxies used for syslog messages */