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 3498D43D85; Sat, 30 Mar 2024 17:46:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CD7D740A75; Sat, 30 Mar 2024 17:45:02 +0100 (CET) Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) by mails.dpdk.org (Postfix) with ESMTP id 75F7B402EE for ; Sat, 30 Mar 2024 17:44:52 +0100 (CET) Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-22a96054726so2131120fac.0 for ; Sat, 30 Mar 2024 09:44:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711817092; x=1712421892; 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=fRTRzeLf4wTFUC+Wg+cVLMIZBI4n9evsB9k3McvrbZ42pWFJ5j6U5IZbK8W8xZGy47 dwJtuLx14grJoSi0xHW/i9LuaxwYF7iTssXg3R+Qbxm/LZ0s+iw7dLdhFCkQvX4sKQjF ehqGNUpNoEoEmNjv2oEdOOKGhI73MXMcTdNe+ByV/OBVL2npVNctAmSsIAYPybi0cItG rDEmMumDt2ofsaOdrdcfIrghRoslToP6fzebYVQd50c9aw4R7eFaoer4hJchqb2EXT+t z7O/eYGWBj0A1Y55WGqCdewBUHaCZGqyUskQ23wU9LLLbE5eI4jQm6YaqpYN4cm+Ea49 HnNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711817092; x=1712421892; 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=DqQx9nP1DamwV4AY7IYdfTDnAfuHI56cbwSfGg4dNnkQnRoBe1ZADm0ADl0CehraIM vzSdMklY4iuZkPLGPSyR8OzS7vpCOGXdmy0rtG2L7odpmy/SlQh1FnOi9hXeuoCYUyxG 5hKMw2fy7SrjXroVfN9OmrmPjpYsxb6VFivWfz4JFgE+t+TVJIzy9X4SmWuhNULLfXcu TLvF/Tt8jlKAKjBPVZBHcCvr11yQDyKLGyzrIMRPfFbQB/byxM7WtSJm7I8oCrgxTx0x 4/ypR1+qB2Ji4FJ9rWG6GaAUecMhfH61npnsdlc8sNGSKnrwX+MmY2++ht9sUzn6FpjC 4Qnw== X-Gm-Message-State: AOJu0YwL4quYqIaJxbqS7wuM6M0ohQ6IzWNl5fOEAX6pEvFy7KOEpOFg nUo587BExxga0Q4K6ZlrugTfMUiQYf+Cq6CsglGZighFdCWNHc///2bnSUNj9+WyDZqmDih35Kx a X-Google-Smtp-Source: AGHT+IE1adO28ODmnxVCQKhRFYqS7+Slmxdlk0TJE4keDnHmx+e+qfOWSW+WBKRx9W4ZhvuBlT4cZQ== X-Received: by 2002:a05:6870:2199:b0:22e:dce:39b6 with SMTP id l25-20020a056870219900b0022e0dce39b6mr3642298oae.48.1711817091844; Sat, 30 Mar 2024 09:44:51 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id by1-20020a056a02058100b005dc26144d96sm4192417pgb.75.2024.03.30.09.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 09:44:51 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v20 10/14] log: add hook for printing log messages Date: Sat, 30 Mar 2024 09:42:21 -0700 Message-ID: <20240330164433.50144-11-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330164433.50144-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330164433.50144-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