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 5827D43D8B; Sat, 30 Mar 2024 04:05:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B8FD42D26; Sat, 30 Mar 2024 04:05:01 +0100 (CET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 0783F406B6 for ; Sat, 30 Mar 2024 04:04:50 +0100 (CET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso1729428b3a.1 for ; Fri, 29 Mar 2024 20:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767889; x=1712372689; 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=ef+4W+K/w1vN13UT87NF7vTe2NZwGZarLjZdNpClf5Y=; b=0TIGlq6g7ASPUA+IeFOhu+aAHiiHBcmftlpAts1rZj1y8o9fLAvOdK5ni0lI74piKz 7NjzvqnfK4q8ha3eLxYpI9SPQ222C5kXwEw97hCUXTvi5/EwB0mZKv2pjPgXJHK4gS+M 8GxVdenLSEzIVvA11xSUJQSK7JcwO9SgCKdPEyiP7XWMMOFaO6XyezX7VXFUtNJXbdCl AuaSBSwKE1hdcNw2tUpZENwwLQPjLZZLRCkQCX8faAplUe8RhOqMAMMbqHO5xnUeKVV7 buiqqe8/1Lsrb0KJRxDbwSIgmKm53sORyWKgDIG+8BGPdVe/EjkSiqCm2+hjVBHEuRz3 qExg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767889; x=1712372689; 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=ef+4W+K/w1vN13UT87NF7vTe2NZwGZarLjZdNpClf5Y=; b=MepygEvmmJBwxRdzXTuDoKGRZPPou6liEoE8jsbx0X11NeOgL4xRmJT0PbTRiA90yz eBke3OjH/unP41bCwpZtRF6y5vAXURPyIT+1/vLH//KvbXOQWVYEa5bcqNL/J9DRtkwg FxQZnZH2maEgrGgk7RVTiHXTJ3MrJwbQ+AnCfo3Ol93WKtlFrvrc94EB/KMVAQ4J89lS dZz8pl2aQVr4EYf1Kqa2xO2Hx1Zzm9g0nrQsdN/c5d34zWy3keXhNbzJq6r/R02ZvCwl e34s+qDt5zuyqx1xLym/QaVBvaqS2kdNAEGnbfokBGzg2ObuzRFr/u39aqUSiNAPVm5o K2RA== X-Gm-Message-State: AOJu0YxFFZYtK1nYUtT/30QxrFwRFAK95tqDbJQOnBpIWZ+7LDu+LaTc o8ipkUgAFODwBn3rXMtpBzx2LMI8jOcTjRWJhKpJJiNt0iXHDhCUrVPjE3hp3p/0CQUY6ACTb4R 5 X-Google-Smtp-Source: AGHT+IHvcCxK3i9OotumUVWSTQWkFaBLLvmxDuhFYGOrrodDuJoTvXhEBxBcefucFqNHK6aHVPzPRg== X-Received: by 2002:a05:6a00:1994:b0:6ea:f43b:b961 with SMTP id d20-20020a056a00199400b006eaf43bb961mr1705048pfl.6.1711767889246; Fri, 29 Mar 2024 20:04:49 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:48 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v19 11/15] log: add hook for printing log messages Date: Fri, 29 Mar 2024 20:00:54 -0700 Message-ID: <20240330030429.4630-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-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 | 14 +++++++++++++- lib/log/log_private.h | 11 +++++++++++ 2 files changed, 24 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..71b00528d0 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 = log_print, }; struct rte_eal_opt_loglevel { @@ -74,6 +78,7 @@ int rte_openlog_stream(FILE *f) { rte_logs.file = f; + rte_logs.print_func = log_print; 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, level, format, ap); fflush(f); return ret; } @@ -499,6 +504,13 @@ eal_log_syslog(const char *mode __rte_unused) return -1; } +/* default log print function */ +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 */ diff --git a/lib/log/log_private.h b/lib/log/log_private.h new file mode 100644 index 0000000000..afd833c3bd --- /dev/null +++ b/lib/log/log_private.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef LOG_PRIVATE_H +#define LOG_PRIVATE_H + +typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap); + +__rte_format_printf(3, 0) +int log_print(FILE *f, uint32_t level, const char *format, va_list ap); + +#endif /* LOG_PRIVATE_H */ -- 2.43.0