[v25,10/15] log: add hook for printing log messages
Checks
Commit Message
This is useful for when decorating log output for console
or journal. Provide basic version in this patch.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
lib/log/log.c | 6 +++++-
lib/log/log_private.h | 9 +++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 lib/log/log_private.h
@@ -18,6 +18,7 @@
#include <rte_per_lcore.h>
#include "log_internal.h"
+#include "log_private.h"
#ifdef RTE_EXEC_ENV_WINDOWS
#define strdup _strdup
@@ -33,11 +34,13 @@ 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 = vfprintf,
};
struct rte_eal_opt_loglevel {
@@ -74,6 +77,7 @@ int
rte_openlog_stream(FILE *f)
{
rte_logs.file = f;
+ rte_logs.print_func = vfprintf;
return 0;
}
@@ -470,7 +474,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, format, ap);
fflush(f);
return ret;
}
new file mode 100644
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef LOG_PRIVATE_H
+#define LOG_PRIVATE_H
+
+/* Note: same as vfprintf() */
+typedef int (*log_print_t)(FILE *f, const char *fmt, va_list ap);
+
+#endif /* LOG_PRIVATE_H */