99f0c5d812138bd276206f8644e466595ea097ed
[apps/core/preloaded/myfiles.git] / src / include / mf-dlog.h
1 /*
2  * Copyright 2013         Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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
18
19
20
21 #ifndef __MYFILE_DEBUG_H_
22 #define __MYFILE_DEBUG_H_
23
24 #include <stdio.h>
25 #include <string.h>
26 #include "mf-log.h"
27
28 #ifdef MYFILE_USE_LOG
29
30 #ifdef LOG_TAG
31 #undef LOG_TAG
32 #endif
33
34 #define LOG_TAG         "MYFILES"
35 #include <dlog.h>
36 #define LOG_COLOR_RED      "\033[31m"
37 #define LOG_COLOR_RESET    "\033[0m"
38
39 #define MYFILE_TRACE_DEBUG(fmt, arg...) do { LOGD("[%s][%d] "fmt "\n", __FILE__, __LINE__, ##arg); } while (0)
40 #define MYFILE_TRACE_ERROR(fmt, arg...) do { LOGE("[%s][%d] "fmt"\n", strrchr(__FILE__, '/')+1, __LINE__, ##arg); } while (0)
41
42 #define mf_func_line()                  do { LOGD("[%s][%s][%d] \n", __FILE__, __func__, __LINE__); } while (0)
43 #define mf_debug(fmt, args...)  do { LOGD("[%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
44
45 #define mf_error(fmt, arg...)   LOGE(LOG_COLOR_RED"[ %s : %d]   "fmt""LOG_COLOR_RESET, __FUNCTION__, __LINE__,##arg)
46 #define mf_warnig(fmt, args...) do { LOGW("[%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
47 #define mf_info(fmt, args...)           do { LOGI("[%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
48 #define mf_assert(fmt, args...) do { LOGE("[ASSERT][%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
49
50 #else
51
52 #define MYFILE_TRACE_DEBUG(fmt, arg...) do { printf("%s:%d: " fmt "\n", __FILE__, __LINE__, ##arg); } while (0)
53 #define MYFILE_TRACE_ERROR(fmt, arg...) do { printf("[%s][%d] "fmt"\n", strrchr(__FILE__, '/')+1, __LINE__, ##arg); } while (0)
54
55 #define mf_debug(fmt, args...)  do { printf("[MYFILE][D][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
56 #define mf_func_line()                  do { printf("[MYFILE][D][%40s:%4d] \n", __FILE__, __func__, __LINE__); } while (0)
57 #define mf_error(fmt, args...)  do { \
58                                         printf("[MYFILE][E][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); \
59                                         MF_LOG_RECORD(fmt,##args); \
60                                    } while (0)
61 #define mf_warnig(fmt, args...) do { printf("[MYFILE][W][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
62 #define mf_info(fmt, args...)   do { printf("[MYFILE][I][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
63 #define mf_assert(fmt, args...) do { printf("[MYFILE][A][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
64
65 #endif
66
67 #define mf_retvm_if(expr, val, fmt, arg...) do { \
68                         if (expr) { \
69                                 MYFILE_TRACE_ERROR(fmt, ##arg); \
70                                 MF_LOG_RECORD(fmt,##arg); \
71                                 return (val); \
72                         } \
73                 } while (0)
74
75 #define mf_retv_if(expr, val) do { \
76                         if (expr) { \
77                                 return (val); \
78                         } \
79                 } while (0)
80
81
82 #define mf_retm_if(expr, fmt, arg...) do { \
83                         if (expr) { \
84                                 MYFILE_TRACE_ERROR(fmt, ##arg); \
85                                 MF_LOG_RECORD(fmt,##arg); \
86                                 return; \
87                         } \
88                 } while (0)
89
90 #define mf_ret_if(expr, fmt, arg...) do { \
91                         if (expr) { \
92                                 MF_LOG_RECORD(fmt,##arg); \
93                                 return; \
94                         } \
95                 } while (0)
96
97 #define MF_TRACE_BEGIN do {\
98                                         {\
99                                                 LOGD("\n\033[0;35mENTER FUNCTION: %s. \033[0m\t%s:%d\n", \
100                                                 __FUNCTION__, (char *)(strrchr(__FILE__, '/')+1), __LINE__);\
101                                         } \
102                                 } while (0) ;
103
104 #define MF_TRACE_END  do {\
105                                         {\
106                                                 LOGD("\n\033[0;35mEXIT FUNCTION: %s. \033[0m\t%s:%d\n", \
107                                                 __FUNCTION__, (char *)(strrchr(__FILE__, '/')+1), __LINE__);\
108                                         } \
109                                 } while (0) ;
110
111 #define MF_CHECK(expr)                          mf_retm_if(!(expr),"INVALID PARAM RETURN")
112 #define MF_CHECK_FALSE(expr)                    mf_retvm_if(!(expr),FALSE,"INVALID PARM RETURN FALSE")
113 #define MF_CHECK_VAL(expr, val)                 mf_retvm_if(!(expr),val,"INVALID PARM RETURN NULL")
114 #define MF_CHECK_NULL(expr)                     mf_retvm_if(!(expr),NULL,"INVALID PARM RETURN NULL")
115
116 #endif /* end of __MYFILE_DEBUG_H_ */