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 6433345965; Wed, 18 Sep 2024 07:00:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0B14942DCA; Wed, 18 Sep 2024 06:58:58 +0200 (CEST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id D1947427E5 for ; Wed, 18 Sep 2024 06:58:48 +0200 (CEST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2057c6c57b5so2407945ad.1 for ; Tue, 17 Sep 2024 21:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726635528; x=1727240328; 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=ZYLpmZxTlLY9tw/lHYZJbDY7ohY9Z50zGEeKhrYMSzlR/fygUbMKw9pe29G9AbXkNd nxWceuK5veY6/yfyVdTHpfg09BvAeR5Ij/Fux6tfuMhIiAZErkqwKewIolHa6VI7bVjr OnP4TKRJ3f0/YNV+4Vjjt3JOavpvfLJr61fjDQAZh1oSaA/YQ4lDAhcepCgUsR4FzUj8 U1MiUBuz/79is4vNnFgfBh+W4Nvdt77WBr+tvceVi0Gb8HZjRoPaPtvpmGXHLO6s5pJZ AgY460Ky3S5bqL93R8Vx+bszqb7MpUVNRZjE91VLgQz1D12oa+QprpzdU4Oy2tX9dTa4 16rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726635528; x=1727240328; 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=KVxYcPdy4swRlwSRx4Ynw5k9VmeeO4OiEt2qfwTR/PRvKymEcJDVj6MI0doXL9krQU 1a02Rj3LbBqEJwCEVi7oljJYoURpkpa6O6H/RJMlW6Q+HPoQhhFeO0L5V/TtySsQeja2 dpzBItqwqG9TK8P9E+HhAoaStMwoTlhaeLqPoJoPuiA8ymTnW9tXYxBO0QR3NLHFwa0h BARD6OUwBxfDMrlWHTWs/AFjF3Ossn8eUC6/ZsIgz/pbIpnLQOlPhxKBogMXblkfG0Vf yhw3BKHeudYSO1VA5CFzDWxAjJ2qQ4L/NKp+m1QaR9Gw15dElZVY1P74RTLLrEkoo78N aekQ== X-Gm-Message-State: AOJu0YyVLBaHREZGujhRqOFbZPa2UnDuyG7BU3Xrq3U5NoPkjNklbEOh hWJqNqagaeTL7bRBvuP5jegJCo+2cgBYXQj21sBEcBiBraabSG2gAwhKxvG9WIKnqKibzH6bwRn 8 X-Google-Smtp-Source: AGHT+IF9i4ZAbMDcl7PrA0ExraTRQR74eJKDObiMeo1GOpMzWybAoczDRvkDyQF7mZMjQUaX30VP/A== X-Received: by 2002:a17:903:32ce:b0:205:6121:1b2d with SMTP id d9443c01a7336-2074c5d24aamr392828795ad.3.1726635527983; Tue, 17 Sep 2024 21:58:47 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20794746d76sm57179245ad.292.2024.09.17.21.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 21:58:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v23 10/15] log: add hook for printing log messages Date: Tue, 17 Sep 2024 21:56:15 -0700 Message-ID: <20240918045830.3798-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240918045830.3798-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240918045830.3798-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