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 1489045B56; Wed, 16 Oct 2024 22:25:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D0BDD4069F; Wed, 16 Oct 2024 22:24:12 +0200 (CEST) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id 5527140650 for ; Wed, 16 Oct 2024 22:24:06 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20cdb889222so2194045ad.3 for ; Wed, 16 Oct 2024 13:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1729110245; x=1729715045; 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=h5e/VBGNQ23+lf6M/wyfGKCbGh1tWvatjLKBKO6WfTodqhoC23RW5JFpup+9fbCgZJ Ua7A9IdAzyGw0ecgyvOi40nZjTslQYQDO+vXw/lOyvDxrjMGGW0LKRrZPxcsB3qT4MmU y8/anxZuMY2JtG/wNFltlZhKvYg+svvqByjxUUqW7EQRZIcgJZv2685yXzQ/u2oMwavi 0NogGUXgP757cyrFMjjK7rVgjiBvH9sbzFtQZohABYhyjjRgZ3PDIn4oq83gU9oCPEYO 3JiueUOq6RJ9BEyXloJwds8fuOxNJrafqJBE8dGr5tkw3RojyR1tuNHPNnixlsBiWAKY U12w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729110245; x=1729715045; 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=opOiTiEQtCd3ry6zuCYtOHI9bHcJRXSOw/zHeHBBY+0vp+t4IEwcuuF8REIHuDgrkV KfQrq95BFfcvfRxZ8rn5stx29ACbjvOAQQ0lSNmWyqfnPmOeTytpNS8J38CwjF8DRKVh Or+JdaAB1ivDLAUofBOAoLa06IfqpmZ0/7tasD8wEh/QF1FGXleBCDyC6xuXNdLf+bPq hE14QUiwobexAWbDJ6EQnQY0kAcWP2og3wstBA78dS46I34EFdWs6481x3Epn4c0V0rp G+xNSPF+83epa9nTz7qz6Nywya+i0CAqCPMZjlIWnVVa/vEx4B+v+4PSTmsfmtF5rBsN pvdQ== X-Gm-Message-State: AOJu0YwBfsB8gwKbK/rUUnhTjpMcT0Fg6rzreBqHQZqeYF+pOPMyqLrJ u9P0oKJuTyFr2SZmbcz/txIeLdcnZXpgfkKYlxY9/U4qwEamljt7PuZfYG2avdF4Kl7pvypj4Ds c X-Google-Smtp-Source: AGHT+IFjHPO1ji76gZnILORXbH2b7SKGTOsHbTrAh3a9khk0PjYFb7ZzHJvo+R+sixW7hmcT8H7yzQ== X-Received: by 2002:a17:903:41c5:b0:20c:c482:1d66 with SMTP id d9443c01a7336-20cc4821f85mr218031325ad.35.1729110244055; Wed, 16 Oct 2024 13:24:04 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20d180361e5sm32308825ad.120.2024.10.16.13.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 13:24:03 -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 v26 10/15] log: add hook for printing log messages Date: Wed, 16 Oct 2024 13:20:37 -0700 Message-ID: <20241016202343.190653-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241016202343.190653-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20241016202343.190653-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