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 156B3459D0; Wed, 18 Sep 2024 22:54:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 025F443302; Wed, 18 Sep 2024 22:53:53 +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 CDEB3432C8 for ; Wed, 18 Sep 2024 22:53:45 +0200 (CEST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-206aee40676so2139855ad.0 for ; Wed, 18 Sep 2024 13:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1726692825; x=1727297625; 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=ZpDqOcK+q4FSmyjCA3ZOQXRXBo5I59kj+jmvRyV4bQIKHmjvwFKsG7lFiO/EXTugtg fwwBE4q9XXTmvx2ErK9DfU0qhZQUVSZjyy+g1e/WUS1EsMspa6jEDsr+nWicHscAu7ge ViO77xGs0vLk/d6Fd6yrSmd/HB2sCE0tt0LWGy9jLhXMn0K84lLPNzDC6mGVMhXNQnRA CCRMsmB18K0LTfNvNCXAmWoM8dms1VYrcZT2j28MNq3ds6aw7rgkbzUlC+s0u6cGYLlC ZcXrSyfK+bXQbxnOjFSBJEt8l2BUe4Z6DrrejZNmDHM0nMaw5ZRrNNdn/q5oW+ETnenk 72yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726692825; x=1727297625; 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=oqqFQyvc2HNbTrxSBUIBi7bnLhNUbDKUkG/I4xejmPzOHwH/1kKq/zLH/NNObzCWxA kP0Tyn0JS/aDgmRazkBA1py9z4sQWHLvEgM09iqJFY4aUJydYRUb4ZNRLFOcuEe8gJ/5 m+SUKh8d9Iu3tOgBfsgPfjf4Sl+h5HfEjCf4hXLrYV3wXWd9K+4GyJKAUQp7du4ajym0 o2u6d2XgY0mjl3NiIUbJwl/dqhPedQRB/tIVdDPR/fvMTW6bpZht7OvSCsXqxkos8Lrv Ods233C8Xvu1pIxoDxson3zVDCZG+JoDZeH82VnhuwHrNQ/b7CbSOx2thU57dg/C1Rm9 3b0Q== X-Gm-Message-State: AOJu0YwISPMreVEeJmHBoFclq34msPSirszEFoJFNX0au1TiiVzQ1NkB IbdrpZGBlkXIgh6dz3CQK9q1HlOEyBP0qUu6+vZ7cYig+5TPVlYU1ZR/MaTmlQ8KqFNaU9hntNo j X-Google-Smtp-Source: AGHT+IGPfc+Q21sd85SESphAswQ0kG7IP1H1Rjs1+5VNG3jOz2Tud3Yp7mLg/D6sZxT9Elp3qx64JQ== X-Received: by 2002:a17:902:db0e:b0:1fd:672f:2b34 with SMTP id d9443c01a7336-20782b634d1mr305803965ad.33.1726692825007; Wed, 18 Sep 2024 13:53:45 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2079471a2e6sm69415775ad.240.2024.09.18.13.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 13:53:44 -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 v24 10/15] log: add hook for printing log messages Date: Wed, 18 Sep 2024 13:52:09 -0700 Message-ID: <20240918205324.35449-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240918205324.35449-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240918205324.35449-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