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 475B343D5B; Thu, 28 Mar 2024 00:31:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E19D042D8C; Thu, 28 Mar 2024 00:30:29 +0100 (CET) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTP id 5031A427DF for ; Thu, 28 Mar 2024 00:30:21 +0100 (CET) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5d42e7ab8a9so216016a12.3 for ; Wed, 27 Mar 2024 16:30:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711582220; x=1712187020; 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=zu4Y35qfKTRMkWDem+dq2ZFz0NT/aAm4UNjlX7qaan4=; b=LykAprlzC2mqe+P5k2QToJ9gepY1jqqzMHFXDfWK8gn40Wb75EVv3Q4wT0ICSejsnC oNN3nxezzWOmLJaTPVRE4A+cENm/bz9SKQX7gqzRz7Af39JZHmGbrVUekwO9uIGBX0+g 4o7I3yXUATpXVVgzL2FcgKprXgGgryEA7Ylq3v6Zf+l7Gg4nryXNPKTa4i4v9Z2qWs41 /ZB6+zSlKAt7gnly7lgVEicOSL08MRgHOguRuzIa7SN68Uszz6SP5+1RS8Z6/0qZJ+3B MQz5if7k9INtpXcxcSZ+P3bO7pZh6ESMr51Z00CFrKnzwzL6ZnWCm/GDf+I5Lt+FBhdS D6gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711582220; x=1712187020; 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=zu4Y35qfKTRMkWDem+dq2ZFz0NT/aAm4UNjlX7qaan4=; b=LQngUFPg+ucX1+3f68D42nTUjhMkKJJZQ1vJmAzgwNcv3g7Oi1tl/CN76khC/qRxY+ BkL521VdWJCAcS/x9pY/paBtOc1AsmNI+OkNfXATzUMGlfnuCLSniPnNgSLNsM5hwVYE odchwaWiE+2pO6biGg9075Nl6j0aelmvNCfV9iFUExoOC46gY6OF2aSIiONTLHLNSLFj FHCoEn1RAFmQdPBGFLS3XlLeKUwL5oXaRVkcjbZMlTvykDoxlk/Haj0AT8mV4m7SLS83 75BRxE0nAFNRAM/6Sfcs37Z2h7Jv+wVUmBozF5LzLm8NmoBwRtoAJPIHJM3hYacuWkij dnWg== X-Gm-Message-State: AOJu0YyIS9tA8qkOJ2gn05c4SqT5NYeEe5GmpdLdBvd52khZPqqCRGaD /qxyEPXFF+skz69ZF3hoNrA3jYokcRbqor/lseGeuu8yEW49OArR2xmHj2tr1IdXlvUTKir+NwN j X-Google-Smtp-Source: AGHT+IG7vD0pIVqBn0UhBgwWi1/nmWO6ctlzwGMlrhdoZfxSggvDQ56Rx4MEp/zSasAVx8Ln/X46Og== X-Received: by 2002:a05:6a20:c702:b0:1a3:3c5f:2ebd with SMTP id hi2-20020a056a20c70200b001a33c5f2ebdmr1830831pzb.59.1711582220528; Wed, 27 Mar 2024 16:30:20 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id n15-20020a170902e54f00b001e0fdc6e4ebsm80772plf.175.2024.03.27.16.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:30:20 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v17 11/15] log: add hook for printing log messages Date: Wed, 27 Mar 2024 16:28:34 -0700 Message-ID: <20240327233001.83505-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240327233001.83505-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240327233001.83505-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 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/log/log.c b/lib/log/log.c index f597da2e39..acd4c320b6 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -26,16 +26,21 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; +typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); +static int log_print(FILE *f, uint32_t level, const char *format, va_list ap); + /** 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 = log_print, }; struct rte_eal_opt_loglevel { @@ -78,6 +83,7 @@ rte_openlog_stream(FILE *f) fclose(rte_logs.file); rte_logs.file = f; + rte_logs.print_func = log_print; return 0; } @@ -484,7 +490,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, level, format, ap); fflush(f); return ret; } @@ -513,6 +519,15 @@ eal_log_syslog(const char *mode __rte_unused) return -1; } +/* default log print function */ +__rte_format_printf(3, 0) +static int +log_print(FILE *f, uint32_t level __rte_unused, + const char *format, va_list ap) +{ + return vfprintf(f, format, ap); +} + /* * Called by rte_eal_init */ -- 2.43.0