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 3A82C43D5B; Wed, 27 Mar 2024 01:30:36 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 28CDB42DB2; Wed, 27 Mar 2024 01:29:30 +0100 (CET) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by mails.dpdk.org (Postfix) with ESMTP id 0974A427DD for ; Wed, 27 Mar 2024 01:29:19 +0100 (CET) Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5e4f79007ffso3981630a12.2 for ; Tue, 26 Mar 2024 17:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711499358; x=1712104158; 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=TMG1/ygWZ3Pt3CptFdbW8cFI4ImJqDhmvYP5qdG2wC4fKVK4cBC6RK/rxDfd6tO/SA MRRZTOnrI+fUcgDiPzsJi7DWl/R+DY2jbWABNeVetUrQYcKn77YdSrtuSJXv4RIjown9 p7MYYPua2vJVlKMxSZd3qDzY3LHIdpHRdgI7fmO0u3HxYeL4B9WBfDyox+Z6eeXvry3e ST6EIPe2SfP27wF4a9tWZyX94/TpJ+nFGq92oG/vpBD33CRi5VxyszLceS1n0tmGdnBq U4dBHtqADHgKyTLAI21KcVvZwGd8G9uTmLKTDQ7tub7+ORULWpsex7fcYLHI/kGZKwTN 2rrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711499358; x=1712104158; 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=iQ4cI+mvkbVWYBbONyvGmpj9GBv7/3WlfLTw/gFh8m/tE2xV90EqJ13OOf/+1hYoHC p5y4OUbPwbnrCRP/XKu0LbdlOERY2yE3LFZLRVqvgRXQ2Zav348qT39945GeAAd0lFEy adQbxvRVgbKEwanTb0+9i8ArIVPqfQeEJr6b4+XhxqKXZYX2DLSjGY49wxniNhXpVJDI qpHYMH7V+d/fcGokQvjac4obp9tYcN7RYnklOhkVrNFT3XM82bWQx/Srpnh8zfDUJIOO YN+FpIzwrXmYNjOZ13g9YAWbdO+QFPViQQoMnkDxOiifuiJnUybBSSNRVZIbbRsa0qZn SFsQ== X-Gm-Message-State: AOJu0Yxot+M4ujWAzeVKVqxfePErq557AcaycfNhvIJJCyc8YbXYay7+ E3YCmCektdIyHyFtsWF56whsR5pgcjMkoSLCElldofFSI1JnhT/LqFtBD+9HejS9vkUNo8uQXY+ Q X-Google-Smtp-Source: AGHT+IEbEvny1BBv5NyxYIp/I+EYxyFGoqOp4Giovaqmd+6zS6Clkr9cVR931NPaFKHTDUcPwaVn2Q== X-Received: by 2002:a17:90a:da05:b0:29d:e004:f8ce with SMTP id e5-20020a17090ada0500b0029de004f8cemr2912340pjv.6.1711499358236; Tue, 26 Mar 2024 17:29:18 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w15-20020a17090ad60f00b002a04eef22c5sm225383pju.44.2024.03.26.17.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 17:29:17 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v15 11/15] log: add hook for printing log messages Date: Tue, 26 Mar 2024 17:27:10 -0700 Message-ID: <20240327002859.203006-12-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240327002859.203006-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240327002859.203006-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