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)
81 * Output the contents of the specified buffer (in hex) with the specified priority level.
83 * @param[in] level DEBUG, INFO, WARNING, ERROR, FATAL
84 * @param[in] tag Module name
85 * @param[in] buffer pointer to buffer of bytes
86 * @param[in] bufferSize max number of byte in buffer
88 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
90 #define OCLog(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes)
91 #define OCLogv(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, (level),tag,fmt,##args)
92 #elif defined(ANDROID) || defined(__linux__) || defined(__APPLE__)
94 * Configure logger to use a context that defines a custom logger function
96 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
98 void OCLogConfig(oc_log_ctx_t *ctx);
101 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
106 * Called to Free dyamically allocated resources used with custom logging.
107 * Not necessary if default logging is used
110 void OCLogShutdown();
113 * Output a variable argument list log string with the specified priority level.
114 * Only defined for Linux and Android
116 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
117 * @param tag - Module name
118 * @param format - variadic log string
120 void OCLogv(LogLevel level, const char * tag, const char * format, ...)
121 #if defined(__GNUC__)
122 __attribute__ ((format(printf, 3, 4)))
127 * Output a log string with the specified priority level.
128 * Only defined for Linux and Android
130 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
131 * @param tag - Module name
132 * @param logStr - log string
134 void OCLog(LogLevel level, const char * tag, const char * logStr);
137 * Output the contents of the specified buffer (in hex) with the specified priority level.
139 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
140 * @param tag - Module name
141 * @param buffer - pointer to buffer of bytes
142 * @param bufferSize - max number of byte in buffer
144 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
145 #else // For arduino platforms
147 * Initialize the serial logger for Arduino
148 * Only defined for Arduino
153 * Output a log string with the specified priority level.
154 * Only defined for Arduino. Uses PROGMEM strings
156 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
157 * @param tag - Module name
158 * @param lineNum- line Number
159 * @param logStr - log string
161 void OCLog(LogLevel level, PROGMEM const char *tag, const int lineNum,
162 PROGMEM const char *logStr);
165 * Output the contents of the specified buffer (in hex) with the specified priority level.
167 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
168 * @param tag - Module name
169 * @param buffer - pointer to buffer of bytes
170 * @param bufferSize - max number of byte in buffer
172 void OCLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, size_t bufferSize);
175 * Output a variable argument list log string with the specified priority level.
177 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
178 * @param tag - Module name
179 * @param lineNum- line Number
180 * @param format - variadic log string
182 void OCLogv(LogLevel level, PROGMEM const char *tag, const int lineNum,
183 PROGMEM const char *format, ...)
184 #if defined(__GNUC__)
185 __attribute__ ((format(printf, 4, 5)))
194 #define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes)
195 #define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt, ##args)
196 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)\
197 OCLogBuffer((level), (tag), (buffer), (bufferSize))
199 #else // These macros are defined for Linux, Android, and Arduino
201 #define OIC_LOG_INIT() OCLogInit()
205 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), PCF(tag), (buffer), (bufferSize))
206 // Don't define variable argument log function for Arduino
207 #define OIC_LOG_V(level, tag, format, ...) OCLogv((level), PCF(tag), __LINE__, PCF(format),__VA_ARGS__)
209 #define OIC_LOG_CONFIG(ctx)
210 #define OIC_LOG_SHUTDOWN()
211 #define OIC_LOG(level, tag, logStr) OCLog((level), PCF(tag), __LINE__, PCF(logStr))
212 #define OIC_LOG_V(level, tag, ...)
216 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), (tag), (buffer), (bufferSize))
217 #define OIC_LOG_CONFIG(ctx) OCLogConfig((ctx))
218 #define OIC_LOG_SHUTDOWN() OCLogShutdown()
219 #define OIC_LOG(level, tag, logStr) OCLog((level), (tag), (logStr))
220 // Define variable argument log function for Linux and Android
221 #define OIC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
228 #define OIC_LOG_CONFIG(ctx)
229 #define OIC_LOG_SHUTDOWN()
230 #define OIC_LOG(level, tag, logStr)
231 #define OIC_LOG_V(level, tag, ...)
232 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
233 #define OIC_LOG_INIT()
238 #endif // __cplusplus
240 #endif /* LOGGER_H_ */