diff options
| author | Stephen Hemminger <[email protected]> | 2024-10-27 10:24:39 -0700 |
|---|---|---|
| committer | David Marchand <[email protected]> | 2024-11-08 18:08:35 +0100 |
| commit | 630cdfcd69c90dcdf54fcf6be05f73fd1ac1e0a9 (patch) | |
| tree | d723b8dd806f4729bc5187263faf64960e1ea4b5 /lib | |
| parent | 2773d39ffee46f66fd628cebdd401d89fce09f1f (diff) | |
log: add hook for printing log messages
This is useful for when decorating log output for console or journal.
Provide basic version in this patch.
Signed-off-by: Stephen Hemminger <[email protected]>
Acked-by: Morten Brørup <[email protected]>
Acked-by: Bruce Richardson <[email protected]>
Acked-by: Chengwen Feng <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/log/log.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/log/log.c b/lib/log/log.c index a5cae1f950..dbff223108 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -29,16 +29,21 @@ struct rte_log_dynamic_type { uint32_t loglevel; }; +/* Note: same as vfprintf() */ +typedef int (*log_print_t)(FILE *f, const char *fmt, va_list ap); + /** The rte_log structure. */ 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 { @@ -75,6 +80,7 @@ int rte_openlog_stream(FILE *f) { rte_logs.file = f; + rte_logs.print_func = vfprintf; return 0; } @@ -471,7 +477,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; } |
