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 93D1443D36; Sun, 24 Mar 2024 03:42:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7CA740693; Sun, 24 Mar 2024 03:41:31 +0100 (CET) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by mails.dpdk.org (Postfix) with ESMTP id E31EC402EB for ; Sun, 24 Mar 2024 03:41:25 +0100 (CET) Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso2193592a12.2 for ; Sat, 23 Mar 2024 19:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711248085; x=1711852885; 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=VdEvoGGjU84scNBTJhyFTXSp+Lveq7VDyLhJBdzO3yw=; b=0ciau0+8uP8waaIAgPRZbMiZFiDkm71Di2SWZisph9qaGVnByRLseMHnfRy7gV/1qq Oz856oSVAD+0RFnoRnq6gbkYG5Ry4ff0AW6UiRpKjJLvuOQYiLe9alh/sBHON9zC2fgK qCif9lxv/oUrssEOyEaaOpTU/7IK8ikAV2vBexOCSVv7Vbe6S2L8qvx0cYsIh8cJyKRd 7EIN78DZEu1IMgQcIqo1OZr2+CZhEEaf9yc6IZj98IulYXx4NhijM485zO76iV6MHQ5p gAFZ+ERj6V3bpmMKgNaDvmNdxcLBA2UuKfw/sS28X64bklunZKk9sSHvn7skPp+UJwpa 8o8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711248085; x=1711852885; 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=VdEvoGGjU84scNBTJhyFTXSp+Lveq7VDyLhJBdzO3yw=; b=IH36M2WG0fxCmsUAzbY61Lv73bJVUwPcwdDgEC4qvh51cFUBla1JezhsyyYEbJqTJH u30smXss6yoM1nVwApYIWJO41gOUAh0FEgTzReM0NsvCyv2EmEPa1/bQzMtuq4i9omE+ Uae275Z/ntOdupp6OW9C6A8uFNdpScAAm5buC+iyJ7c4Md2rPbo5DCvcysLDFYozP00h hV0zuFSXf5ffDmBSa+6ZKOvepdVXtjABYTY7QM+rV/7Zr6xv7kA9pSCE6V/BdJcSzcm3 053ka4nmSVnWy0V/XKdV3WZ47+OFXeEAf2axBfVpk27i8Qx0UHUmjwu4YkFDz3K1/NRH 01KQ== X-Gm-Message-State: AOJu0YzSgKp2ZzG3+H0jWlo8S2iw4puugUIHBuRl4lcdk/hk0Tuq/UNC V44nsjAMYwxD+aOPpqf7qre9w1FpYnUqrO/VJ+bvhvzvK+t3lp6DBXWXbfUxLuEv4zb2N6QauSy 1 X-Google-Smtp-Source: AGHT+IG0oFdAT96k4vrSZop5SaKJHVtkLZIwY6iFWpzxW4sIwul8La0GCfx0MkBQ8PNGeMst8keV+Q== X-Received: by 2002:a17:902:d4c3:b0:1e0:1f59:d672 with SMTP id o3-20020a170902d4c300b001e01f59d672mr5214967plg.36.1711248085063; Sat, 23 Mar 2024 19:41:25 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id q17-20020a17090311d100b001dc3c4e7a12sm2244980plh.14.2024.03.23.19.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 19:41:24 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v11 6/9] log: add hook for printing log messages Date: Sat, 23 Mar 2024 19:33:28 -0700 Message-ID: <20240324024109.306614-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324024109.306614-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240324024109.306614-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. No functional changes in this patch, just infrastructure addition. Signed-off-by: Stephen Hemminger --- lib/log/log.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/log/log.c b/lib/log/log.c index 4c8666ac93..4cc871911c 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 { @@ -67,8 +72,6 @@ struct log_cur_msg { /* per core log */ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg); -/* default logs */ - /* Change the stream that will be used by logging system */ int rte_openlog_stream(FILE *f) @@ -77,6 +80,7 @@ rte_openlog_stream(FILE *f) fclose(rte_logs.file); rte_logs.file = f; + rte_logs.print_func = log_print; return 0; } @@ -473,7 +477,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; } @@ -509,6 +513,15 @@ rte_eal_log_cleanup(void) } } +/* 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); +} + /* initialize logging */ void eal_log_init(const char *id __rte_unused) -- 2.43.0