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 "oc_logger.h"
28 #include "oc_console_logger.h"
31 #include <android/log.h>
34 #include <avr/pgmspace.h>
41 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
42 // Example: OC_LOG(INFO, TAG, PCF("Entering function"));
44 #define PCF(str) ((PROGMEM const char *)(F(str)))
49 // Max buffer size used in variable argument log function
50 #define MAX_LOG_V_BUFFER_SIZE (256)
65 * Configure logger to use a context that defines a custom logger function
67 * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
69 void OCLogConfig(oc_log_ctx_t *ctx);
72 * Initialize the logger. Optional on Android and Linux. Configures serial port on Arduino
77 * Called to Free dyamically allocated resources used with custom logging.
78 * Not necessary if default logging is used
84 * Output a variable argument list log string with the specified priority level.
85 * Only defined for Linux and Android
87 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
88 * @param tag - Module name
89 * @param format - variadic log string
91 void OCLogv(LogLevel level, const char * tag, const char * format, ...);
94 * Output a log string with the specified priority level.
95 * Only defined for Linux and Android
97 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
98 * @param tag - Module name
99 * @param logStr - log string
101 void OCLog(LogLevel level, const char * tag, const char * logStr);
104 * Output the contents of the specified buffer (in hex) with the specified priority level.
106 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
107 * @param tag - Module name
108 * @param buffer - pointer to buffer of bytes
109 * @param bufferSize - max number of byte in buffer
111 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
114 * Initialize the serial logger for Arduino
115 * Only defined for Arduino
120 * Output a log string with the specified priority level.
121 * Only defined for Arduino. Uses PROGMEM strings
123 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
124 * @param tag - Module name
125 * @param logStr - log string
127 void OCLog(LogLevel level, PROGMEM const char * tag, PROGMEM const char * logStr);
130 * Output the contents of the specified buffer (in hex) with the specified priority level.
132 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
133 * @param tag - Module name
134 * @param buffer - pointer to buffer of bytes
135 * @param bufferSize - max number of byte in buffer
137 void OCLogBuffer(LogLevel level, PROGMEM const char * tag, const uint8_t * buffer, uint16_t bufferSize);
140 * Output a variable argument list log string with the specified priority level.
142 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
143 * @param tag - Module name
144 * @param format - variadic log string
146 void OCLogv(LogLevel level, const char * tag, const char * format, ...);
150 // These macros are defined for Linux, Android, and Arduino
151 #define OC_LOG_INIT() OCLogInit()
152 #define OC_LOG(level, tag, logStr) OCLog((level), (tag), (logStr))
153 #define OC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), (tag), (buffer), (bufferSize))
156 #define OC_LOG_CONFIG(ctx)
157 #define OC_LOG_SHUTDOWN()
158 // Use full namespace for logInit to avoid function name collision
159 #define OC_LOG_INIT() OCLogInit()
160 // Don't define variable argument log function for Arduino
161 #define OC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
163 #define OC_LOG_CONFIG(ctx) OCLogConfig((ctx))
164 #define OC_LOG_SHUTDOWN() OCLogShutdown()
165 // Define variable argument log function for Linux and Android
166 #define OC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
170 #define OC_LOG_CONFIG(ctx)
171 #define OC_LOG_SHUTDOWN()
172 #define OC_LOG(level, tag, logStr)
173 #define OC_LOG_V(level, tag, ...)
174 #define OC_LOG_BUFFER(level, tag, buffer, bufferSize)
175 #define OC_LOG_INIT()
180 #endif // __cplusplus
182 #endif /* LOGGER_H_ */