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 43F3043D49; Mon, 25 Mar 2024 21:55:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E756B40EAB; Mon, 25 Mar 2024 21:54:31 +0100 (CET) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 90E8540E0F for ; Mon, 25 Mar 2024 21:54:26 +0100 (CET) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1e0d6356ce9so6469865ad.3 for ; Mon, 25 Mar 2024 13:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400066; x=1712004866; 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=U3Pm2jWPA8CvWVzSCbpUHJ5X5gWKk93CeDmKEZa2qf2WGzpLw9U2C+aKdtH4As9pQ0 NnlRROzopdzrat3lSGt8RRHozRgv8e8eoB1rNb5p/a+qB7If3JIqr81rz0zXX8iKQO1a Vz5N9We6iQDCGiFS7007RFGcQc/ascpI+CfbIcmplXj9XIEmsxd3YVwtC+yxeW2qFimw U9u5/H/b/qdFBGIG+V9ErbRWU4kSYbKgPfWlCz3QFlm82tZqhDbPhS//sJP2+Pa7fG2P RIT9E9APSiE0qtVQG7Pb/xv7wy20rqHdlRY86QZYGFAmcbL+cRAVOdYgF8qk1eZHKVPd anSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711400066; x=1712004866; 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=Ql56zAVTEj4nPrcpFm+8Pjl3fJk8Ujt8VocUmkLiQaPoJlQD75KB6cG4h0+R0/L3yg m/K3rfUoM9tox7pxxnuAITgaw1/TRTgEHKuFVR6GyhzY7HFbPxVct5OUKhEkVZS6S2N8 NZ9y2GfFT4MZovkxh0/8wk3TQ8vepYP7jeDCuZDDLECSePRlpdY1sWdTLPREMUZX5bBI Oa3hYaQC51zlZckAyNDJqwn1RpmmXsSJHyy9GICxPjj5gsQ/nAYCnengL3v3Cyy5q4jg r36U2tnJkBKjuEnd9fieTwks9jr614elVcJPT5klzvDdaPzMvI4MtapQ1OUF4ffdLKD4 whRg== X-Gm-Message-State: AOJu0YzH9P2HyxYENR1nX2G7Zf9AQFJrsuTulidgQio2Jsp5sRH9voEG wXSmFeGosA9B+A7yhpag2GY/dCg6RyDH3PXndAYCGxvCEKtJ4H5hQ6zWLAN7OnU59XgmsjCw9Sv U X-Google-Smtp-Source: AGHT+IEzhQllpPHYQWlKQvYb+SaxR9fB1T0nyUgfj4k3GAzY9wjEDIGU8/Qo9R76RUoJ01l8pc5HJw== X-Received: by 2002:a17:903:41c8:b0:1e0:c88f:654b with SMTP id u8-20020a17090341c800b001e0c88f654bmr3149091ple.25.1711400065835; Mon, 25 Mar 2024 13:54:25 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:54:25 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v12 09/14] log: add hook for printing log messages Date: Mon, 25 Mar 2024 13:47:06 -0700 Message-ID: <20240325205405.669897-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240325205405.669897-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240325205405.669897-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