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 "logger_types.h"
30 #include <android/log.h>
31 #elif defined(__TIZEN__)
33 #elif defined(ARDUINO)
35 #include "avr/pgmspace.h"
43 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
44 // Example: OIC_LOG(INFO, TAG, PCF("Entering function"));
47 #define PCF(str) ((PROGMEM const char *)(F(str)))
49 #define PCF(str) ((PROGMEM const char *)(PSTR(str)))
55 // Max buffer size used in variable argument log function
56 #define MAX_LOG_V_BUFFER_SIZE (256)
78 #define OCLog(level,tag,mes)
79 #define OCLogv(level,tag,fmt,args...)
80 #elif defined(ANDROID) || defined(__linux__) || defined(__APPLE__)
82 * Configure logger to use a context that defines a custom logger function
84 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
86 void OCLogConfig(oc_log_ctx_t *ctx);
89 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
94 * Called to Free dyamically allocated resources used with custom logging.
95 * Not necessary if default logging is used
101 * Output a variable argument list log string with the specified priority level.
102 * Only defined for Linux and Android
104 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
105 * @param tag - Module name
106 * @param format - variadic log string
108 void OCLogv(LogLevel level, const char * tag, const char * format, ...)
109 #if defined(__GNUC__)
110 __attribute__ ((format(printf, 3, 4)))
115 * Output a log string with the specified priority level.
116 * Only defined for Linux and Android
118 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
119 * @param tag - Module name
120 * @param logStr - log string
122 void OCLog(LogLevel level, const char * tag, const char * logStr);
125 * Output the contents of the specified buffer (in hex) with the specified priority level.
127 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
128 * @param tag - Module name
129 * @param buffer - pointer to buffer of bytes
130 * @param bufferSize - max number of byte in buffer
132 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
133 #else // For arduino platforms
135 * Initialize the serial logger for Arduino
136 * Only defined for Arduino
141 * Output a log string with the specified priority level.
142 * Only defined for Arduino. Uses PROGMEM strings
144 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
145 * @param tag - Module name
146 * @param lineNum- line Number
147 * @param logStr - log string
149 void OCLog(LogLevel level, PROGMEM const char *tag, const int lineNum,
150 PROGMEM const char *logStr);
153 * Output the contents of the specified buffer (in hex) with the specified priority level.
155 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
156 * @param tag - Module name
157 * @param buffer - pointer to buffer of bytes
158 * @param bufferSize - max number of byte in buffer
160 void OCLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, size_t bufferSize);
163 * Output a variable argument list log string with the specified priority level.
165 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
166 * @param tag - Module name
167 * @param lineNum- line Number
168 * @param format - variadic log string
170 void OCLogv(LogLevel level, PROGMEM const char *tag, const int lineNum,
171 PROGMEM const char *format, ...)
172 #if defined(__GNUC__)
173 __attribute__ ((format(printf, 4, 5)))
182 #define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, (level), (tag), mes)
183 #define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt, ##args)
184 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
186 #else // These macros are defined for Linux, Android, and Arduino
188 #define OIC_LOG_INIT() OCLogInit()
192 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), PCF(tag), (buffer), (bufferSize))
193 // Don't define variable argument log function for Arduino
194 #define OIC_LOG_V(level, tag, format, ...) OCLogv((level), PCF(tag), __LINE__, PCF(format),__VA_ARGS__)
196 #define OIC_LOG_CONFIG(ctx)
197 #define OIC_LOG_SHUTDOWN()
198 #define OIC_LOG(level, tag, logStr) OCLog((level), PCF(tag), __LINE__, PCF(logStr))
199 #define OIC_LOG_V(level, tag, ...)
203 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), (tag), (buffer), (bufferSize))
204 #define OIC_LOG_CONFIG(ctx) OCLogConfig((ctx))
205 #define OIC_LOG_SHUTDOWN() OCLogShutdown()
206 #define OIC_LOG(level, tag, logStr) OCLog((level), (tag), (logStr))
207 // Define variable argument log function for Linux and Android
208 #define OIC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
215 #define OIC_LOG_CONFIG(ctx)
216 #define OIC_LOG_SHUTDOWN()
217 #define OIC_LOG(level, tag, logStr)
218 #define OIC_LOG_V(level, tag, ...)
219 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
220 #define OIC_LOG_INIT()
225 #endif // __cplusplus
227 #endif /* LOGGER_H_ */