Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/138781/?format=api
http://patchwork.dpdk.org/api/patches/138781/?format=api", "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20240325205405.669897-12-stephen@networkplumber.org/", "project": { "id": 1, "url": "http://patchwork.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20240325205405.669897-12-stephen@networkplumber.org>", "list_archive_url": "https://inbox.dpdk.org/dev/20240325205405.669897-12-stephen@networkplumber.org", "date": "2024-03-25T20:47:08", "name": "[v12,11/14] log: add optional support of syslog", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "17e3ceb697753c385e28b963db9d4766e700c2f6", "submitter": { "id": 27, "url": "http://patchwork.dpdk.org/api/people/27/?format=api", "name": "Stephen Hemminger", "email": "stephen@networkplumber.org" }, "delegate": { "id": 1, "url": "http://patchwork.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20240325205405.669897-12-stephen@networkplumber.org/mbox/", "series": [ { "id": 31616, "url": "http://patchwork.dpdk.org/api/series/31616/?format=api", "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=31616", "date": "2024-03-25T20:46:57", "name": "Logging unification and enhancements", "version": 12, "mbox": "http://patchwork.dpdk.org/series/31616/mbox/" } ], "comments": "http://patchwork.dpdk.org/api/patches/138781/comments/", "check": "success", "checks": "http://patchwork.dpdk.org/api/patches/138781/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 62E1A43D49;\n\tMon, 25 Mar 2024 21:55:31 +0100 (CET)", "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 29D7D40EDB;\n\tMon, 25 Mar 2024 21:54:34 +0100 (CET)", "from mail-pl1-f173.google.com (mail-pl1-f173.google.com\n [209.85.214.173])\n by mails.dpdk.org (Postfix) with ESMTP id 9D41D40E36\n for <dev@dpdk.org>; Mon, 25 Mar 2024 21:54:28 +0100 (CET)", "by mail-pl1-f173.google.com with SMTP id\n d9443c01a7336-1e0d82c529fso5676955ad.2\n for <dev@dpdk.org>; Mon, 25 Mar 2024 13:54:28 -0700 (PDT)", "from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203])\n by smtp.gmail.com with ESMTPSA id\n b18-20020a170903229200b001e0b5eee802sm3164487plh.123.2024.03.25.13.54.27\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 25 Mar 2024 13:54:27 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711400068;\n x=1712004868; darn=dpdk.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=BzCso9sKu6dCrjxH8A6EQo0nwJbP6WzCWG5/oETewgQ=;\n b=ZnfbW7hNVNsxdhVztvhGeX95AmCAu4RGNr/PbVX4a5YX1Od6vBznqshdclOnPoPcfh\n xBMzICjQ5lnYa0bpfCLTnM1GV9n40NAYLW7BGsNOl+45nYDCV6FVwEqy8auE3K9qhxrs\n QTUBHWh6ToZI/+WQIneegw4l1CTODJrKcrRcwUM0lZRANyTaKPPk3aE575oBjJN1gSs8\n s79LyHGicbZnqzChyAaRonQsNKVYMAdHAfcuyFzieTllts2xkMVQo70W/i3pRGnsAUvg\n NV68HThmW5A3nnGltEtKtnI9UlR1tFx9xpmxe3fKD4Vh0jMmbi72ljq5YkXGQrx2f6lc\n CLlw==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1711400068; x=1712004868;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=BzCso9sKu6dCrjxH8A6EQo0nwJbP6WzCWG5/oETewgQ=;\n b=RA7nLY/z9+hQ+LChDP1W+2sS8gIy4HQfxpl3u4NjWtHVLKO53WbGTQR0qCNgLkP9rQ\n cs0aTLzVHubk+2JPFTVTL9q/P8A8FbRRF3YQujyEZfQQ0d2w0qIWNp6sCuygAX1qerLs\n /74S1zmSM4dsp1NHVqPzJp+LNdwLn9hb0GMh8wqZRGaUM92wb/uyVDG7iUD77sAtFevY\n kPDcY2ltfRwN1tpVyfNmO44N8dxk5U5O/g8I8Mh8EvNyAuhK+tLfy8wLPIU+qIywbEYn\n MDQznuzuV7Xfq+aAtUb+QEBYIKCzoa5LhMKjj5gVGnWQ4o1KlTG3X8OxSvMVlsc7tKnV\n Kb4g==", "X-Gm-Message-State": "AOJu0YxFyrv9uIWcbw198MmzzWyO2AmNRyAIRWpaqORhQB7GXjU30Mi6\n BpWO4DCekhd4wsLuv9quAZo3dtc+g7oB3L5zYPnkNiVgRYEc+BVU3SyeJ1zms51Wle3RBFgQ3QZ\n D", "X-Google-Smtp-Source": "\n AGHT+IGU1NoqUXTfuqcSERumdWI47EVx+YEnr9woZqwfXZHt5gb5dGKdHn+tnvMM7FP8ImXVSsf/+w==", "X-Received": "by 2002:a17:902:ea05:b0:1e0:a7c2:af8f with SMTP id\n s5-20020a170902ea0500b001e0a7c2af8fmr7633604plg.5.1711400067717;\n Mon, 25 Mar 2024 13:54:27 -0700 (PDT)", "From": "Stephen Hemminger <stephen@networkplumber.org>", "To": "dev@dpdk.org", "Cc": "Stephen Hemminger <stephen@networkplumber.org>", "Subject": "[PATCH v12 11/14] log: add optional support of syslog", "Date": "Mon, 25 Mar 2024 13:47:08 -0700", "Message-ID": "<20240325205405.669897-12-stephen@networkplumber.org>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20240325205405.669897-1-stephen@networkplumber.org>", "References": "<20200814173441.23086-1-stephen@networkplumber.org>\n <20240325205405.669897-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 <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "Log to syslog only if option is specified. And if syslog is used\nthen normally only log to syslog, don't duplicate output.\nAlso enables syslog support on FreeBSD.\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\n---\n doc/guides/linux_gsg/linux_eal_parameters.rst | 27 -----\n doc/guides/prog_guide/log_lib.rst | 17 +++\n lib/eal/common/eal_common_options.c | 2 +-\n lib/log/log.c | 101 ++++++++++++++++--\n 4 files changed, 111 insertions(+), 36 deletions(-)", "diff": "diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst\nindex ea8f381391..d86f94d8a8 100644\n--- a/doc/guides/linux_gsg/linux_eal_parameters.rst\n+++ b/doc/guides/linux_gsg/linux_eal_parameters.rst\n@@ -108,30 +108,3 @@ Memory-related options\n * ``--match-allocations``\n \n Free hugepages back to system exactly as they were originally allocated.\n-\n-Other options\n-~~~~~~~~~~~~~\n-\n-* ``--syslog <syslog facility>``\n-\n- Set syslog facility. Valid syslog facilities are::\n-\n- auth\n- cron\n- daemon\n- ftp\n- kern\n- lpr\n- mail\n- news\n- syslog\n- user\n- uucp\n- local0\n- local1\n- local2\n- local3\n- local4\n- local5\n- local6\n- local7\ndiff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst\nindex 504eefe1d2..abaedc7212 100644\n--- a/doc/guides/prog_guide/log_lib.rst\n+++ b/doc/guides/prog_guide/log_lib.rst\n@@ -83,6 +83,23 @@ To prefix all console messages with ISO format time the syntax is::\n \n \t/path/to/app --log-timestamp=iso\n \n+Log output\n+~~~~~~~~~~\n+\n+If desired, messages can be redirected to syslog (on Linux and FreeBSD) with the ``--syslog``\n+option. There are three possible settings for this option:\n+\n+*always*\n+ Redirect all log output to syslog.\n+\n+*auto*\n+ Use console if it is a terminal, and use syslog if is not.\n+\n+*both*\n+ Print to both console and syslog.\n+\n+If ``--syslog`` option is not specified, then only console (stderr) will be used.\n+\n \n \n Using Logging APIs to Generate Log Messages\ndiff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c\nindex aa1faad45c..6f0fd151c1 100644\n--- a/lib/eal/common/eal_common_options.c\n+++ b/lib/eal/common/eal_common_options.c\n@@ -91,7 +91,7 @@ eal_long_options[] = {\n \t{OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },\n \t{OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },\n \t{OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },\n-\t{OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },\n+\t{OPT_SYSLOG, 2, NULL, OPT_SYSLOG_NUM },\n \t{OPT_VDEV, 1, NULL, OPT_VDEV_NUM },\n \t{OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },\n \t{OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM },\ndiff --git a/lib/log/log.c b/lib/log/log.c\nindex 2dca91306e..d8974c66db 100644\n--- a/lib/log/log.c\n+++ b/lib/log/log.c\n@@ -13,15 +13,17 @@\n #include <sys/queue.h>\n #include <unistd.h>\n \n+#ifdef RTE_EXEC_ENV_WINDOWS\n+#include <rte_os_shim.h>\n+#else\n+#include <syslog.h>\n+#endif\n+\n #include <rte_log.h>\n #include <rte_per_lcore.h>\n \n #include \"log_internal.h\"\n \n-#ifdef RTE_EXEC_ENV_WINDOWS\n-#include <rte_os_shim.h>\n-#endif\n-\n struct rte_log_dynamic_type {\n \tconst char *name;\n \tuint32_t loglevel;\n@@ -36,14 +38,25 @@ enum eal_log_time_format {\n \tEAL_LOG_TIMESTAMP_ISO,\n };\n \n+enum eal_log_syslog {\n+\tEAL_LOG_SYSLOG_NONE = 0,\t/* do not use syslog */\n+\tEAL_LOG_SYSLOG_AUTO,\t\t/* use syslog only if not a terminal */\n+\tEAL_LOG_SYSLOG_ALWAYS,\t\t/* always use syslog */\n+\tEAL_LOG_SYSLOG_BOTH,\t\t/* log to both syslog and stderr */\n+};\n+\n typedef int (*log_print_t)(FILE *f, uint32_t level, const char *fmt, va_list ap);\n static int log_print(FILE *f, uint32_t level, const char *format, va_list ap);\n \n+\n /** The rte_log structure. */\n static struct rte_logs {\n \tuint32_t type; /**< Bitfield with enabled logs. */\n \tuint32_t level; /**< Log level. */\n \tFILE *file; /**< Output file set by rte_openlog_stream, or NULL. */\n+#ifndef RTE_EXEC_ENV_WINDOWS\n+\tenum eal_log_syslog syslog_opt;\n+#endif\n \tlog_print_t print_func;\n \n \tenum eal_log_time_format time_format;\n@@ -532,9 +545,23 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...)\n \n /* Placeholder */\n int\n-eal_log_syslog(const char *mode __rte_unused)\n+eal_log_syslog(const char *str)\n {\n+#ifdef RTE_EXEC_ENV_WINDOWS\n+\tRTE_SET_USED(str);\n \treturn -1;\n+#else\n+\tif (str == NULL || strcmp(str, \"auto\") == 0)\n+\t\t/* log to syslog only if stderr is not a terminal */\n+\t\trte_logs.syslog_opt = EAL_LOG_SYSLOG_AUTO;\n+\telse if (strcmp(str, \"both\") == 0)\n+\t\trte_logs.syslog_opt = EAL_LOG_SYSLOG_BOTH;\n+\telse if (strcmp(str, \"always\") == 0)\n+\t\trte_logs.syslog_opt = EAL_LOG_SYSLOG_ALWAYS;\n+\telse\n+\t\treturn -1;\n+\treturn 0;\n+#endif\n }\n \n /* Set the log timestamp format */\n@@ -706,17 +733,75 @@ log_print_with_timestamp(FILE *f, uint32_t level,\n \treturn log_print(f, level, format, ap);\n }\n \n+#ifndef RTE_EXEC_ENV_WINDOWS\n /*\n- * Called by rte_eal_init\n+ * wrapper for log stream to put messages into syslog\n+ * useful for cases like:\n+ * rte_hex_dump(rte_get_log_stream(), ...)\n */\n-void\n-eal_log_init(const char *id __rte_unused)\n+static ssize_t\n+syslog_log_write(__rte_unused void *c, const char *buf, size_t size)\n+{\n+\t/* Syslog error levels are from 0 to 7, so subtract 1 to convert */\n+\tsyslog(rte_log_cur_msg_loglevel() - 1, \"%.*s\", (int)size, buf);\n+\treturn size;\n+}\n+\n+static int\n+syslog_log_close(__rte_unused void *c)\n {\n+\tcloselog();\n+\treturn 0;\n+}\n+\n+static cookie_io_functions_t syslog_log_func = {\n+\t.write = syslog_log_write,\n+\t.close = syslog_log_close,\n+};\n+#endif\n+\n+\n+/* Choose how log output is directed */\n+static void\n+log_output_selection(const char *id)\n+{\n+\tRTE_SET_USED(id);\n+\n+#ifndef RTE_EXEC_ENV_WINDOWS\n+\tbool is_terminal = isatty(STDERR_FILENO);\n+\n+\tif (!(rte_logs.syslog_opt == EAL_LOG_SYSLOG_NONE ||\n+\t (rte_logs.syslog_opt == EAL_LOG_SYSLOG_AUTO && is_terminal))) {\n+\t\tint flags = LOG_NDELAY | LOG_PID;\n+\n+#ifdef LOG_PERROR\n+\t\tif (rte_logs.syslog_opt == EAL_LOG_SYSLOG_BOTH)\n+\t\t\tflags |= LOG_PERROR;\n+#endif\n+\t\topenlog(id, flags, is_terminal ? LOG_USER : LOG_DAEMON);\n+\n+\t\t/* redirect other log messages to syslog as well */\n+\t\tFILE *log_stream = fopencookie(NULL, \"w\", syslog_log_func);\n+\t\tif (log_stream != NULL)\n+\t\t\tdefault_log_stream = log_stream;\n+\t\treturn;\n+\t}\n+#endif\n \tif (rte_logs.time_format != EAL_LOG_TIMESTAMP_NONE)\n \t\trte_logs.print_func = log_print_with_timestamp;\n+}\n \n+/*\n+ * Called by rte_eal_init\n+ */\n+void\n+eal_log_init(const char *id)\n+{\n+\trte_logs.print_func = log_print;\n \tdefault_log_stream = stderr;\n \n+\tlog_output_selection(id);\n+\n #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG\n \tRTE_LOG(NOTICE, EAL,\n \t\t\"Debug dataplane logs available - lower performance\\n\");\n", "prefixes": [ "v12", "11/14" ] }{ "id": 138781, "url": "