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 51BD843D4E; Tue, 26 Mar 2024 02:59:35 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 09BEE40DC9; Tue, 26 Mar 2024 02:58:55 +0100 (CET) Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) by mails.dpdk.org (Postfix) with ESMTP id 49C4D40DFB for ; Tue, 26 Mar 2024 02:58:48 +0100 (CET) Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-22a639aedb6so78112fac.3 for ; Mon, 25 Mar 2024 18:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711418327; x=1712023127; 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=xfr9GGpW+m4ZcIkUaGni30cMeql/PTaerJGKogSvGTBnM51YuBqq5IJ8NvruKwhgyB s0JLL6nOLHkVI1/rqZUxOkBObpynC+wahFGxBK25WvycBgrBFiG7ou1wuOXYv+4SkCL+ ZEA0jwOz1eY583cdRvnR6pyeMqYUuTFWpMo5fpGBRtT+zcu7n/AUHX/y2Bea27N5kyEo zapa0eVBuBHe3+FjVyhEaw06NuzQvQicMhyqdbJluBNdkcNRq1Dshfpu+A7zOSOqMzCv cSPNE7EtIYqbyEX6dsCMfdAIbLHxD1LJQbmYsJCKkrIdrGZ7MzZ97uvxlYg3bfm2/mQl ACGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711418327; x=1712023127; 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=G4LEKc30BN7439NfOHhuHarOE9cdYHaGEKvRixacHzmCOFh+YabG3yBLo73pz4N1CV TCq5EWD745psZR0rryR7DkvRzy9Ak5yAJuvTfRFsu/jT1mwXEzMfNUiffLd41swqx6ZT cRKNLfryzREaUThENzZa7Y7RBpn0NMT/Pjzw77ryNCFnmAvjlOr3zY2IPN3Oijz5X2ar sOPpIadTh6h78pDWuuYXIeffZbkyFI42vC0M75OJQEvWn4herJ6pJeTXObHI7OHVplCt 8atxwlQ9IKQHFQiUmIBOz+2LZ9YDXMtdk65mDnj5O6wQ5LCi4l4Od6X+LLJYB3EvfTio MhYA== X-Gm-Message-State: AOJu0Ywz2ugZfNzp92VhwzY+r4QrG5aJgAvudT+yGXIrodDnhI+0vgoQ SyH6IZ0mgaaKuNvRJ7i7U5wyiGxPbzdB3MFEJ/WVrhc1JVy/XoxEoiBCn86ygmrRBIUMsE8lE+V p X-Google-Smtp-Source: AGHT+IFMcsG2OplwAnkb63rkcN3GpjP7iy6ZFyS8JQKWFySkowbnOvOrcrdVRZfJc9SEWwYtflpxsA== X-Received: by 2002:a05:6871:3426:b0:22a:5423:45ff with SMTP id nh38-20020a056871342600b0022a542345ffmr2857019oac.40.1711418327572; Mon, 25 Mar 2024 18:58:47 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id u19-20020a63d353000000b005dc88b232a5sm6571541pgi.26.2024.03.25.18.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 18:58:47 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v13 09/11] log: add hook for printing log messages Date: Mon, 25 Mar 2024 18:57:04 -0700 Message-ID: <20240326015827.825648-10-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326015827.825648-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240326015827.825648-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