1 //******************************************************************
3 // Copyright 2014 Intel Corporation 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
33 #include <android/log.h>
36 #include <avr/pgmspace.h>
39 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
40 // Example: OC_LOG(INFO, TAG, PCF("Entering function"));
42 #define PCF(str) ((const prog_char*)(F(str)))
47 // Max buffer size used in variable argument log function
48 #define MAX_LOG_V_BUFFER_SIZE (256)
60 #if defined(__ANDROID__) || defined(__linux__)
62 * Output a variable argument list log string with the specified priority level.
63 * Only defined for Linux and Android
65 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
66 * @param tag - Module name
67 * @param format - variadic log string
69 void OCLogv(LogLevel level, const char * tag, const char * format, ...);
72 * Output a log string with the specified priority level.
73 * Only defined for Linux and Android
75 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
76 * @param tag - Module name
77 * @param logStr - log string
79 void OCLog(LogLevel level, const char * tag, const char * logStr);
82 * Output the contents of the specified buffer (in hex) with the specified priority level.
84 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
85 * @param tag - Module name
86 * @param buffer - pointer to buffer of bytes
87 * @param bufferSize - max number of byte in buffer
89 void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
94 * Initialize the serial logger for Arduino
95 * Only defined for Arduino
100 * Output a log string with the specified priority level.
101 * Only defined for Arduino. Uses PROGMEM strings
103 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
104 * @param tag - Module name
105 * @param logStr - log string
107 void OCLog(LogLevel level, const prog_char * tag, const prog_char * logStr);
110 * Output the contents of the specified buffer (in hex) with the specified priority level.
112 * @param level - DEBUG, INFO, WARNING, ERROR, FATAL
113 * @param tag - Module name
114 * @param buffer - pointer to buffer of bytes
115 * @param bufferSize - max number of byte in buffer
117 void OCLogBuffer(LogLevel level, const prog_char * tag, const uint8_t * buffer, uint16_t bufferSize);
121 // These macros are defined for Linux, Android, and Arduino
122 #define OC_LOG(level, tag, logStr) OCLog((level), (tag), (logStr))
123 #define OC_LOG_BUFFER(level, tag, buffer, bufferSize) OCLogBuffer((level), (tag), (buffer), (bufferSize))
126 // Use full namespace for logInit to avoid function name collision
127 #define OC_LOG_INIT() OCLogInit()
128 // Don't define variable argument log function for Arduino
129 #define OC_LOG_V(level, tag, ...)
131 // Don't define LOG_INIT for Linux and Android
132 #define OC_LOG_INIT()
133 // Define variable argument log function for Linux and Android
134 #define OC_LOG_V(level, tag, ...) OCLogv((level), (tag), __VA_ARGS__)
138 #define OC_LOG(level, tag, logStr)
139 #define OC_LOG_V(level, tag, ...)
140 #define OC_LOG_BUFFER(level, tag, buffer, bufferSize)
141 #define OC_LOG_INIT()
146 #endif // __cplusplus
148 #endif /* LOGGER_H_ */