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 C653143D17; Thu, 21 Mar 2024 17:19:04 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC74742E39; Thu, 21 Mar 2024 17:18:54 +0100 (CET) Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by mails.dpdk.org (Postfix) with ESMTP id 7CA8B42E09 for ; Thu, 21 Mar 2024 17:18:52 +0100 (CET) Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78a2093cd44so93349985a.0 for ; Thu, 21 Mar 2024 09:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711037932; x=1711642732; 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=va7MWJRuAR3nLxH5zGMYb78QbpeyFQrBUnnO1GsDymY=; b=gS0nZDxZWq6ZrPbrWvP3FpE3zskM8o2jntgoJZHyiyb9QzBOi13u2mQHijXMk5VgOW 84W8kii6J9x0IcYSiahdqnyJYINZAv7F2evxC0YDCPLnl67ylhSQffNxL5Ph3HR+MEDv kJXmkzr7UhFc2+rht4l7rGFaqCArb9qb0WYs1vYBJt0/K5ygJNvZH4fr/3vo08kcYPgE hs3GiXFD/MvKjqcXfJFPay+drNfrLVQUfuosemEQzJPRwOzSJmc8YjFnihX7b/AHuxZH eSiX+4KwxLfFUI2C3wLKM8soTQZpPA5Tfcz73kSrLGzqLntrdRzhxDERCgInuUb4wHP4 Jwvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711037932; x=1711642732; 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=va7MWJRuAR3nLxH5zGMYb78QbpeyFQrBUnnO1GsDymY=; b=UYLEuiewFHOV87sys+yfsCbe7BKtANMZ+RBxdEaURfJ90WbluKTh/F3m+ElOmQegJX e8MAnI6+wNAtHZj471CK63YanwWhekTiCpQ5y2Xh4im7Sn5YcPMtevV6wQ2qohG2vm71 szCVbvjr2DpvijhuXkmz2GqZOzUYgWPNz/ATyBgBmI+NxiCMPSTviok9P/o/LoturIXV p6VV0eq8WWRwtGL17QO0oWBYTlz3KNPmKhsXLB0lyVvIEyhqyIs0ZNM2kKkc01gUDCwq ePDRA035N3DAmvrvN7bc/7IGuGpchM/KtKkp9B53slmFobm9b9Z5zKOeDRtDDsJ9o1H5 3C5Q== X-Gm-Message-State: AOJu0YwVuOJUUx3ZedOunJJj+AWTZz8Oy9I00wSB6ftr725SUCh3NLXT sB8Zl4vCJTHBF9017SOq1ySUOb0wXVJBGzAGdMppthEqczTfgESp09ImVq1/cXDalwpHjJqQC8t u X-Google-Smtp-Source: AGHT+IH+RCR8/OOEPPLFLO6+5PUXkSJAY31XYdim4DQOqOtkOc3ZjoSYxJ3K+G6mWmsn/IMlR1E6/A== X-Received: by 2002:a05:6a20:2d95:b0:1a3:7f25:fb4c with SMTP id bf21-20020a056a202d9500b001a37f25fb4cmr2001636pzb.51.1711037518079; Thu, 21 Mar 2024 09:11:58 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id w62-20020a638241000000b005e485fbd455sm41815pgd.45.2024.03.21.09.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:11:57 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v10 02/10] log: unify logging code Date: Thu, 21 Mar 2024 09:00:18 -0700 Message-ID: <20240321161146.340421-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240321161146.340421-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240321161146.340421-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 FreeBSD and Linux logging code can use common code. This also fixes FreeBSD not using syslog. Signed-off-by: Stephen Hemminger --- doc/guides/linux_gsg/linux_eal_parameters.rst | 27 ------------------- doc/guides/prog_guide/log_lib.rst | 18 +++++++++++-- lib/eal/freebsd/eal.c | 8 ++++++ lib/log/log_freebsd.c | 12 --------- lib/log/{log_linux.c => log_unix.c} | 0 lib/log/meson.build | 12 ++++++--- 6 files changed, 32 insertions(+), 45 deletions(-) delete mode 100644 lib/log/log_freebsd.c rename lib/log/{log_linux.c => log_unix.c} (100%) diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index ea8f38139119..d86f94d8a85d 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -108,30 +108,3 @@ Memory-related options * ``--match-allocations`` Free hugepages back to system exactly as they were originally allocated. - -Other options -~~~~~~~~~~~~~ - -* ``--syslog `` - - Set syslog facility. Valid syslog facilities are:: - - auth - cron - daemon - ftp - kern - lpr - mail - news - syslog - user - uucp - local0 - local1 - local2 - local3 - local4 - local5 - local6 - local7 diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst index ff9d1b54a2c8..aacb36c36ce0 100644 --- a/doc/guides/prog_guide/log_lib.rst +++ b/doc/guides/prog_guide/log_lib.rst @@ -5,8 +5,8 @@ Log Library =========== The DPDK Log library provides the logging functionality for other DPDK libraries and drivers. -By default, in a Linux application, logs are sent to syslog and also to the console. -On FreeBSD and Windows applications, logs are sent only to the console. +By default, in a Linux (or FreeBSD) application, logs are sent to syslog and also to the console. +In Windows applications, logs are sent only to the console. However, the log function can be overridden by the user to use a different logging mechanism. Log Levels @@ -29,6 +29,7 @@ will be emitted by the application to the log output. That level can be configured either by the application calling the relevant APIs from the logging library, or by the user passing the ``--log-level`` parameter to the EAL via the application. + Setting Global Log Level ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -59,6 +60,19 @@ For example:: Within an application, the same result can be got using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs. + +Setting syslog facility +~~~~~~~~~~~~~~~~~~~~~~~ + +On Linux and FreeBSD, where syslog is used a ``facility`` argument can be +used to specify what type of program is logging. +The default facility is ``daemon`` but it can be overridden +by the ``--syslog`` EAL parameter. See ``syslog.3`` man page for full values. +For example:: + + /path/to/app --syslog local0 + + Using Logging APIs to Generate Log Messages ------------------------------------------- diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index bab77118e967..a57ee8406f0c 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -53,6 +53,7 @@ #include "eal_options.h" #include "eal_memcfg.h" #include "eal_trace.h" +#include "log_internal.h" #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) @@ -760,6 +761,13 @@ rte_eal_init(int argc, char **argv) #endif } + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); + return -1; + } + /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c deleted file mode 100644 index 698d3c542337..000000000000 --- a/lib/log/log_freebsd.c +++ /dev/null @@ -1,12 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2023 Intel Corporation - */ - -#include -#include "log_internal.h" - -int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) -{ - return 0; -} diff --git a/lib/log/log_linux.c b/lib/log/log_unix.c similarity index 100% rename from lib/log/log_linux.c rename to lib/log/log_unix.c diff --git a/lib/log/meson.build b/lib/log/meson.build index 0d4319b36f77..60516a0b2a2d 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -2,8 +2,12 @@ # Copyright(c) 2023 Intel Corporation includes += global_inc -sources = files( - 'log.c', - 'log_' + exec_env + '.c', -) +sources = files('log.c') + +if is_windows + sources += files('log_windows.c') +else + sources += files('log_unix.c') +endif + headers = files('rte_log.h') -- 2.43.0