Update Iot.js
[platform/upstream/iotjs.git] / src / iotjs_debuglog.h
1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef IOTJS_DEBUGLOG_H
17 #define IOTJS_DEBUGLOG_H
18
19
20 #ifdef ENABLE_DEBUG_LOG
21
22 #include <stdio.h>
23
24 extern int iotjs_debug_level;
25 extern FILE* iotjs_log_stream;
26 extern const char* iotjs_debug_prefix[4];
27
28 #define DBGLEV_ERR 1
29 #define DBGLEV_WARN 2
30 #define DBGLEV_INFO 3
31
32 #define IOTJS_DLOG(lvl, ...)                                        \
33   do {                                                              \
34     if (0 <= lvl && lvl <= iotjs_debug_level && iotjs_log_stream) { \
35       fprintf(iotjs_log_stream, "[%s] ", iotjs_debug_prefix[lvl]);  \
36       fprintf(iotjs_log_stream, __VA_ARGS__);                       \
37       fprintf(iotjs_log_stream, "\n");                              \
38       fflush(iotjs_log_stream);                                     \
39     }                                                               \
40   } while (0)
41 #define DLOG(...) IOTJS_DLOG(DBGLEV_ERR, __VA_ARGS__)
42 #define DDLOG(...) IOTJS_DLOG(DBGLEV_WARN, __VA_ARGS__)
43 #define DDDLOG(...) IOTJS_DLOG(DBGLEV_INFO, __VA_ARGS__)
44
45 /*
46   Use DLOG for errors, default you will see them
47   Use DDLOG for warnings, set iotjs_debug_level=2 to see them
48   USE DDDLOG for information, set iotjs_debug_level=3 to see them
49 */
50
51 #else /* !ENABLE_DEBUG_LOG */
52
53 #define IOTJS_DLOG(...)
54 #define DLOG(...)
55 #define DDLOG(...)
56 #define DDDLOG(...)
57
58 #endif /* ENABLE_DEBUG_LOG */
59
60
61 void init_debug_settings();
62 void release_debug_settings();
63
64
65 #endif /* IOTJS_DEBUGLOG_H */