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>
34 #include <avr/pgmspace.h>
42 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
43 // Example: OC_LOG(INFO, TAG, PCF("Entering function"));
45 #define PCF(str) ((PROGMEM const char *)(F(str)))
50 // Max buffer size used in variable argument log function
51 #define MAX_LOG_V_BUFFER_SIZE (256)
56 DEBUG = 0, INFO, WARNING, ERROR, FATAL
62 * Configure logger to use a context that defines a custom logger function
64 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
66 void OICLogConfig(oic_log_ctx_t *ctx);
69 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
74 * Called to Free dyamically allocated resources used with custom logging.
75 * Not necessary if default logging is used
78 void OICLogShutdown();
81 * Output a log string with the specified priority level.
82 * Only defined for Linux and Android
84 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
85 * @param tag - Module name
86 * @param logStr - log string
88 void OICLog(LogLevel level, const char * tag, const char * logStr);
91 * Output a variable argument list log string with the specified priority level.
92 * Only defined for Linux and Android
94 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
95 * @param tag - Module name
96 * @param format - variadic log string
98 void OICLogv(LogLevel level, const char * tag, const char * format, ...);
101 * Output the contents of the specified buffer (in hex) with the specified priority level.
103 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
104 * @param tag - Module name
105 * @param buffer - pointer to buffer of bytes
106 * @param bufferSize - max number of byte in buffer
108 void OICLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
111 * Initialize the serial logger for Arduino
112 * Only defined for Arduino
117 * Output a log string with the specified priority level.
118 * Only defined for Arduino. Uses PROGMEM strings
120 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
121 * @param tag - Module name
122 * @param logStr - log string
124 void OICLog(LogLevel level, PROGMEM const char * tag, PROGMEM const char * logStr);
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, PROGMEM const char * tag, const uint8_t * buffer, uint16_t bufferSize);
137 * Output a variable argument list log string with the specified priority level.
139 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
140 * @param tag - Module name
141 * @param format - variadic log string
143 void OICLogv(LogLevel level, const char * tag, const char * format, ...);
147 // These macros are defined for Linux, Android, and Arduino
148 #define OIC_LOG_INIT() OICLogInit()
149 #define OIC_LOG(level, tag, logStr) OICLog((level), (tag), (logStr))
150 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize) OICLogBuffer((level), (tag), (buffer), (bufferSize))
153 #define OIC_LOG_CONFIG(ctx)
154 #define OIC_LOG_SHUTDOWN()
155 // Use full namespace for logInit to avoid function name collision
156 #define OIC_LOG_INIT() OICLogInit()
157 // Don't define variable argument log function for Arduino
158 #define OIC_LOG_V(level, tag, ...) OICLogv((level), (tag), __VA_ARGS__)
160 #define OIC_LOG_CONFIG(ctx) OICLogConfig((ctx))
161 #define OIC_LOG_SHUTDOWN() OICLogShutdown()
162 // Define variable argument log function for Linux and Android
163 #define OIC_LOG_V(level, tag, ...) OICLogv((level), (tag), __VA_ARGS__)
167 #define OIC_LOG_CONFIG(ctx)
168 #define OIC_LOG_SHUTDOWN()
169 #define OIC_LOG(level, tag, logStr)
170 #define OIC_LOG_V(level, tag, ...)
171 #define OIC_LOG_BUFFER(level, tag, buffer, bufferSize)
172 #define OIC_LOG_INIT()
177 #endif // __cplusplus
178 #endif /* _U_LOGGER_H_ */