From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8061C459C0; Tue, 17 Sep 2024 22:42:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B3ACC42D66; Tue, 17 Sep 2024 22:42:05 +0200 (CEST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTP id E884D427A9 for ; Tue, 17 Sep 2024 22:41:56 +0200 (CEST) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2053a0bd0a6so63661715ad.3 for ; Tue, 17 Sep 2024 13:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726605716; x=1727210516; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nFxxNCUyFtMM5wcqjcLlv2FohR1N/mlIZ8BNIhll2lM=; b=ol76fpjUF+1IlBaZGwdyLTBARjcZ/hqVU/6apBuWYJIQAC96NU2K/OEYpb2hGC6YEH KqjX3wvEDddh5ZsIgP+OJvMEYG83HrZbwe+t/jgN8hAvUr598j6ToD+f2csBhjkP1Jiw EdZSvlTayQ4t+S8tTLn52ZRO8ob7Xaa2oSnb5lF9b5TEpBYXnDh98ZJki71DtPEmKK69 R4VkTu5NET5hNMPmzELSltv67bDilJqL/+mjGGuMVfhFkqPesVikBpQgAmR+Iz6yvg0D Wh7COXqUyIzxQdOZ+5EWkf5DfhCqDr5MVoc8iuWYUDTmb21775xkTT8W7806p9eZ40qs rPcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726605716; x=1727210516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nFxxNCUyFtMM5wcqjcLlv2FohR1N/mlIZ8BNIhll2lM=; b=BSODgAC6YMcVjcO9v3RJL/a848cxN20kfNYpGaGqkyzv+uS9xu2Kl0RzQPZe+ZeifT j9x7i0OKMC/WijSFmJ4N6gj3MaVQ3Pi+upsiGb4MxTaAeyt6SaNLquCE6u7C3YtPIFku O3+3+CYTiWzmg0s8/Eve5Y1KFXnn8Q+pBzuOITfcKypzAFR/bFO2o7aYTcL5yuiGFfMy W4MsZWn8vhiV6YlruGKoeujZY10OZdD96wqEfL/VVyRiMJ5ZMwORAM2OcXqB4XCVkxZC BTHQnclxbTByycdZp2Mqn2DoMuxSc6jKrQe3rB8dFRp97cLkr13RJxZmIhnyFbRKWhwE BFCg== X-Gm-Message-State: AOJu0YyuZn2gPGd3n5gsFRIDpxgTW9TaFSg7Erq8veZoWwA2v1SwHOTq /Nv6muOFpyA06sKHRJjlxCctKkZ4AqL7DaXN5EHEYjmnHbIseelN5ezhtuYP1RAGJSjBU6YOjeW y X-Google-Smtp-Source: AGHT+IHACVTnBllEHBjt1hmx1Szx8lhGdzWeHQsrFtwnXfuTPpAIM5sN5hB/ozNGtSJzIANd9nYlgg== X-Received: by 2002:a17:902:e802:b0:202:2cd5:2095 with SMTP id d9443c01a7336-2076e33e92amr288355575ad.18.1726605716049; Tue, 17 Sep 2024 13:41:56 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20794731afasm53830425ad.272.2024.09.17.13.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 13:41:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v22 10/15] log: add hook for printing log messages Date: Tue, 17 Sep 2024 13:35:52 -0700 Message-ID: <20240917203828.414701-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240917203828.414701-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240917203828.414701-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This is useful for when decorating log output for console or journal. Provide basic version in this patch. Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup --- lib/log/log.c | 6 +++++- lib/log/log_private.h | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/log/log_private.h diff --git a/lib/log/log.c b/lib/log/log.c index 3fe86ddcd7..48543ee941 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -18,6 +18,7 @@ #include #include "log_internal.h" +#include "log_private.h" #ifdef RTE_EXEC_ENV_WINDOWS #define strdup _strdup @@ -33,11 +34,13 @@ static struct rte_logs { uint32_t type; /**< Bitfield with enabled logs. */ uint32_t level; /**< Log level. */ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */ + log_print_t print_func; size_t dynamic_types_len; struct rte_log_dynamic_type *dynamic_types; } rte_logs = { .type = UINT32_MAX, .level = RTE_LOG_DEBUG, + .print_func = vfprintf, }; struct rte_eal_opt_loglevel { @@ -74,6 +77,7 @@ int rte_openlog_stream(FILE *f) { rte_logs.file = f; + rte_logs.print_func = vfprintf; return 0; } @@ -470,7 +474,7 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) RTE_PER_LCORE(log_cur_msg).loglevel = level; RTE_PER_LCORE(log_cur_msg).logtype = logtype; - ret = vfprintf(f, format, ap); + ret = (*rte_logs.print_func)(f, format, ap); fflush(f); return ret; } diff --git a/lib/log/log_private.h b/lib/log/log_private.h new file mode 100644 index 0000000000..67d2463b2f --- /dev/null +++ b/lib/log/log_private.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef LOG_PRIVATE_H +#define LOG_PRIVATE_H + +/* Note: same as vfprintf() */ +typedef int (*log_print_t)(FILE *f, const char *fmt, va_list ap); + +#endif /* LOG_PRIVATE_H */ -- 2.45.2