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 B964044136; Tue, 4 Jun 2024 02:49:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5495143318; Tue, 4 Jun 2024 02:48:00 +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 60ABD432E0 for ; Tue, 4 Jun 2024 02:47:53 +0200 (CEST) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1f47f07acd3so4840295ad.0 for ; Mon, 03 Jun 2024 17:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717462072; x=1718066872; 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=PJaBt95mJGUWxHM6IfnmZOombz4LVzOya7YPQnoawfY=; b=0APDtRNQ5tIc7UzTVMosc9Ci3++lVofRUmmVDyX/d7GoV7aBgHBhFjYYeP7dKaDsRB DVoln2G8817Xr0My+Sr4tSiPmtlaE01oYo+6Tf8iaNKuQByrMHPlMdF7PDVKO5VJ5Woj cJxemV7ruSP63dfLJ81IXgmf76tOXt+z32Vy3cFqLYp5dZPbtAzAT5WoLXY3yayh8M22 GdMyGhktXtwXXe0DC1uqLKAA4WP/dFgIQteadawsp2pgTpswc6dAyGYNjm3VQ2Pb1hAJ xqNdWlr/+MKcS1LkZszZm8Daa+u3WfVYZPF7BmfTrHKAsvB+FBmnH+BTeqs1+sahYtiQ l6ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717462072; x=1718066872; 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=PJaBt95mJGUWxHM6IfnmZOombz4LVzOya7YPQnoawfY=; b=huZITHu47kH0yQJjfzqJCUDw7buMPifa5cDQwb0z/umbT9lItyIjfKZ5CpUHjKhshh y4z5N3j8MwJwk9oei286bt8VCR4jquetWwFNuYBrtMzR8rvhXWaSakLwEZBDP1Z6LWAY ddBNx0F09spYAbzxMwhlFQj7IXWDIo/CBvBZ/Lev5QRopZPIrHyshKeJZ9naXg+r9zjg d5Da47tTbqTaSQadd1LtluASlFg4uGJ+qPq+o3E8uOzOxytnq2q28jGjVJ/PQ8mycOKZ jepCxj+t5C34fP4ysP8sJvZyZixEVEZdA/86If2TWJ4QgsbV9znF0FqieH0RBb1N9txe iJKQ== X-Gm-Message-State: AOJu0YxBqmCT4PbmvufbjtAlz087hIEPu77AbnVPeEqlaGqLo93U4W0A wg/v9f+vsN5mkU+nXdtNj2nS46WK5kx74UOn56NJ/OghDTrdT8Y2bdyP95pvpTwCzXzbQ5GLSyp 7 X-Google-Smtp-Source: AGHT+IEMcp4c5zOnv49uoR5NiZV8TFqnJ1mTEzeB2beQoqfRIjW1G4yPDOg6dq79bginjtN9bfVmYQ== X-Received: by 2002:a17:903:22d2:b0:1f4:6252:db95 with SMTP id d9443c01a7336-1f636ffe906mr127136155ad.5.1717462072471; Mon, 03 Jun 2024 17:47:52 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323e9aa7sm70381125ad.192.2024.06.03.17.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 17:47:52 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v21 10/14] log: add hook for printing log messages Date: Mon, 3 Jun 2024 17:44:58 -0700 Message-ID: <20240604004731.6654-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604004731.6654-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240604004731.6654-1-stephen@networkplumber.org> MIME-Version: 1.0 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 --- lib/log/log.c | 7 ++++++- lib/log/log_private.h | 9 +++++++++ 2 files changed, 15 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..979b20c3ef 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 @@ -28,16 +29,19 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; + /** The rte_log structure. */ 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 +78,7 @@ int rte_openlog_stream(FILE *f) { rte_logs.file = f; + rte_logs.print_func = vfprintf; return 0; } @@ -470,7 +475,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.43.0