3c469a6744f80f8506452274ffceb195e66d8a17
[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
37 #define MYFILE_TRACE_DEBUG(fmt, arg...) do { LOGD("[%s][%d] "fmt "\n", __FILE__, __LINE__, ##arg); } while (0)
38 #define MYFILE_TRACE_ERROR(fmt, arg...) do { LOGE("[%s][%d] "fmt"\n", strrchr(__FILE__, '/')+1, __LINE__, ##arg); } while (0)
39
40 #define mf_func_line()                  do { LOGD("[%s][%s][%d] \n", __FILE__, __func__, __LINE__); } while (0)
41 #define mf_debug(fmt, args...)  do { LOGD("[%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
42
43 #define mf_error(fmt, args...)          do {\
44                                                 LOGE("[%s][%d] "fmt"\n", __func__, __LINE__, ##args); \
45                                                 MF_LOG_RECORD(fmt,##args); \
46                                            } while (0)
47 #define mf_warnig(fmt, args...) do { LOGW("[%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
48 #define mf_info(fmt, args...)           do { LOGI("[%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
49 #define mf_assert(fmt, args...) do { LOGE("[ASSERT][%s][%d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
50
51 #else
52
53 #define MYFILE_TRACE_DEBUG(fmt, arg...) do { printf("%s:%d: " fmt "\n", __FILE__, __LINE__, ##arg); } while (0)
54 #define MYFILE_TRACE_ERROR(fmt, arg...) do { printf("[%s][%d] "fmt"\n", strrchr(__FILE__, '/')+1, __LINE__, ##arg); } while (0)
55
56 #define mf_debug(fmt, args...)  do { printf("[MYFILE][D][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
57 #define mf_func_line()                  do { printf("[MYFILE][D][%40s:%4d] \n", __FILE__, __func__, __LINE__); } while (0)
58 #define mf_error(fmt, args...)  do { \
59                                         printf("[MYFILE][E][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); \
60                                         MF_LOG_RECORD(fmt,##args); \
61                                    } while (0)
62 #define mf_warnig(fmt, args...) do { printf("[MYFILE][W][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
63 #define mf_info(fmt, args...)   do { printf("[MYFILE][I][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
64 #define mf_assert(fmt, args...) do { printf("[MYFILE][A][%40s:%4d] "fmt"\n", __func__, __LINE__, ##args); } while (0)
65
66 #endif
67
68 #define mf_retvm_if(expr, val, fmt, arg...) do { \
69                         if (expr) { \
70                                 MYFILE_TRACE_ERROR(fmt, ##arg); \
71                                 MF_LOG_RECORD(fmt,##arg); \
72                                 return (val); \
73                         } \
74                 } while (0)
75
76 #define mf_retv_if(expr, val) do { \
77                         if (expr) { \
78                                 return (val); \
79                         } \
80                 } while (0)
81
82
83 #define mf_retm_if(expr, fmt, arg...) do { \
84                         if (expr) { \
85                                 MYFILE_TRACE_ERROR(fmt, ##arg); \
86                                 MF_LOG_RECORD(fmt,##arg); \
87                                 return; \
88                         } \
89                 } while (0)
90
91 #define mf_ret_if(expr, fmt, arg...) do { \
92                         if (expr) { \
93                                 MF_LOG_RECORD(fmt,##arg); \
94                                 return; \
95                         } \
96                 } while (0)
97
98 #define MF_TRACE_BEGIN do {\
99                                         {\
100                                                 LOGD("\n\033[0;35mENTER FUNCTION: %s. \033[0m\t%s:%d\n", \
101                                                 __FUNCTION__, (char *)(strrchr(__FILE__, '/')+1), __LINE__);\
102                                         } \
103                                 } while (0) ;
104
105 #define MF_TRACE_END  do {\
106                                         {\
107                                                 LOGD("\n\033[0;35mEXIT FUNCTION: %s. \033[0m\t%s:%d\n", \
108                                                 __FUNCTION__, (char *)(strrchr(__FILE__, '/')+1), __LINE__);\
109                                         } \
110                                 } while (0) ;
111
112 #define MF_CHECK(expr)                          mf_retm_if(!(expr),"INVALID PARAM RETURN")
113 #define MF_CHECK_FALSE(expr)                    mf_retvm_if(!(expr),FALSE,"INVALID PARM RETURN FALSE")
114 #define MF_CHECK_VAL(expr, val)                 mf_retvm_if(!(expr),val,"INVALID PARM RETURN NULL")
115 #define MF_CHECK_NULL(expr)                     mf_retvm_if(!(expr),NULL,"INVALID PARM RETURN NULL")
116
117 #endif /* end of __MYFILE_DEBUG_H_ */