1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
27 #include "oic_logger.h"
28 #include "oic_console_logger.h"
31 #include <android/log.h>
32 #elif defined(__TIZEN__)
36 #include "avr/pgmspace.h"
44 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
45 // Example: OC_LOG(INFO, TAG, PCF("Entering function"));
49 #define PCF(str) ((PROGMEM const char *)(F(str)))
51 #define PCF(str) ((PROGMEM const char *)(PSTR(str)))
58 // Max buffer size used in variable argument log function
59 #define MAX_LOG_V_BUFFER_SIZE (256)
65 DEBUG = 0, INFO, WARNING, ERROR, FATAL
68 #define DEBUG DLOG_DEBUG
69 #define INFO DLOG_INFO
70 #define WARNING DLOG_WARNING
71 #define ERROR DLOG_ERROR
72 #define FATAL DLOG_ERROR
76 #define OICLog(level,tag,mes) LOG(level,tag,mes)
77 #define OICLogv(level,tag,fmt,args...) LOG(level,tag,fmt,##args)
78 #elif defined(ANDROID) || defined(__linux__) || defined(__APPLE__)
80 * Configure logger to use a context that defines a custom logger function
82 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
84 void OICLogConfig(oic_log_ctx_t *ctx);
87 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
92 * Called to Free dyamically allocated resources used with custom logging.
93 * Not necessary if default logging is used
96 void OICLogShutdown();
99 * Output a log string with the specified priority level.
100 * Only defined for Linux and Android
102 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
103 * @param tag - Module name
104 * @param logStr - log string
106 void OICLog(LogLevel level, const char *tag, const char *logStr);
109 * Output a variable argument list log string with the specified priority level.
110 * Only defined for Linux and Android
112 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
113 * @param tag - Module name
114 * @param format - variadic log string
116 void OICLogv(LogLevel level, const char *tag, const char *format, ...);
119 * Output the contents of the specified buffer (in hex) with the specified priority level.
121 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
122 * @param tag - Module name
123 * @param buffer - pointer to buffer of bytes
124 * @param bufferSize - max number of byte in buffer
126 void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16_t bufferSize);
127 #else // For arduino platforms
129 * Initialize the serial logger for Arduino
130 * Only defined for Arduino
135 * Output a log string with the specified priority level.
136 * Only defined for Arduino. Uses PROGMEM strings
138 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
139 * @param tag - Module name
140 * @param logStr - log string
142 void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum,
143 PROGMEM const char *logStr);
146 * Output the contents of the specified buffer (in hex) with the specified priority level.
148 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
149 * @param tag - Module name
150 * @param buffer - pointer to buffer of bytes
151 * @param bufferSize - max number of byte in buffer
153 void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16_t bufferSize);
156 * Output a variable argument list log string with the specified priority level.
158 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
159 * @param tag - Module name
160 * @param format - variadic log string
162 void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum,
163 PROGMEM const char *format, ...);
169 #define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, level, tag, mes)
170 #define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt,##args)
171 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
172 #else // These macros are defined for Linux, Android, and Arduino
173 #define OIC_LOG_INIT() OICLogInit()
174 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)\
175 OICLogBuffer((level), (tag), (buffer), (bufferSize))
178 #define OIC_LOG_CONFIG(ctx)
179 #define OIC_LOG_SHUTDOWN()
180 #define OIC_LOG(level, tag, logStr) OICLog((level), PCF(tag), __LINE__, PCF(logStr))
181 #define OIC_LOG_V(level, tag, ...)
182 // To enable OIC_LOG_V, uncomment the below
183 //#define OIC_LOG_V(level, tag, format, ...) OICLogv((level), PCF(tag), __LINE__, PCF(format), __VA_ARGS__)
185 #define OIC_LOG_CONFIG(ctx) OICLogConfig((ctx))
186 #define OIC_LOG_SHUTDOWN() OICLogShutdown()
187 #define OIC_LOG(level, tag, logStr) OICLog((level), (tag), (logStr))
188 #define OIC_LOG_V(level, tag, ...) OICLogv((level), (tag), __VA_ARGS__)
193 #define OIC_LOG_CONFIG(ctx)
194 #define OIC_LOG_SHUTDOWN()
195 #define OIC_LOG(level, tag, logStr)
196 #define OIC_LOG_V(level, tag, ...)
197 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
198 #define OIC_LOG_INIT()
205 #endif // __cplusplus
206 #endif /* U_LOGGER_H_ */