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.1.1"
29 #include "logger_types.h"
32 #include <android/log.h>
33 #elif defined(__TIZEN__)
35 #elif defined(ARDUINO)
37 #include "avr/pgmspace.h"
45 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
46 // Example: OIC_LOG(INFO, TAG, PCF("Entering function"));
49 #define PCF(str) ((PROGMEM const char *)(F(str)))
51 #define PCF(str) ((PROGMEM const char *)(PSTR(str)))
57 // Max buffer size used in variable argument log function
58 #define MAX_LOG_V_BUFFER_SIZE (256)
71 /** @todo temporary work-around until better names with prefixes are used for the enum values. */
87 * Output the contents of the specified buffer (in hex) with the specified priority level.
89 * @param[in] level DEBUG, INFO, WARNING, ERROR, FATAL
90 * @param[in] tag Module name
91 * @param[in] buffer pointer to buffer of bytes
92 * @param[in] bufferSize max number of byte in buffer
94 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
96 #define OCLog(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes)
97 #define OCLogv(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, (level),tag,fmt,##args)
98 #elif !defined(ARDUINO)
100 * Configure logger to use a context that defines a custom logger function
102 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
104 void OCLogConfig(oc_log_ctx_t *ctx);
107 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
112 * Called to Free dyamically allocated resources used with custom logging.
113 * Not necessary if default logging is used
116 void OCLogShutdown();
119 * Output a variable argument list log string with the specified priority level.
120 * Only defined for Linux and Android
122 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
123 * @param tag - Module name
124 * @param format - variadic log string
126 void OCLogv(LogLevel level, const char * tag, const char * format, ...)
127 #if defined(__GNUC__)
128 __attribute__ ((format(printf, 3, 4)))
133 * Output a log string with the specified priority level.
134 * Only defined for Linux and Android
136 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
137 * @param tag - Module name
138 * @param logStr - log string
140 void OCLog(LogLevel level, const char * tag, const char * logStr);
143 * Output the contents of the specified buffer (in hex) with the specified priority level.
145 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
146 * @param tag - Module name
147 * @param buffer - pointer to buffer of bytes
148 * @param bufferSize - max number of byte in buffer
150 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
151 #else // For arduino platforms
153 * Initialize the serial logger for Arduino
154 * Only defined for Arduino
159 * Output a log string with the specified priority level.
160 * Only defined for Arduino. Uses PROGMEM strings
162 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
163 * @param tag - Module name
164 * @param lineNum- line Number
165 * @param logStr - log string
167 void OCLog(LogLevel level, PROGMEM const char *tag, const int lineNum,
168 PROGMEM const char *logStr);
171 * Output the contents of the specified buffer (in hex) with the specified priority level.
173 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
174 * @param tag - Module name
175 * @param buffer - pointer to buffer of bytes
176 * @param bufferSize - max number of byte in buffer
178 void OCLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, size_t bufferSize);
181 * Output a variable argument list log string with the specified priority level.
183 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
184 * @param tag - Module name
185 * @param lineNum- line Number
186 * @param format - variadic log string
188 void OCLogv(LogLevel level, PROGMEM const char *tag, const int lineNum,
189 PROGMEM const char *format, ...)
190 #if defined(__GNUC__)
191 __attribute__ ((format(printf, 4, 5)))
200 #define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes)
201 #define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt, ##args)
202 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)\
203 OCLogBuffer((level), (tag), (buffer), (bufferSize))
205 #else // These macros are defined for Linux, Android, Win32, and Arduino
207 #define OIC_LOG_INIT() OCLogInit()
211 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), PCF(tag), (buffer), (bufferSize))
212 // Don't define variable argument log function for Arduino
213 #define OIC_LOG_V(level, tag, format, ...) OCLogv((level), PCF(tag), __LINE__, PCF(format),__VA_ARGS__)
215 #define OIC_LOG_CONFIG(ctx)
216 #define OIC_LOG_SHUTDOWN()
217 #define OIC_LOG(level, tag, logStr) OCLog((level), PCF(tag), __LINE__, PCF(logStr))
218 #define OIC_LOG_V(level, tag, ...)
222 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), (tag), (buffer), (bufferSize))
223 #define OIC_LOG_CONFIG(ctx) OCLogConfig((ctx))
224 #define OIC_LOG_SHUTDOWN() OCLogShutdown()
225 #define OIC_LOG(level, tag, logStr) OCLog((level), (tag), (logStr))
226 // Define variable argument log function for Linux, Android, and Win32
227 #define OIC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
234 #define OIC_LOG_CONFIG(ctx)
235 #define OIC_LOG_SHUTDOWN()
236 #define OIC_LOG(level, tag, logStr)
237 #define OIC_LOG_V(level, tag, ...)
238 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
239 #define OIC_LOG_INIT()
244 #endif // __cplusplus
246 #endif /* LOGGER_H_ */