Modifying version number for building on tizen 3.0
[platform/upstream/iotivity.git] / resource / csdk / logger / include / logger.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef LOGGER_H_
22 #define LOGGER_H_
23
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdarg.h>
27 #include "oc_logger.h"
28 #include "oc_console_logger.h"
29
30 #ifdef __ANDROID__
31     #include <android/log.h>
32 #elif defined ARDUINO
33     #include "Arduino.h"
34     #include <avr/pgmspace.h>
35 #endif
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 // Use the PCF macro to wrap strings stored in FLASH on the Arduino
42 // Example:  OC_LOG(INFO, TAG, PCF("Entering function"));
43 #ifdef ARDUINO
44     #define PCF(str)  ((PROGMEM const char *)(F(str)))
45 #else
46     #define PCF(str) str
47 #endif
48
49 // Max buffer size used in variable argument log function
50 #define MAX_LOG_V_BUFFER_SIZE (256)
51
52 // Log levels
53 typedef enum {
54     DEBUG = 0,
55     INFO,
56     WARNING,
57     ERROR,
58     FATAL
59 } LogLevel;
60
61
62 #ifndef ARDUINO
63
64     /**
65      * Configure logger to use a context that defines a custom logger function
66      *
67      * @param ctx - pointer to oc_log_ctx_t struct that defines custom logging functions
68      */
69     void OCLogConfig(oc_log_ctx_t *ctx);
70
71     /**
72      * Initialize the logger.  Optional on Android and Linux.  Configures serial port on Arduino
73      */
74     void OCLogInit();
75
76     /**
77      * Called to Free dyamically allocated resources used with custom logging.
78      * Not necessary if default logging is used
79      *
80      */
81     void OCLogShutdown();
82
83     /**
84      * Output a variable argument list log string with the specified priority level.
85      * Only defined for Linux and Android
86      *
87      * @param level  - DEBUG, INFO, WARNING, ERROR, FATAL
88      * @param tag    - Module name
89      * @param format - variadic log string
90      */
91     void OCLogv(LogLevel level, const char * tag, const char * format, ...);
92
93     /**
94      * Output a log string with the specified priority level.
95      * Only defined for Linux and Android
96      *
97      * @param level  - DEBUG, INFO, WARNING, ERROR, FATAL
98      * @param tag    - Module name
99      * @param logStr - log string
100      */
101     void OCLog(LogLevel level, const char * tag, const char * logStr);
102
103     /**
104      * Output the contents of the specified buffer (in hex) with the specified priority level.
105      *
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
110      */
111     void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize);
112 #else
113     /**
114      * Initialize the serial logger for Arduino
115      * Only defined for Arduino
116      */
117     void OCLogInit();
118
119     /**
120      * Output a log string with the specified priority level.
121      * Only defined for Arduino.  Uses PROGMEM strings
122      *
123      * @param level  - DEBUG, INFO, WARNING, ERROR, FATAL
124      * @param tag    - Module name
125      * @param logStr - log string
126      */
127     void OCLog(LogLevel level, PROGMEM const char * tag, PROGMEM const char * logStr);
128
129     /**
130      * Output the contents of the specified buffer (in hex) with the specified priority level.
131      *
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
136      */
137     void OCLogBuffer(LogLevel level, PROGMEM const char * tag, const uint8_t * buffer, uint16_t bufferSize);
138
139     /**
140      * Output a variable argument list log string with the specified priority level.
141      *
142      * @param level  - DEBUG, INFO, WARNING, ERROR, FATAL
143      * @param tag    - Module name
144      * @param format - variadic log string
145      */
146     void OCLogv(LogLevel level, const char * tag, const char * format, ...);
147 #endif
148
149 #ifdef TB_LOG
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))
154
155     #ifdef ARDUINO
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__)
162     #else
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__)
167     #endif
168
169 #else
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()
176 #endif
177
178 #ifdef __cplusplus
179 }
180 #endif // __cplusplus
181
182 #endif /* LOGGER_H_ */