[dpdk-dev] log: respect rte_openlog_stream calls before rte_eal_init
Commit Message
Before this patch, rte_eal_init invoked rte_openlog_stream, cancelling
any application-specific logger and making it it impossible for an
application to capture the initial log messages generated during
rte_eal_init. With this patch, applications can capture all of the
log messages.
Signed-off-by: John Ousterhout <ouster@cs.stanford.edu>
---
lib/librte_eal/bsdapp/eal/eal_log.c | 3 +--
lib/librte_eal/common/eal_common_log.c | 13 +++++++------
lib/librte_eal/common/include/rte_log.h | 2 +-
lib/librte_eal/linuxapp/eal/eal_log.c | 3 +--
4 files changed, 10 insertions(+), 11 deletions(-)
Comments
2016-09-28 13:42, John Ousterhout:
> Before this patch, rte_eal_init invoked rte_openlog_stream, cancelling
> any application-specific logger and making it it impossible for an
> application to capture the initial log messages generated during
> rte_eal_init. With this patch, applications can capture all of the
> log messages.
It deserves an explanation of what the patch does, i.e. the new logic.
If think you just want to remove the log init from rte_eal_init and
use the default stream when it is not initialized (NULL).
You could also remove the early log stream since the default one could
work from the early stage. Indeed the complex log history was removed:
http://dpdk.org/commit/a3f34a98
Thanks for improving the usability.
@@ -52,6 +52,5 @@ rte_eal_log_init(const char *id __rte_unused, int facility __rte_unused)
int
rte_eal_log_early_init(void)
{
- rte_openlog_stream(stderr);
- return 0;
+ return rte_eal_common_log_init(stderr);
}
@@ -48,11 +48,12 @@ struct rte_logs rte_logs = {
.file = NULL,
};
+/* Stream to use for logging if rte_logs.file is NULL */
static FILE *default_log_stream;
/**
* This global structure stores some informations about the message
- * that is currently beeing processed by one lcore
+ * that is currently being processed by one lcore
*/
struct log_cur_msg {
uint32_t loglevel; /**< log level - see rte_log.h */
@@ -68,10 +69,7 @@ static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg);
int
rte_openlog_stream(FILE *f)
{
- if (f == NULL)
- rte_logs.file = default_log_stream;
- else
- rte_logs.file = f;
+ rte_logs.file = f;
return 0;
}
@@ -127,6 +125,8 @@ rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
{
int ret;
FILE *f = rte_logs.file;
+ if (f == NULL)
+ f = default_log_stream;
if ((level > rte_logs.level) || !(logtype & rte_logs.type))
return 0;
@@ -158,7 +158,8 @@ rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
}
/*
- * called by environment-specific log init function
+ * Called during initialization to specify where to log messages if
+ * openlog_stream hasn't been called.
*/
int
rte_eal_common_log_init(FILE *default_log)
@@ -54,7 +54,7 @@ extern "C" {
struct rte_logs {
uint32_t type; /**< Bitfield with enabled logs. */
uint32_t level; /**< Log level. */
- FILE *file; /**< Pointer to current FILE* for logs. */
+ FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */
};
/** Global log informations */
@@ -136,6 +136,5 @@ rte_eal_log_early_init(void)
printf("Cannot configure early_log_stream\n");
return -1;
}
- rte_openlog_stream(early_log_stream);
- return 0;
+ return rte_eal_common_log_init(early_log_stream);
}