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 5611343D73; Fri, 29 Mar 2024 00:53:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4DE5842D97; Fri, 29 Mar 2024 00:52:27 +0100 (CET) Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by mails.dpdk.org (Postfix) with ESMTP id 91084427E5 for ; Fri, 29 Mar 2024 00:52:16 +0100 (CET) Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6e6a1d24770so854309a34.0 for ; Thu, 28 Mar 2024 16:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711669936; x=1712274736; 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=giTdfr+RN6uyZUtqeZRydi6pfOybpgRHCGsV9B26rK/UYq5BQWgez2vL8l/SH/1ej4 AfXen0cI4P9ymnFJsEIdCuHzisD8ynchcJ2hkpbpXHV4zU0IGfiwwcM2DUZhhvkoRavH hSnrWAeLpWV7cH/QZNPScsEfduZTPoPcHSxm5Xn31dYw87SBQNG9scYRjP5TDHMj9uxK X+teupiwZ/NXJzGyQLavONG8Tjc7PfDAQ8G196R4QuSz9Wfu8AcWenSdSWFswk6uTE7r EGiL0cCkknWBrXjSb/eYULOG1xsb3MWYill10NVSluKN01XEfDRddcGosdLDIxCYiWIS kn9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711669936; x=1712274736; 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=Bkpe/8xYjEEPSOVyNPqKx1ClUpsXIo4SZ5ZMK8OqStYoIGUxBYrQOcEl38amrFLOYT 27E1beavSbDbBzNI8t/eckCu2akE7igtuO1j5SO3SWGAkOrw1fgpLVNaWEmo+CFFUMhQ zrQJa4dan0XHhD+UHSWyjXOh0VN4yXrzO33nrgFqbReLO4aa1BzDDV33RcXzeH6JWa76 4KYlMTYoztTU20gVnMtgMyi2vZWJioihorQ34X2a/oBEjpyVBSTV00wj3/sXMGAsc0Uw so1A7GOJHaNRP4gc599MPvgrAA9tZ0TtnykdfHUzEEr+eSOjlFnZbpmV3+QNIPdbvZeO wtlg== X-Gm-Message-State: AOJu0YynSxGquvXsCpUjoRuPGVrZHzM2GeK6f0c8L4+Kt0oAG6uhNYXl YYgZYhb6fpzT2awLz78673vLuG21ex0+V9BNvKlAJukKLE07GBw072bYcoZmKw7pHKHf2EyQ7S0 m X-Google-Smtp-Source: AGHT+IFpJZ40oO6ELHJ6eBVXACsd2se9xYSACfkOn76iiKCNRiAlwsHmnTB9XhGj98oyt0NZDM/VLg== X-Received: by 2002:a05:6870:ac0b:b0:22a:5423:45ff with SMTP id kw11-20020a056870ac0b00b0022a542345ffmr739184oab.40.1711669935927; Thu, 28 Mar 2024 16:52:15 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id g21-20020a631115000000b005df58c83e89sm1875650pgl.84.2024.03.28.16.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:52:15 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v18 11/15] log: add hook for printing log messages Date: Thu, 28 Mar 2024 16:49:41 -0700 Message-ID: <20240328235156.5768-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328235156.5768-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240328235156.5768-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