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"));
47 #define PCF(str) ((PROGMEM const char *)(F(str)))
52 // Max buffer size used in variable argument log function
53 #define MAX_LOG_V_BUFFER_SIZE (256)
59 DEBUG = 0, INFO, WARNING, ERROR, FATAL
62 #define DEBUG DLOG_DEBUG
63 #define INFO DLOG_INFO
64 #define WARNING DLOG_WARNING
65 #define ERROR DLOG_ERROR
66 #define FATAL DLOG_ERROR
70 #define OICLog(level,tag,mes) LOG(level,tag,mes)
71 #define OICLogv(level,tag,fmt,args...) LOG(level,tag,fmt,##args)
72 #elif defined(ANDROID) || defined(__linux__)
74 * Configure logger to use a context that defines a custom logger function
76 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
78 void OICLogConfig(oic_log_ctx_t *ctx);
81 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
86 * Called to Free dyamically allocated resources used with custom logging.
87 * Not necessary if default logging is used
90 void OICLogShutdown();
93 * Output a log string with the specified priority level.
94 * Only defined for Linux and Android
96 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
97 * @param tag - Module name
98 * @param logStr - log string
100 void OICLog(LogLevel level, const char *tag, const char *logStr);
103 * Output a variable argument list log string with the specified priority level.
104 * Only defined for Linux and Android
106 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
107 * @param tag - Module name
108 * @param format - variadic log string
110 void OICLogv(LogLevel level, const char *tag, const char *format, ...);
113 * Output the contents of the specified buffer (in hex) with the specified priority level.
115 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
116 * @param tag - Module name
117 * @param buffer - pointer to buffer of bytes
118 * @param bufferSize - max number of byte in buffer
120 void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16_t bufferSize);
121 #else // For arduino platforms
123 * Initialize the serial logger for Arduino
124 * Only defined for Arduino
129 * Output a log string with the specified priority level.
130 * Only defined for Arduino. Uses PROGMEM strings
132 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
133 * @param tag - Module name
134 * @param logStr - log string
136 void OICLog(LogLevel level, const char *tag, const int16_t lineNum, const char *logStr);
139 * Output the contents of the specified buffer (in hex) with the specified priority level.
141 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
142 * @param tag - Module name
143 * @param buffer - pointer to buffer of bytes
144 * @param bufferSize - max number of byte in buffer
146 void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16_t bufferSize);
149 * Output a variable argument list log string with the specified priority level.
151 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
152 * @param tag - Module name
153 * @param format - variadic log string
155 void OICLogv(LogLevel level, const char *tag, const int16_t lineNum, const char *format, ...);
161 #define OIC_LOG(level,tag,mes) LOG_(LOG_ID_MAIN, level, tag, mes)
162 #define OIC_LOG_V(level,tag,fmt,args...) LOG_(LOG_ID_MAIN, level, tag, fmt,##args)
163 #else // These macros are defined for Linux, Android, and Arduino
164 #define OIC_LOG_INIT() OICLogInit()
165 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OICLogBuffer((level), (tag), (buffer), (bufferSize))
168 #define OIC_LOG_CONFIG(ctx)
169 #define OIC_LOG_SHUTDOWN()
170 #define OIC_LOG(level, tag, logStr) OICLog((level), (tag), __LINE__, (logStr))
171 #define OIC_LOG_V(level, tag, ...)
173 #define OIC_LOG_CONFIG(ctx) OICLogConfig((ctx))
174 #define OIC_LOG_SHUTDOWN() OICLogShutdown()
175 #define OIC_LOG(level, tag, logStr) OICLog((level), (tag), (logStr))
176 #define OIC_LOG_V(level, tag, ...) OICLogv((level), (tag), __VA_ARGS__)
181 #define OIC_LOG_CONFIG(ctx)
182 #define OIC_LOG_SHUTDOWN()
183 #define OIC_LOG(level, tag, logStr)
184 #define OIC_LOG_V(level, tag, ...)
185 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
186 #define OIC_LOG_INIT()
191 #endif // __cplusplus
192 #endif /* _U_LOGGER_H_ */