4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <rte_per_lcore.h>
42 #include "eal_private.h"
44 /* global log structure */
45 struct rte_logs rte_logs = {
47 .level = RTE_LOG_DEBUG,
51 static FILE *default_log_stream;
54 * This global structure stores some informations about the message
55 * that is currently beeing processed by one lcore
58 uint32_t loglevel; /**< log level - see rte_log.h */
59 uint32_t logtype; /**< log type - see rte_log.h */
63 static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg);
67 /* Change the stream that will be used by logging system */
69 rte_openlog_stream(FILE *f)
72 rte_logs.file = default_log_stream;
78 /* Set global log level */
80 rte_set_log_level(uint32_t level)
82 rte_logs.level = (uint32_t)level;
85 /* Get global log level */
87 rte_get_log_level(void)
89 return rte_logs.level;
92 /* Set global log type */
94 rte_set_log_type(uint32_t type, int enable)
97 rte_logs.type |= type;
99 rte_logs.type &= (~type);
102 /* Get global log type */
104 rte_get_log_type(void)
106 return rte_logs.type;
109 /* get the current loglevel for the message beeing processed */
110 int rte_log_cur_msg_loglevel(void)
112 return RTE_PER_LCORE(log_cur_msg).loglevel;
115 /* get the current logtype for the message beeing processed */
116 int rte_log_cur_msg_logtype(void)
118 return RTE_PER_LCORE(log_cur_msg).logtype;
122 * Generates a log message The message will be sent in the stream
123 * defined by the previous call to rte_openlog_stream().
126 rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
129 FILE *f = rte_logs.file;
131 if ((level > rte_logs.level) || !(logtype & rte_logs.type))
134 /* save loglevel and logtype in a global per-lcore variable */
135 RTE_PER_LCORE(log_cur_msg).loglevel = level;
136 RTE_PER_LCORE(log_cur_msg).logtype = logtype;
138 ret = vfprintf(f, format, ap);
144 * Generates a log message The message will be sent in the stream
145 * defined by the previous call to rte_openlog_stream().
146 * No need to check level here, done by rte_vlog().
149 rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
154 va_start(ap, format);
155 ret = rte_vlog(level, logtype, format, ap);
161 * called by environment-specific log init function
164 rte_eal_common_log_init(FILE *default_log)
166 default_log_stream = default_log;
167 rte_openlog_stream(default_log);
169 #if RTE_LOG_LEVEL >= RTE_LOG_DEBUG
170 RTE_LOG(NOTICE, EAL, "Debug logs available - lower performance\n");