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 34579459D7; Thu, 19 Sep 2024 17:07:47 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4A960433AA; Thu, 19 Sep 2024 17:06:33 +0200 (CEST) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by mails.dpdk.org (Postfix) with ESMTP id 8B42B43390 for ; Thu, 19 Sep 2024 17:06:28 +0200 (CEST) Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7d4fa972cbeso702524a12.2 for ; Thu, 19 Sep 2024 08:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726758388; x=1727363188; 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=UCRQWgJapj7+HojJ8oBIRtUN3JgniCpMlRHwhFLw+h4=; b=m1sRgA2TjAw38ytqsHrT5kJ6sar4eKsnDfmX6aGlKRik2PhwU8fWli7+fdsf1Eqln1 IUAWq1QzV5bnL2yxeNlqcwHdAUfMrteLMaFVYqu722Bf1NvGKfssr4xejzwnQ+wuMDIU KLtRcv4bf3Y+aJmN0R1/IKmzmLRSStb2IYH+SIkIyl0KFMxADlc2YVvWPUWF1cPEJBge nxfDDt37mJmh3oExNZPW8INkBU46s7TjRlRG+qSqMR7e6JhmXSYhZa7yhyGrNrRCPAP6 xy8hO+rOvwHiANW/vOUo32xq//zrArujX+Qnq9bIlS6+6othac2XReRdIYK7iZ8RQthU pVpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726758388; x=1727363188; 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=UCRQWgJapj7+HojJ8oBIRtUN3JgniCpMlRHwhFLw+h4=; b=Te0I+/AL2OWXlLTdETK7rMxqW/f7CzZq8eKyhf9kDPgEWPwcqtLd7/hvrUf1LH6Dpa klaYIF6OC6ek8ff2140G41yNl2inHrGWqafN9NV6Bg3/eFYq7mS0azzychyHDed6O3DW qwSOUXSaJTN7jV/DQO3Dz6PrEVZwDnohvtxxysSLuna3Egwgl/mH7yvHTNTRqafcuFIA QV3M3JY/saLJUOA08XQn4c125aIfHFAW6E3L7XmgoOM7BD06raq+uhalTnMX8iz6SUlb FDH6CwJXgzg+8mX5lvryi/z2ING2fh/r4whMHFFheV7NEKFEVx6jJqVjOWmBe4O/tzwG Y3UA== X-Gm-Message-State: AOJu0Yx+5iiL1F5VXD02NOgiFfKXaKnZZfhTW05w9wPGvACF50TyeSWk ONZwXt2oxoPZhyPLKEcKfZQKfC2zEr05/NNy73Lj5f7CEVtkvHM3Sk5SXtJet21ulgpyASXkyoQ J X-Google-Smtp-Source: AGHT+IE+fi8TC9Ca9MUtejNFhWq44gH8E9zrlF+9G48LDWVYNRZxOkGx3dP6RxU+QKasBW38W0ASUg== X-Received: by 2002:a05:6a21:3a41:b0:1cf:5b31:313a with SMTP id adf61e73a8af0-1cf75c7e923mr38773866637.1.1726758387690; Thu, 19 Sep 2024 08:06:27 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944adfd3dsm8620841b3a.92.2024.09.19.08.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 08:06:27 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng Subject: [PATCH v25 10/15] log: add hook for printing log messages Date: Thu, 19 Sep 2024 08:04:16 -0700 Message-ID: <20240919150609.5281-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240919150609.5281-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240919150609.5281-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 Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- 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