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 3AC1143D5A; Tue, 26 Mar 2024 18:37:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E26C140EF0; Tue, 26 Mar 2024 18:36:21 +0100 (CET) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by mails.dpdk.org (Postfix) with ESMTP id 5795A410FA for ; Tue, 26 Mar 2024 18:36:14 +0100 (CET) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6ea8a0d1a05so22295b3a.1 for ; Tue, 26 Mar 2024 10:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711474573; x=1712079373; 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=EAtBlHcl5jikUNLB/Ftkk0xJ2EMYsX/E0EVeYH55RWz8a2PQgM6Dg4lMBX6K1GERAR mLOEexidU728BDw7vLN8RbbASTPCivELn+pSKV5esjjf7oebsTjrk40hPYAyeVM+8oIE i23Mrk2pq7PzWqg8AtHuK86JLfqRW68RelXQwcUhHv+E2ggouIpwIMvocaQOybGimJwh LXC7Skqjl24y6PuIWCaJGEqzDT+q6v+jKgi5LrQ2XrxTFBukqTeHAhkt9rYx2mgy7WH8 3kfyhghZtuA6uF+NFqf2ICL3LyIXg/rb8uo1uyIUOjxWvTAiIG8AVRi1e4AvHUPWk4Y0 /nLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711474573; x=1712079373; 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=MD4McT//4zcRuvbwBkH6ejkxsBm/FwbrCWKO5yC0FJ9a+KYrPtgwdPg67XGCOuY8GA MdEM+RfwXz2jYEoNP5wtCQNTQC9Z+jWFmI7g1SwGIt8nFS+2hQaenL9MrK/rBuMMCls/ a4Gr+PPnnp9wLeGW/XZKgQ0hKMUONgpvgzw47IxJvSWmKoEFW2EBE5HPePc9SF29Pe+n l9If5Jphv/FHPap/86L1T8MSMESQI1MXUXr0aX+4OoqixxMCToy4eYHS3GqOwRFGrqhb uzgeUTIEzumh+5Sel3lu4KysvdV28UfoKzP323JpoEk3cEBjyU0Ho5nY5I0u0M+3TQdp O99w== X-Gm-Message-State: AOJu0Yy5srJ2TKh/xOdfJF3vl8ScC2zS4Q3xnSjnyWNeNTJG92xRLWvM FXAI5/QmXxL/310EnJZ0QNYLb8rgFfuRG2HGawV1jlJfpsOFEVU263+Z6qnINI4gzSuSRg1rdAY t X-Google-Smtp-Source: AGHT+IE8J4mG7B921OgI7lWLAVJ3CoCrvwnpEr9KdR9s3S+nJtr6NxtPiN70XCSRtUInTmc7+BFwHQ== X-Received: by 2002:a05:6a00:1ad3:b0:6ea:9a10:b74c with SMTP id f19-20020a056a001ad300b006ea9a10b74cmr2913550pfv.16.1711474573495; Tue, 26 Mar 2024 10:36:13 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u6-20020aa78386000000b006e58da8bb6asm6205546pfm.132.2024.03.26.10.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 10:36:13 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v14 11/15] log: add hook for printing log messages Date: Tue, 26 Mar 2024 10:34:31 -0700 Message-ID: <20240326173552.97249-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326173552.97249-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326173552.97249-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