[v9,1/5] log: unify logging code

Message ID 20240318220432.7486-2-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Logging unification and timestamp |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger March 18, 2024, 10:02 p.m. UTC
  FreeBSD and Linux logging code can use common code. This also
fixes FreeBSD not using syslog.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 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%)
  

Patch

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 <syslog facility>``
-
-    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 <rte_common.h>
-#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')