log: remove deprecated history dump
[dpdk.git] / lib / librte_eal / common / eal_common_log.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <stdio.h>
35 #include <stdint.h>
36 #include <stdarg.h>
37 #include <stdlib.h>
38
39 #include <rte_log.h>
40 #include <rte_per_lcore.h>
41
42 #include "eal_private.h"
43
44 /* global log structure */
45 struct rte_logs rte_logs = {
46         .type = ~0,
47         .level = RTE_LOG_DEBUG,
48         .file = NULL,
49 };
50
51 static FILE *default_log_stream;
52
53 /**
54  * This global structure stores some informations about the message
55  * that is currently beeing processed by one lcore
56  */
57 struct log_cur_msg {
58         uint32_t loglevel; /**< log level - see rte_log.h */
59         uint32_t logtype;  /**< log type  - see rte_log.h */
60 };
61
62  /* per core log */
63 static RTE_DEFINE_PER_LCORE(struct log_cur_msg, log_cur_msg);
64
65 /* default logs */
66
67 /* Change the stream that will be used by logging system */
68 int
69 rte_openlog_stream(FILE *f)
70 {
71         if (f == NULL)
72                 rte_logs.file = default_log_stream;
73         else
74                 rte_logs.file = f;
75         return 0;
76 }
77
78 /* Set global log level */
79 void
80 rte_set_log_level(uint32_t level)
81 {
82         rte_logs.level = (uint32_t)level;
83 }
84
85 /* Get global log level */
86 uint32_t
87 rte_get_log_level(void)
88 {
89         return rte_logs.level;
90 }
91
92 /* Set global log type */
93 void
94 rte_set_log_type(uint32_t type, int enable)
95 {
96         if (enable)
97                 rte_logs.type |= type;
98         else
99                 rte_logs.type &= (~type);
100 }
101
102 /* Get global log type */
103 uint32_t
104 rte_get_log_type(void)
105 {
106         return rte_logs.type;
107 }
108
109 /* get the current loglevel for the message beeing processed */
110 int rte_log_cur_msg_loglevel(void)
111 {
112         return RTE_PER_LCORE(log_cur_msg).loglevel;
113 }
114
115 /* get the current logtype for the message beeing processed */
116 int rte_log_cur_msg_logtype(void)
117 {
118         return RTE_PER_LCORE(log_cur_msg).logtype;
119 }
120
121 /*
122  * Generates a log message The message will be sent in the stream
123  * defined by the previous call to rte_openlog_stream().
124  */
125 int
126 rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
127 {
128         int ret;
129         FILE *f = rte_logs.file;
130
131         if ((level > rte_logs.level) || !(logtype & rte_logs.type))
132                 return 0;
133
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;
137
138         ret = vfprintf(f, format, ap);
139         fflush(f);
140         return ret;
141 }
142
143 /*
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().
147  */
148 int
149 rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
150 {
151         va_list ap;
152         int ret;
153
154         va_start(ap, format);
155         ret = rte_vlog(level, logtype, format, ap);
156         va_end(ap);
157         return ret;
158 }
159
160 /*
161  * called by environment-specific log init function
162  */
163 int
164 rte_eal_common_log_init(FILE *default_log)
165 {
166         default_log_stream = default_log;
167         rte_openlog_stream(default_log);
168
169 #if RTE_LOG_LEVEL >= RTE_LOG_DEBUG
170         RTE_LOG(NOTICE, EAL, "Debug logs available - lower performance\n");
171 #endif
172
173         return 0;
174 }