[v5,5/6] eal: allow user to set default log stream before init
Checks
Commit Message
It is useful for application to be able to set the default log
stream before call rte_eal_init(). This makes all messages go
to the new default.
For example, to skip using syslog; just doing
rte_log_set_default(stderr);
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/eal/common/eal_common_log.c | 6 ++++++
lib/eal/common/eal_log.h | 1 +
lib/eal/unix/eal_log.c | 4 ++++
3 files changed, 11 insertions(+)
@@ -535,6 +535,12 @@ eal_log_set_default(FILE *default_log)
#endif
}
+FILE *
+eal_log_get_default(void)
+{
+ return default_log_stream;
+}
+
/*
* Called by eal_cleanup
*/
@@ -22,6 +22,7 @@ int eal_log_level_parse(int argc, char * const argv[]);
* Determine where log data is written when no call to rte_openlog_stream.
*/
void eal_log_set_default(FILE *default_log);
+FILE *eal_log_get_default(void);
/*
* Save a log option for later.
@@ -113,6 +113,10 @@ eal_log_init(const char *id, int facility)
{
FILE *log_stream;
+ /* has user has already setup a log stream */
+ if (eal_log_get_default())
+ return 0;
+
log_stream = fopencookie(NULL, "w+", console_log_func);
if (log_stream == NULL)
return -1;