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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 #define IOTIVITY_VERSION "1.2.1"
29 #include "logger_types.h"
32 #include <android/log.h>
33 #elif defined(__TIZEN__)
35 #elif defined(ARDUINO)
37 #include "avr/pgmspace.h"
46 * Helper for unused warning.
48 #define UNUSED(x) (void)(x)
50 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
51 // Example: OIC_LOG(INFO, TAG, PCF("Entering function"));
54 #define PCF(str) ((PROGMEM const char *)(F(str)))
56 #define PCF(str) ((PROGMEM const char *)(PSTR(str)))
62 // Max buffer size used in variable argument log function
63 #define MAX_LOG_V_BUFFER_SIZE (256)
76 /** @todo temporary work-around until better names with prefixes are used for the enum values. */
92 * Output the contents of the specified buffer (in hex) with the specified priority level.
94 * @param[in] level DEBUG, INFO, WARNING, ERROR, FATAL
95 * @param[in] tag Module name
96 * @param[in] buffer pointer to buffer of bytes
97 * @param[in] bufferSize max number of byte in buffer
99 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
101 #define OCLog(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes)
102 #define OCLogv(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, (level),tag,fmt,##args)
103 #elif !defined(ARDUINO)
105 * Configure logger to use a context that defines a custom logger function
107 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
109 void OCLogConfig(oc_log_ctx_t *ctx);
112 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
117 * Called to Free dyamically allocated resources used with custom logging.
118 * Not necessary if default logging is used
121 void OCLogShutdown();
124 * Output a variable argument list log string with the specified priority level.
125 * Only defined for Linux and Android
127 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
128 * @param tag - Module name
129 * @param format - variadic log string
131 void OCLogv(LogLevel level, const char * tag, const char * format, ...)
132 #if defined(__GNUC__)
133 __attribute__ ((format(printf, 3, 4)))
138 * Output a log string with the specified priority level.
139 * Only defined for Linux and Android
141 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
142 * @param tag - Module name
143 * @param logStr - log string
145 void OCLog(LogLevel level, const char * tag, const char * logStr);
148 * Output the contents of the specified buffer (in hex) with the specified priority level.
150 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
151 * @param tag - Module name
152 * @param buffer - pointer to buffer of bytes
153 * @param bufferSize - max number of byte in buffer
155 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
156 #else // For arduino platforms
158 * Initialize the serial logger for Arduino
159 * Only defined for Arduino
164 * Output a log string with the specified priority level.
165 * Only defined for Arduino. Uses PROGMEM strings
167 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
168 * @param tag - Module name
169 * @param lineNum- line Number
170 * @param logStr - log string
172 void OCLog(LogLevel level, PROGMEM const char *tag, const int lineNum,
173 PROGMEM const char *logStr);
176 * Output the contents of the specified buffer (in hex) with the specified priority level.
178 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
179 * @param tag - Module name
180 * @param buffer - pointer to buffer of bytes
181 * @param bufferSize - max number of byte in buffer
183 void OCLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, size_t bufferSize);
186 * Output a variable argument list log string with the specified priority level.
188 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
189 * @param tag - Module name
190 * @param lineNum- line Number
191 * @param format - variadic log string
193 void OCLogv(LogLevel level, PROGMEM const char *tag, const int lineNum,
194 PROGMEM const char *format, ...)
195 #if defined(__GNUC__)
196 __attribute__ ((format(printf, 4, 5)))
205 #define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes)
206 #define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt, ##args)
207 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)\
208 OCLogBuffer((level), (tag), (buffer), (bufferSize))
210 #else // These macros are defined for Linux, Android, Win32, and Arduino
212 #define OIC_LOG_INIT() OCLogInit()
216 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), PCF(tag), (buffer), (bufferSize))
217 // Don't define variable argument log function for Arduino
218 #define OIC_LOG_V(level, tag, format, ...) OCLogv((level), PCF(tag), __LINE__, PCF(format),__VA_ARGS__)
220 #define OIC_LOG_CONFIG(ctx)
221 #define OIC_LOG_SHUTDOWN()
222 #define OIC_LOG(level, tag, logStr) OCLog((level), PCF(tag), __LINE__, PCF(logStr))
223 #define OIC_LOG_V(level, tag, ...)
227 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), (tag), (buffer), (bufferSize))
228 #define OIC_LOG_CONFIG(ctx) OCLogConfig((ctx))
229 #define OIC_LOG_SHUTDOWN() OCLogShutdown()
230 #define OIC_LOG(level, tag, logStr) OCLog((level), (tag), (logStr))
231 // Define variable argument log function for Linux, Android, and Win32
232 #define OIC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
239 #define OIC_LOG_CONFIG(ctx)
240 #define OIC_LOG_SHUTDOWN()
241 #define OIC_LOG(level, tag, logStr)
242 #define OIC_LOG_V(level, tag, ...)
243 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
244 #define OIC_LOG_INIT()
249 #endif // __cplusplus
251 #endif /* LOGGER_H_ */