From 81086b76be9ab3dd1cb1653918fc649dae91181f Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Thu, 14 Apr 2022 13:18:51 -0400 Subject: [PATCH] journald: print tag and name if both are specified Signed-off-by: Peter Hunt --- src/ctr_logging.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ctr_logging.c b/src/ctr_logging.c index ad97bced..16a907f3 100644 --- a/src/ctr_logging.c +++ b/src/ctr_logging.c @@ -132,22 +132,23 @@ void configure_log_drivers(gchar **log_drivers, int64_t log_size_max_, char *cuu /* Setup some sd_journal_sendv arguments that won't change */ container_id_full = g_strdup_printf("CONTAINER_ID_FULL=%s", cuuid); container_id = g_strdup_printf("CONTAINER_ID=%s", short_cuuid); - if (tag) { - container_tag = g_strdup_printf("CONTAINER_TAG=%s", tag); - container_tag_len = strlen(container_tag); - syslog_identifier = g_strdup_printf("SYSLOG_IDENTIFIER=%s", tag); - syslog_identifier_len = strlen(syslog_identifier); - } else if (name) { - /* save the length so we don't have to compute every sd_journal_* call */ + /* Priority order of syslog_identifier (in order of precedence) is tag, name, `conmon`. */ + syslog_identifier = g_strdup_printf("SYSLOG_IDENTIFIER=%s", short_cuuid); + syslog_identifier_len = TRUNC_ID_LEN + SYSLOG_IDENTIFIER_EQ_LEN; + if (name) { name_len = strlen(name); container_name = g_strdup_printf("CONTAINER_NAME=%s", name); syslog_identifier = g_strdup_printf("SYSLOG_IDENTIFIER=%s", name); syslog_identifier_len = name_len + SYSLOG_IDENTIFIER_EQ_LEN; - } else { - syslog_identifier = g_strdup_printf("SYSLOG_IDENTIFIER=%s", short_cuuid); - syslog_identifier_len = TRUNC_ID_LEN + SYSLOG_IDENTIFIER_EQ_LEN; + } + if (tag) { + container_tag = g_strdup_printf("CONTAINER_TAG=%s", tag); + container_tag_len = strlen(container_tag); + + syslog_identifier = g_strdup_printf("SYSLOG_IDENTIFIER=%s", tag); + syslog_identifier_len = strlen(syslog_identifier); } } }