b/lib/librte_eal/bsdapp/eal/eal_log.c
@@ -42,9 +42,9 @@
* once memzones are available.
*/
int
-rte_eal_log_init(const char *id __rte_unused, int facility __rte_unused)
+rte_eal_log_init(const char *id, int facility)
{
- if (rte_eal_common_log_init(stderr) < 0)
+ if (rte_eal_common_log_init(stderr, id, facility) < 0)
return -1;
return 0;
}
@@ -52,6 +52,6 @@ rte_eal_log_init(const char *id __rte_unused, int
facility __rte_unused)
int
rte_eal_log_early_init(void)
{
- rte_openlog_stream(stderr);
+ rte_openlog_stream_initial(stderr);
return 0;
}
b/lib/librte_eal/common/eal_common_log.c
@@ -48,6 +48,14 @@ struct rte_logs rte_logs = {
.file = NULL,
};
+struct rte_default_log_args rte_default_log_args =
+{
+ .facility = 0,
+ .log_id = NULL,
+ .prepare_default_log = NULL,
+};
+
+
static FILE *default_log_stream;
/**
@@ -82,9 +90,30 @@ int
rte_openlog_stream(FILE *f)
{
if (f == NULL)
+ {
+ if (rte_default_log_args.prepare_default_log)
+ {
+ if
(rte_default_log_args.prepare_default_log(rte_default_log_args.log_id,
+ rte_default_log_args.facility) <
0)
+ return -1;
+ }
rte_logs.file = default_log_stream;
+ }
else
+ {
rte_logs.file = f;
+ }
+ return 0;
+}
+
+int
+rte_openlog_stream_initial(FILE *f)
+{
+ /* only initialize if not configured before rte_eal_init() */
+ if (NULL == rte_logs.file)
+ {
+ return rte_openlog_stream(f);
+ }
return 0;
}
@@ -176,14 +205,26 @@ rte_log(uint32_t level, uint32_t logtype, const char
*format, ...)
return ret;
}
+int rte_eal_set_default_log_stream(FILE *default_log, const char *id,
int facility,
+ int (*prepare_log)(const char
*log_id, int facility))
+{
+ rte_default_log_args.facility = facility;
+ rte_default_log_args.log_id = id;
+ rte_default_log_args.prepare_default_log = prepare_log;
+ default_log_stream = default_log;
+
+ return 0;
+}
+
/*
* called by environment-specific log init function
*/
int
-rte_eal_common_log_init(FILE *default_log)
+rte_eal_common_log_init(FILE *default_log, const char *id, int facility,
+ int (*prepare_log)(const char *log_id, int
facility))
{
- default_log_stream = default_log;
- rte_openlog_stream(default_log);
+ rte_eal_set_default_log_stream(default_log, id, facility,
prepare_log);
+ rte_openlog_stream_initial(NULL); /* enable default log stream */
#if RTE_LOG_LEVEL >= RTE_LOG_DEBUG
RTE_LOG(NOTICE, EAL, "Debug logs available - lower
performance\n");
b/lib/librte_eal/common/eal_private.h
@@ -49,13 +49,26 @@ int rte_eal_memzone_init(void);
/**
* Common log initialization function (private to eal).
*
- * @param default_log
- * The default log stream to be used.
+ * @param default_log The default log stream to be used.
+ * @param id the id used for openlog call
+ * @param facility the facility used for openlog call
+ * @param prepare_log a platform specific log prepare function
* @return
* - 0 on success
* - Negative on error
*/
-int rte_eal_common_log_init(FILE *default_log);
+int rte_eal_common_log_init(FILE *default_log, const char *id, int
facility,
+ int (*prepare_log)(const char *log_id, int
facility));
+
+/**
+ * A function that only sets the log stream if it has not previously been
set.
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ * 0 on success, negative on error
+ */
+int rte_openlog_stream_initial(FILE *f);
/**
* Fill configuration with number of physical and logical processors
@@ -97,6 +110,27 @@ int rte_eal_memory_init(void);
int rte_eal_timer_init(void);
/**
+ * Perform necessary initialization for the default stream before it is
used
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ * 0 on success, negative on error
+ */
+int rte_eal_prepare_log(const char *id, int facility);
+
+/**
+ * Setup the default log stream and related parameters
+ *
+ * This function is private to EAL.
+ *
+ * @return
+ * 0 on success, negative on error
+ */
+int rte_eal_set_default_log_stream(FILE *default_log, const char *id,
int facility,
+ int (*prepare_log)(const char *log_id, int
facility));
+
+/**
* Init early logs
*
* This function is private to EAL.
b/lib/librte_eal/common/include/rte_log.h
@@ -59,8 +59,15 @@ struct rte_logs {
FILE *file; /**< Pointer to current FILE* for logs. */
};
+struct rte_default_log_args {
+ int facility;
+ const char *log_id;
+ int (*prepare_default_log)(const char *log_id, int facility);
+};
+
/** Global log informations */
extern struct rte_logs rte_logs;
+extern struct rte_default_log_args rte_default_log_args;
/* SDK log type */
#define RTE_LOGTYPE_EAL 0x00000001 /**< Log related to eal. */
b/lib/librte_eal/linuxapp/eal/eal_log.c
@@ -49,6 +49,8 @@
#include "eal_private.h"
+static FILE *early_log_stream;
+
/*
* default log function
*/
@@ -82,10 +84,18 @@ static cookie_io_functions_t console_log_func = {
.write = console_log_write,
};
+static int
+rte_eal_prepare_default_log(const char *id, int facility)
+{
+ openlog(id, LOG_NDELAY | LOG_PID, facility);
+ return 0;
+}
+
/*
* set the log to default function, called during eal init process,
* once memzones are available.
*/
+
int
rte_eal_log_init(const char *id, int facility)
{
@@ -95,10 +105,14 @@ rte_eal_log_init(const char *id, int facility)
if (log_stream == NULL)
return -1;
- openlog(id, LOG_NDELAY | LOG_PID, facility);
-
- if (rte_eal_common_log_init(log_stream) < 0)
- return -1;
+ if (rte_logs.file != early_log_stream) /* logging was initialized
before rte_eal_init() */
+ {
+ rte_eal_set_default_log_stream(log_stream, id, facility,
rte_eal_prepare_default_log);
+ } else
+ {
+ if (rte_eal_common_log_init(log_stream, id, facility,
rte_eal_prepare_default_log) < 0)
+ return -1;
+ }