]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
cassandra: Fix logging messages with LFs
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 7 Dec 2020 13:58:00 +0000 (15:58 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 26 Jan 2021 09:06:15 +0000 (09:06 +0000)
At least some trace level messages had them.

src/lib-sql/driver-cassandra.c

index ea41d10865a98c0b42bc322bd23c4833fbc71c3a..65fcc22ccaeb7c96c7b4041e7129681a5e462041 100644 (file)
@@ -259,6 +259,24 @@ static void driver_cassandra_result_send_query(struct cassandra_result *result);
 static void driver_cassandra_send_queries(struct cassandra_db *db);
 static void result_finish(struct cassandra_result *result);
 
+static void log_one_line(const CassLogMessage *message,
+                        enum log_type log_type, const char *log_level_str,
+                        const char *text, size_t text_len)
+{
+       /* NOTE: We may not be in the main thread. We can't use the
+          standard Dovecot functions that may use data stack. That's why
+          we can't use i_log_type() in here, but have to re-implement the
+          internal logging protocol. Otherwise preserve Cassandra's own
+          logging format. */
+       fprintf(stderr, "\001%c%s %u.%03u %s(%s:%d:%s): %.*s\n",
+               log_type+1, my_pid,
+               (unsigned int)(message->time_ms / 1000),
+               (unsigned int)(message->time_ms % 1000),
+               log_level_str,
+               message->file, message->line, message->function,
+               (int)text_len, text);
+}
+
 static void
 driver_cassandra_log_handler(const CassLogMessage* message,
                             void *data ATTR_UNUSED)
@@ -290,18 +308,13 @@ driver_cassandra_log_handler(const CassLogMessage* message,
                break;
        }
 
-       /* NOTE: We may not be in the main thread. We can't use the
-          standard Dovecot functions that may use data stack. That's why
-          we can't use i_log_type() in here, but have to re-implement the
-          internal logging protocol. Otherwise preserve Cassandra's own
-          logging format. */
-       fprintf(stderr, "\001%c%s %u.%03u %s(%s:%d:%s): %s\n",
-               log_type+1, my_pid,
-               (unsigned int)(message->time_ms / 1000),
-               (unsigned int)(message->time_ms % 1000),
-               log_level_str,
-               message->file, message->line, message->function,
-               message->message);
+       /* Log message may contain LFs, so log each line separately. */
+       const char *p, *line = message->message;
+       while ((p = strchr(line, '\n')) != NULL) {
+               log_one_line(message, log_type, log_level_str, line, p - line);
+               line = p+1;
+       }
+       log_one_line(message, log_type, log_level_str, line, strlen(line));
 }
 
 static void driver_cassandra_init_log(void)