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);
68 rte_log_add_in_history(const char *buf __rte_unused, size_t size __rte_unused)
74 rte_log_set_history(int enable)
77 RTE_LOG(WARNING, EAL, "The log history is deprecated.\n");
80 /* Change the stream that will be used by logging system */
82 rte_openlog_stream(FILE *f)
85 rte_logs.file = default_log_stream;
91 /* Set global log level */
93 rte_set_log_level(uint32_t level)
95 rte_logs.level = (uint32_t)level;
98 /* Get global log level */
100 rte_get_log_level(void)
102 return rte_logs.level;
105 /* Set global log type */
107 rte_set_log_type(uint32_t type, int enable)
110 rte_logs.type |= type;
112 rte_logs.type &= (~type);
115 /* Get global log type */
117 rte_get_log_type(void)
119 return rte_logs.type;
122 /* get the current loglevel for the message beeing processed */
123 int rte_log_cur_msg_loglevel(void)
125 return RTE_PER_LCORE(log_cur_msg).loglevel;
128 /* get the current logtype for the message beeing processed */
129 int rte_log_cur_msg_logtype(void)
131 return RTE_PER_LCORE(log_cur_msg).logtype;
134 /* Dump log history to file */
136 rte_log_dump_history(FILE *out __rte_unused)
141 * Generates a log message The message will be sent in the stream
142 * defined by the previous call to rte_openlog_stream().
145 rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
148 FILE *f = rte_logs.file;
150 if ((level > rte_logs.level) || !(logtype & rte_logs.type))
153 /* save loglevel and logtype in a global per-lcore variable */
154 RTE_PER_LCORE(log_cur_msg).loglevel = level;
155 RTE_PER_LCORE(log_cur_msg).logtype = logtype;
157 ret = vfprintf(f, format, ap);
163 * Generates a log message The message will be sent in the stream
164 * defined by the previous call to rte_openlog_stream().
165 * No need to check level here, done by rte_vlog().
168 rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
173 va_start(ap, format);
174 ret = rte_vlog(level, logtype, format, ap);
180 * called by environment-specific log init function
183 rte_eal_common_log_init(FILE *default_log)
185 default_log_stream = default_log;
186 rte_openlog_stream(default_log);
188 #if RTE_LOG_LEVEL >= RTE_LOG_DEBUG
189 RTE_LOG(NOTICE, EAL, "Debug logs available - lower performance\n");