2 Copyright (c) 2012, Broadcom Europe Ltd
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 /*=============================================================================
29 VideoCore OS Abstraction Layer - logging support
30 =============================================================================*/
32 #ifndef VCOS_LOGGING_H
33 #define VCOS_LOGGING_H
41 #include "interface/vcos/vcos_types.h"
43 #include "vcos_logging_control.h"
50 * This provides categorised logging. Clients register
51 * a category, and then get a number of logging levels for
54 * The logging level flag is tested using a flag *before* the
55 * function call, which makes logging very fast when disabled - there
56 * is no function call overhead just to find out that this log
57 * message is disabled.
59 * \section VCOS_LOG_CATEGORY
61 * As a convenience, clients define VCOS_LOG_CATEGORY to point to
62 * their category; the various vcos_log_xxx() macros then expand to
67 * #define VCOS_LOG_CATEGORY (&my_category)
69 * #include <interface/vcos/vcos.h>
71 * VCOS_LOG_CAT_T my_category;
75 * vcos_log_trace("Stuff happened: %d", n_stuff);
80 typedef enum VCOS_LOG_LEVEL_T
82 VCOS_LOG_UNINITIALIZED = 0,
91 /** Initialize a logging category without going through vcos_log_register().
93 * This is useful for the case where there is no obvious point to do the
94 * registration (no initialization function for the module). However, it
95 * means that your logging category is not registered, so cannot be easily
96 * changed at run-time.
98 #define VCOS_LOG_INIT(n,l) { l, n, 0, {0}, 0, 0 }
100 /** A registered logging category.
102 typedef struct VCOS_LOG_CAT_T
104 VCOS_LOG_LEVEL_T level; /**< Which levels are enabled for this category */
105 const char *name; /**< Name for this category. */
106 struct VCOS_LOG_CAT_T *next;
108 unsigned int want_prefix:1;
110 unsigned int refcount;
111 void *platform_data; /**< platform specific data */
114 typedef void (*VCOS_VLOG_IMPL_FUNC_T)(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, va_list args);
116 /** Convert a VCOS_LOG_LEVEL_T into a printable string.
117 * The platform needs to implement this function.
119 VCOSPRE_ const char * VCOSPOST_ vcos_log_level_to_string( VCOS_LOG_LEVEL_T level );
121 /** Convert a string into a VCOS_LOG_LEVEL_T
122 * The platform needs to implement this function.
124 VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_string_to_log_level( const char *str, VCOS_LOG_LEVEL_T *level );
126 /** Log a message. Basic API. Normal code should not use this.
127 * The platform needs to implement this function.
129 VCOSPRE_ void VCOSPOST_ vcos_log_impl(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, ...) VCOS_FORMAT_ATTR_(printf, 3, 4);
131 /** Log a message using a varargs parameter list. Normal code should
134 VCOSPRE_ void VCOSPOST_ vcos_vlog_impl(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, va_list args) VCOS_FORMAT_ATTR_(printf, 3, 0);
136 /** Set the function which does the actual logging output.
137 * Passing in NULL causes the default logging function to be
140 VCOSPRE_ void VCOSPOST_ vcos_set_vlog_impl( VCOS_VLOG_IMPL_FUNC_T vlog_impl_func );
142 /** The default logging function, which is provided by each
146 VCOSPRE_ void VCOSPOST_ vcos_vlog_default_impl(const VCOS_LOG_CAT_T *cat, VCOS_LOG_LEVEL_T _level, const char *fmt, va_list args) VCOS_FORMAT_ATTR_(printf, 3, 0);
149 * Initialise the logging subsystem. This is called from
150 * vcos_init() so you don't normally need to call it.
152 VCOSPRE_ void VCOSPOST_ vcos_logging_init(void);
154 /** Register a logging category.
156 * @param name the name of this category.
157 * @param category the category to register.
159 VCOSPRE_ void VCOSPOST_ vcos_log_register(const char *name, VCOS_LOG_CAT_T *category);
161 /** Unregister a logging category.
163 VCOSPRE_ void VCOSPOST_ vcos_log_unregister(VCOS_LOG_CAT_T *category);
165 /** Return a default logging category, for people too lazy to create their own.
167 * Using the default category will be slow (there's an extra function
168 * call overhead). Don't do this in normal code.
170 VCOSPRE_ const VCOS_LOG_CAT_T * VCOSPOST_ vcos_log_get_default_category(void);
172 VCOSPRE_ void VCOSPOST_ vcos_set_log_options(const char *opt);
174 /** Set the logging level for a category at run time. Without this, the level
175 * will be that set by vcos_log_register from a platform-specific source.
177 * @param category the category to modify.
178 * @param level the new logging level for this category.
180 VCOS_STATIC_INLINE void vcos_log_set_level(VCOS_LOG_CAT_T *category, VCOS_LOG_LEVEL_T level)
182 category->level = level;
185 #define vcos_log_dump_mem(cat,label,addr,voidMem,numBytes) do { if (vcos_is_log_enabled(cat,VCOS_LOG_TRACE)) vcos_log_dump_mem_impl(cat,label,addr,voidMem,numBytes); } while (0)
187 void vcos_log_dump_mem_impl( const VCOS_LOG_CAT_T *cat,
194 * Platform specific hooks (optional).
196 #ifndef vcos_log_platform_init
197 #define vcos_log_platform_init() (void)0
200 #ifndef vcos_log_platform_register
201 #define vcos_log_platform_register(category) (void)0
204 #ifndef vcos_log_platform_unregister
205 #define vcos_log_platform_unregister(category) (void)0
208 /* VCOS_TRACE() - deprecated macro which just outputs in a debug build and
209 * is a no-op in a release build.
211 * _VCOS_LOG_X() - internal macro which outputs if the current level for the
212 * particular category is higher than the supplied message level.
215 #define VCOS_LOG_DFLT_CATEGORY vcos_log_get_default_category()
217 #define _VCOS_LEVEL(x) (x)
219 #define vcos_is_log_enabled(cat,_level) (_VCOS_LEVEL((cat)->level) >= _VCOS_LEVEL(_level))
221 #if defined(_VCOS_METAWARE) || defined(__GNUC__)
223 # if !defined(AMPUTATE_ALL_VCOS_LOGGING) && (!defined(NDEBUG) || defined(VCOS_ALWAYS_WANT_LOGGING))
224 # define VCOS_LOGGING_ENABLED
225 # define _VCOS_LOG_X(cat, _level, fmt...) do { if (vcos_is_log_enabled(cat,_level)) vcos_log_impl(cat,_level,fmt); } while (0)
226 # define _VCOS_VLOG_X(cat, _level, fmt, ap) do { if (vcos_is_log_enabled(cat,_level)) vcos_vlog_impl(cat,_level,fmt,ap); } while (0)
228 # define _VCOS_LOG_X(cat, _level, fmt...) (void)0
229 # define _VCOS_VLOG_X(cat, _level, fmt, ap) (void)0
234 # define vcos_log_error(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_ERROR, __VA_ARGS__)
235 # define vcos_log_warn(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_WARN, __VA_ARGS__)
236 # define vcos_log_info(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_INFO, __VA_ARGS__)
237 # define vcos_log_trace(...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_TRACE, __VA_ARGS__)
239 # define vcos_vlog_error(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_ERROR, fmt, ap)
240 # define vcos_vlog_warn(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_WARN, fmt, ap)
241 # define vcos_vlog_info(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_INFO, fmt, ap)
242 # define vcos_vlog_trace(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_TRACE, fmt, ap)
244 # define vcos_logc_error(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_ERROR, __VA_ARGS__)
245 # define vcos_logc_warn(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_WARN, __VA_ARGS__)
246 # define vcos_logc_info(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_INFO, __VA_ARGS__)
247 # define vcos_logc_trace(cat,...) _VCOS_LOG_X(cat, VCOS_LOG_TRACE, __VA_ARGS__)
249 # define vcos_vlogc_error(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_ERROR, fmt, ap)
250 # define vcos_vlogc_warn(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_WARN, fmt, ap)
251 # define vcos_vlogc_info(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_INFO, fmt, ap)
252 # define vcos_vlogc_trace(cat,fmt,ap) _VCOS_VLOG_X(cat, VCOS_LOG_TRACE, fmt, ap)
254 # define vcos_log(...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, __VA_ARGS__)
255 # define vcos_vlog(fmt,ap) _VCOS_VLOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, fmt, ap)
256 # define VCOS_ALERT(...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_ERROR, __VA_ARGS__)
257 # define VCOS_TRACE(...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, __VA_ARGS__)
260 * MS Visual Studio - pre 2005 does not grok variadic macros
262 #elif defined(_MSC_VER)
264 # if _MSC_VER >= 1400
266 # if !defined(AMPUTATE_ALL_VCOS_LOGGING) && (!defined(NDEBUG) || defined(VCOS_ALWAYS_WANT_LOGGING))
267 # define VCOS_LOGGING_ENABLED
268 # define _VCOS_LOG_X(cat, _level, fmt,...) do { if (vcos_is_log_enabled(cat,_level)) vcos_log_impl(cat, _level, fmt, __VA_ARGS__); } while (0)
270 # define _VCOS_LOG_X(cat, _level, fmt,...) (void)0
273 # define vcos_log_error(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_ERROR, fmt, __VA_ARGS__)
274 # define vcos_log_warn(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_WARN, fmt, __VA_ARGS__)
275 # define vcos_log_info(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_INFO, fmt, __VA_ARGS__)
276 # define vcos_log_trace(fmt,...) _VCOS_LOG_X(VCOS_LOG_CATEGORY, VCOS_LOG_TRACE, fmt, __VA_ARGS__)
278 # define vcos_logc_error(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_ERROR, fmt, __VA_ARGS__)
279 # define vcos_logc_warn(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_WARN, fmt, __VA_ARGS__)
280 # define vcos_logc_info(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_INFO, fmt, __VA_ARGS__)
281 # define vcos_logc_trace(cat,fmt,...) _VCOS_LOG_X(cat, VCOS_LOG_TRACE, fmt, __VA_ARGS__)
283 # define vcos_log(fmt,...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, fmt, __VA_ARGS__)
284 # define VCOS_ALERT(fmt,...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_ERROR, fmt, __VA_ARGS__)
285 # define VCOS_TRACE(fmt,...) _VCOS_LOG_X(VCOS_LOG_DFLT_CATEGORY, VCOS_LOG_INFO, fmt, __VA_ARGS__)
287 # else /* _MSC_VER >= 1400 */
289 /* do not define these */
291 # endif /* _MSC_VER >= 1400 */
297 #include "interface/vcos/vcos_cmd.h"
300 * These are the log sub-commands. They're exported here for user-mode apps which
301 * may want to call these, since the "log" command isn't registered for user-mode
302 * apps (vcdbg for example, has its own log command).
304 VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_assert_cmd( VCOS_CMD_PARAM_T *param );
305 VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_set_cmd( VCOS_CMD_PARAM_T *param );
306 VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_status_cmd( VCOS_CMD_PARAM_T *param );
307 VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_log_test_cmd( VCOS_CMD_PARAM_T *param );
313 #endif /* VCOS_LOGGING_H */