log_util.h
Go to the documentation of this file.
1 /*!**********************************************************************
2  *
3  * @copyright Copyright (C) 2016 Siemens Aktiengesellschaft.\n
4  * All rights reserved.
5  *
6  *************************************************************************
7  *
8  * @file log_util.h
9  * @date Jun 27, 2016
10  * @brief Log utility module header file.
11  *
12  * This utility module defines macros and functions for logging purposes.
13  *
14  ************************************************************************/
15 
16 #ifndef LOG_UTIL_H_
17 #define LOG_UTIL_H_
18 
19 // Definition of default and module specific log level.
20 // Modules log level overrides the default log level.
21 // This log level is set during compile time check and has no runtime overhead.
22 
23 #if defined(MCL_LOG_UTIL_LEVEL)
24 #define ZF_LOG_LEVEL MCL_LOG_UTIL_LEVEL
25 #elif defined(LOG_UTIL_DEFAULT_LEVEL)
26 #define ZF_LOG_DEF_LEVEL LOG_UTIL_DEFAULT_LEVEL
27 #else
28 
29 #ifdef NDEBUG
30 #define MCL_LOG_UTIL_LEVEL LOG_UTIL_LEVEL_INFO
31 #else
32 #define MCL_LOG_UTIL_LEVEL LOG_UTIL_LEVEL_INFO
33 #endif
34 
35 #define ZF_LOG_LEVEL MCL_LOG_UTIL_LEVEL
36 
37 #endif
38 
39 // Definition of logging tags
40 #define LOG_UTIL_TAG_DEFAULT "[..]"
41 #define LOG_UTIL_TAG_ENTRY "[->]"
42 #define LOG_UTIL_TAG_LEAVE "[<-]"
43 #define ZF_LOG_DEF_TAG LOG_UTIL_TAG_DEFAULT
44 
45 #include "zf_log/zf_log.h"
46 
47 #define LOG_UTIL_LEVEL_VERBOSE ZF_LOG_VERBOSE
48 #define LOG_UTIL_LEVEL_DEBUG ZF_LOG_DEBUG
49 #define LOG_UTIL_LEVEL_INFO ZF_LOG_INFO
50 #define LOG_UTIL_LEVEL_WARN ZF_LOG_WARN
51 #define LOG_UTIL_LEVEL_ERROR ZF_LOG_ERROR
52 #define LOG_UTIL_LEVEL_FATAL ZF_LOG_FATAL
53 #define LOG_UTIL_LEVEL_NONE ZF_LOG_NONE
54 
55 // Definition of logging macros
56 // MCL_VERBOSE
57 #define MCL_VERBOSE(...) ZF_LOGV(__VA_ARGS__)
58 #define MCL_VERBOSE_STRING(data) ZF_LOGV_STR((data))
59 #define MCL_VERBOSE_MEMORY(data, data_size, ...) ZF_LOGV_MEM(data, data_size, __VA_ARGS__)
60 
61 #if ZF_LOG_ENABLED(LOG_UTIL_LEVEL_VERBOSE)
62 #define VERBOSE_ENTRY(...) ZF_LOG_WRITE(LOG_UTIL_LEVEL_VERBOSE, LOG_UTIL_TAG_ENTRY, __VA_ARGS__);
63 #define VERBOSE_LEAVE(...) ZF_LOG_WRITE(LOG_UTIL_LEVEL_VERBOSE, LOG_UTIL_TAG_LEAVE, __VA_ARGS__)
64 #else
65 #define VERBOSE_ENTRY(...)
66 #define VERBOSE_LEAVE(...) _ZF_LOG_UNUSED(__VA_ARGS__)
67 #endif
68 
69 // MCL_DEBUG
70 #define MCL_DEBUG(...) ZF_LOGD(__VA_ARGS__)
71 #define MCL_DEBUG_STRING(data) ZF_LOGD_STR((data))
72 #define MCL_DEBUG_MEMORY(data, data_size, ...) ZF_LOGD_MEM(data, data_size, __VA_ARGS__)
73 
74 #if ZF_LOG_ENABLED(LOG_UTIL_LEVEL_DEBUG)
75 #define DEBUG_ENTRY(...) ZF_LOG_WRITE(LOG_UTIL_LEVEL_DEBUG, LOG_UTIL_TAG_ENTRY, __VA_ARGS__);
76 #define DEBUG_LEAVE(...) ZF_LOG_WRITE(LOG_UTIL_LEVEL_DEBUG, LOG_UTIL_TAG_LEAVE, __VA_ARGS__)
77 #define DEBUG_MEMORY_ENTRY(...) ZF_LOG_WRITE_MEM(LOG_UTIL_LEVEL_DEBUG, LOG_UTIL_TAG_ENTRY, __VA_ARGS__)
78 #define DEBUG_MEMORY_LEAVE(...) ZF_LOG_WRITE_MEM(LOG_UTIL_LEVEL_DEBUG, LOG_UTIL_TAG_LEAVE, __VA_ARGS__)
79 #else
80 #define DEBUG_ENTRY(...)
81 #define DEBUG_LEAVE(...) _ZF_LOG_UNUSED(__VA_ARGS__)
82 #define DEBUG_MEMORY_ENTRY(...) _ZF_LOG_UNUSED(__VA_ARGS__)
83 #define DEBUG_MEMORY_LEAVE(...) _ZF_LOG_UNUSED(__VA_ARGS__)
84 #endif
85 
86 // MCL_INFO
87 #define MCL_INFO(...) ZF_LOGI(__VA_ARGS__)
88 #define MCL_INFO_STRING(data) ZF_LOGI_STR((data))
89 #define MCL_INFO_MEMORY(data, data_size, ...) ZF_LOGI_MEM(data, data_size, __VA_ARGS__)
90 
91 // MCL_WARN
92 #define MCL_WARN(...) ZF_LOGW(__VA_ARGS__)
93 #define MCL_WARN_STRING(data) ZF_LOGW_STR((data))
94 #define MCL_WARN_MEMORY(data, data_size, ...) ZF_LOGW_MEM(data, data_size, __VA_ARGS__)
95 
96 // ERROR
97 #define MCL_ERROR(...) ZF_LOGE(__VA_ARGS__)
98 #define MCL_ERROR_STRING(data) ZF_LOGE_STR((data))
99 #define MCL_ERROR_MEMORY(data, data_size, ...) ZF_LOGE_MEM(data, data_size, __VA_ARGS__)
100 
101 // MCL_FATAL
102 #define MCL_FATAL(...) ZF_LOGF(__VA_ARGS__)
103 #define MCL_FATAL_STRING(data) ZF_LOGF_STR((data))
104 #define MCL_FATAL_MEMORY(data, data_size, ...) ZF_LOGF_MEM(data, data_size, __VA_ARGS__)
105 
106 #endif //LOG_UTIL_H_
107