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)
73 DEBUG = 0, INFO, WARNING, ERROR, FATAL
78 #define OC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, level, tag, mes)
79 #define OC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt,##args)
80 #define OC_LOG_BUFFER(level, tag, buffer, bufferSize)
84 #define OICLog(level,tag,mes) LOG(level,tag,mes)
85 #define OICLogv(level,tag,fmt,args...) LOG(level,tag,fmt,##args)
86 #elif defined(ANDROID) || defined(__linux__) || defined(__APPLE__)
88 * Configure logger to use a context that defines a custom logger function
90 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
92 void OICLogConfig(oic_log_ctx_t *ctx);
95 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
100 * Called to Free dyamically allocated resources used with custom logging.
101 * Not necessary if default logging is used
104 void OICLogShutdown();
107 * Output a log string with the specified priority level.
108 * Only defined for Linux and Android
110 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
111 * @param tag - Module name
112 * @param logStr - log string
114 void OICLog(LogLevel level, const char *tag, const char *logStr);
117 * Output a variable argument list log string with the specified priority level.
118 * Only defined for Linux and Android
120 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
121 * @param tag - Module name
122 * @param format - variadic log string
124 void OICLogv(LogLevel level, const char *tag, const char *format, ...);
127 * Output the contents of the specified buffer (in hex) with the specified priority level.
129 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
130 * @param tag - Module name
131 * @param buffer - pointer to buffer of bytes
132 * @param bufferSize - max number of byte in buffer
134 void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16_t bufferSize);
135 #else // For arduino platforms
137 * Initialize the serial logger for Arduino
138 * Only defined for Arduino
143 * Output a log string with the specified priority level.
144 * Only defined for Arduino. Uses PROGMEM strings
146 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
147 * @param tag - Module name
148 * @param logStr - log string
150 void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum,
151 PROGMEM const char *logStr);
154 * Output the contents of the specified buffer (in hex) with the specified priority level.
156 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
157 * @param tag - Module name
158 * @param buffer - pointer to buffer of bytes
159 * @param bufferSize - max number of byte in buffer
161 void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16_t bufferSize);
164 * Output a variable argument list log string with the specified priority level.
166 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
167 * @param tag - Module name
168 * @param format - variadic log string
170 void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum,
171 PROGMEM const char *format, ...);
177 #define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, level, tag, mes)
178 #define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt,##args)
179 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
180 #else // These macros are defined for Linux, Android, and Arduino
181 #define OIC_LOG_INIT() OICLogInit()
182 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)\
183 OICLogBuffer((level), (tag), (buffer), (bufferSize))
186 #define OIC_LOG_CONFIG(ctx)
187 #define OIC_LOG_SHUTDOWN()
188 #define OIC_LOG(level, tag, logStr) OICLog((level), PCF(tag), __LINE__, PCF(logStr))
189 #define OIC_LOG_V(level, tag, ...)
190 // To enable OIC_LOG_V, uncomment the below
191 //#define OIC_LOG_V(level, tag, format, ...) OICLogv((level), PCF(tag), __LINE__, PCF(format), __VA_ARGS__)
193 #define OIC_LOG_CONFIG(ctx) OICLogConfig((ctx))
194 #define OIC_LOG_SHUTDOWN() OICLogShutdown()
195 #define OIC_LOG(level, tag, logStr) OICLog((level), (tag), (logStr))
196 #define OIC_LOG_V(level, tag, ...) OICLogv((level), (tag), __VA_ARGS__)
201 #define OIC_LOG_CONFIG(ctx)
202 #define OIC_LOG_SHUTDOWN()
203 #define OIC_LOG(level, tag, logStr)
204 #define OIC_LOG_V(level, tag, ...)
205 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
206 #define OIC_LOG_INIT()
213 #endif // __cplusplus
214 #endif /* U_LOGGER_H_ */