[v8,1/5] log: unify logging code
Checks
Commit Message
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%)
@@ -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
@@ -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
-------------------------------------------
@@ -760,6 +760,14 @@ rte_eal_init(int argc, char **argv)
#endif
}
+ if (eal_log_init(program_invocation_short_name,
+ 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.
deleted file mode 100644
@@ -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;
-}
similarity index 100%
rename from lib/log/log_linux.c
rename to lib/log/log_unix.c
@@ -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')