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 B8F1443D55; Wed, 27 Mar 2024 17:48:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6BE7442DB1; Wed, 27 Mar 2024 17:47:53 +0100 (CET) Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) by mails.dpdk.org (Postfix) with ESMTP id 9AED7402A3 for ; Wed, 27 Mar 2024 17:47:45 +0100 (CET) Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-221e6bf537dso43410fac.1 for ; Wed, 27 Mar 2024 09:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711558065; x=1712162865; 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=hhEZrQqff+DqeHzMEIDJ7i2X7+Y6T1XoV12RpizGFDqKM/F+AVFhNF9/YmypapTmKg 9ZDCmlSM5mAreTMbb9EjpKDr/pfIV6VQgZNsbEJfhmgDjA88HVtI70hbQMwvGIV1kji2 fSROAfAVgNgr5P2PtPpEFxP0mjkAZXGtE4yYTUfBJKTndh1nmTo47t4WgQoAlm6i1qmW E6QXM35XnQoMl2ZMmcRC/NFdgGFes/gWnz3thT1zhBlSqxcFndBeGHhX3+BUvz8v++Br HMMWpIi4X95J+UVY9tOmgaZ/yqerAEIylsmvBm52R/uWcBeMyr8MCSnbFPUiZEUNqI3r iV0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711558065; x=1712162865; 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=RycrDwhRZhjbwUF/Qrx1UQnxIPQ17WU/YFGDgtxMirg8Ix8O5L+5jx84hDAl6WqRze amdCFr3BP6/OVS+gKAfoFkq4sbr1BhVe0XfI46oSwK9nv9uwqs5YRFduia6UIZ5fH2Xr ugyhI6gARWuZ3pResyCYWhLeuOaLVnDsJt10FeH00Xp4pi0gpl0SdPJmXFgRSwMrseuM XCQOKUjRI44lixfZeMdnf2w0LrQG3Q7HmtoUAbEL5Qt4dEqcKg0fLFESWKv3g68jc6E1 +sAZsZnx+oUriyEp9qJFGmVGQ5aD2HFoX7kfLW0zKVFB6dp5ziZ3wk3D8eyXsEfhznP/ Hd2w== X-Gm-Message-State: AOJu0YzqGDili440b+tw3lSgpvyQYjXftdkq5eqzI9PYlJUavsO344Nk c3Wjb5s8CMnMjfxgwW1O0x6CkVLHgod1ZbMa5BZrJl2FHYL4zaFkIPxcoaOnU0Gksqr13JaVxZm n X-Google-Smtp-Source: AGHT+IF0GzXSD6Ugt4/Wv5LoLl+XYFF1ongDJv5ErEnyoi1mlOHATwalW8cCmK2dmtJrTssdr+TpTQ== X-Received: by 2002:a05:6870:c14c:b0:22a:80e5:ccbe with SMTP id g12-20020a056870c14c00b0022a80e5ccbemr233672oad.20.1711558064843; Wed, 27 Mar 2024 09:47:44 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id a33-20020a056a0011e100b006e580678dfbsm5160873pfu.193.2024.03.27.09.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:47:44 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v16 11/15] log: add hook for printing log messages Date: Wed, 27 Mar 2024 09:45:29 -0700 Message-ID: <20240327164726.68732-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240327164726.68732-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240327164726.68732-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