merge with master
[platform/framework/web/download-provider.git] / agent / include / download-agent-debug.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _Download_Agent_Debug_H
18 #define _Download_Agent_Debug_H
19
20 #include "download-agent-type.h"
21
22 #define DA_DEBUG_ENV_KEY "DOWNLOAD_AGENT_DEBUG"
23 #define DA_DEBUG_CONFIG_FILE_PATH "/tmp/.download_agent.conf"
24
25 #define IS_LOG_ON(channel) (DALogBitMap & (0x1<<(channel)))
26
27 typedef enum {
28         Soup,
29         HTTPManager,
30         FileManager,
31         DRMManager,
32         DownloadManager,
33         ClientNoti,
34         HTTPMessageHandler,
35         Encoding,
36         QueueManager,
37         Parsing,
38         Thread,
39         Default,
40         DA_LOG_CHANNEL_MAX
41 } da_log_channel;
42
43 extern int DALogBitMap;
44
45 da_result_t init_log_mgr(void);
46
47 #ifdef NODEBUG
48         #define DA_LOG(channel, format, ...) ((void)0)
49         #define DA_LOG_CRITICAL(channel, format, ...) ((void)0)
50         #define DA_LOG_VERBOSE(channel, format, ...) ((void)0)
51         #define DA_LOG_ERR(channel, format, ...) ((void)0)
52         #define DA_LOG_FUNC_START(channel, ...) ((void)0)
53
54 #else /* NODEBUG */
55 #include <stdio.h>
56 #include <stdarg.h>
57 #include <pthread.h>
58
59 #ifdef DA_DEBUG_USING_DLOG
60         #include <dlog.h>
61         #ifdef LOG_TAG
62         #undef LOG_TAG
63         #endif /*  LOG_TAG */
64         #define LOG_TAG "DOWNLOAD_AGENT"
65
66         #define DA_LOG(channel, format, ...) LOGD_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
67         #define DA_LOG_CRITICAL(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
68         #define DA_LOG_VERBOSE(channel, format, ...) LOGV_IF(IS_LOG_ON(channel), format, ##__VA_ARGS__);
69         #define DA_LOG_ERR(channel, format, ...) LOGE_IF(IS_LOG_ON(channel), "ERR! "format, ##__VA_ARGS__);
70         #define DA_LOG_FUNC_START(channel, ...) LOGV_IF(IS_LOG_ON(channel), "starting...");
71 #else /* DA_DEBUG_USING_DLOG */
72         #include <unistd.h>
73         #include <syscall.h>
74
75         #define DA_LOG(channel, format, ...) do {\
76                 IS_LOG_ON(channel) \
77                                 ? fprintf(stderr, "[DA][%u][%s(): %d] "format"\n",(unsigned int)syscall(__NR_gettid), __FUNCTION__,__LINE__, ##__VA_ARGS__) \
78                                 : ((void)0);\
79         }while(0)
80         #define DA_LOG_ERR(channel, format, ...) do {\
81                 IS_LOG_ON(channel) \
82                                 ? fprintf(stderr, "[DA][%u][ERR][%s(): %d]\n",(unsigned int)syscall(__NR_gettid), __FUNCTION__,__LINE__, ##__VA_ARGS__) \
83                                 : ((void)0); \
84         }while(0)
85         #define DA_LOG_FUNC_START(channel, ...) do {\
86                 IS_LOG_ON(channel) \
87                                 ? fprintf(stderr, "[DA][%u][%s(): %d] starting\n",(unsigned int)syscall(__NR_gettid), __FUNCTION__,__LINE__) \
88                                 : ((void)0); \
89         }while(0)
90         #define DA_LOG_CRITICAL DA_LOG
91         #define DA_LOG_VERBOSE DA_LOG
92 #endif /* DA_DEBUG_USING_DLOG */
93 #endif /* NDEBUG */
94 #endif /* _Download_Agent_Debug_H */