4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 /******************************************************************************
25 * File: email-debug-log.h
26 * Desc: email-common-use debug header
31 * 2006.08.01 : created
32 *****************************************************************************/
33 #ifndef __EMAIL_DEBUG_LOG_H__
34 #define __EMAIL_DEBUG_LOG_H__
40 #include <tzplatform_config.h>
47 #define __FEATURE_DEBUG_LOG__
48 /* #define __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__ */
49 /* #define __FEATURE_LOG_FOR_DEBUG_LOG_DEV__ */
50 /* #define FEATURE_CORE_DEBUG */
52 #ifdef __FEATURE_DEBUG_LOG__
54 /* definition of LOG_TAG */
59 #define LOG_TAG "EMAIL_SERVICE"
61 #define EM_DEBUG_LOG(format, arg...) SLOGD(format, ##arg)
62 #define EM_DEBUG_EXCEPTION(format, arg...) SLOGE("[EXCEPTION!] " format "\n", ##arg)
64 #define EM_DEBUG_LOG_SEC(format, arg...) SECURE_SLOGD(format, ##arg)
65 #define EM_DEBUG_EXCEPTION_SEC(format, arg...) SECURE_SLOGE("[EXCEPTION!] " format "\n", ##arg)
66 #define EM_DEBUG_FUNC_BEGIN_SEC(format, arg...) EM_DEBUG_LOG_SEC("BEGIN - "format, ##arg)
68 #ifdef _DEBUG_MIME_PARSE_
69 #define EM_DEBUG_LOG_MIME(format, arg...) EM_DEBUG_LOG_SEC(format, ##arg)
70 #else /* _DEBUG_MIME_PARSE */
71 #define EM_DEBUG_LOG_MIME(format, arg...)
72 #endif /* _DEBUG_MIME_PARSE */
74 #ifdef __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__
75 #define EM_DEBUG_FUNC_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
76 #define EM_DEBUG_FUNC_END(format, arg...) EM_DEBUG_LOG("END - "format, ##arg)
77 #else /* __FEATURE_LOG_FOR_LIFE_CYCLE_OF_FUNCTION__ */
78 #define EM_DEBUG_FUNC_BEGIN(format, arg...)
79 #define EM_DEBUG_FUNC_END(format, arg...)
80 #undef EM_DEBUG_FUNC_BEGIN_SEC
81 #define EM_DEBUG_FUNC_BEGIN_SEC(format, arg...)
84 #ifdef __FEATURE_LOG_FOR_DEBUG_LOG_DEV__
85 #define EM_DEBUG_LOG_DEV(format, arg...) EM_DEBUG_LOG("[DEV] " format, ##arg)
86 #else /* __FEATURE_LOG_FOR_DEBUG_LOG_DEV__ */
87 #define EM_DEBUG_LOG_DEV(format, arg...)
90 #define EM_DEBUG_LINE EM_DEBUG_LOG("FUNC[%s : %d]", __FUNCTION__, __LINE__)
91 #define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_EXCEPTION X; expr;} else {;}
93 #define EM_DEBUG_ERROR_FILE_PATH tzplatform_mkpath(TZ_USER_DATA, "email/.email_data/.critical_error.log")
94 #define EM_DEBUG_CRITICAL_EXCEPTION(format, arg...) \
96 FILE *fp_error = NULL;\
97 fp_error = fopen(EM_DEBUG_ERROR_FILE_PATH, "a");\
99 char now_time_string[30] = {0,}; \
100 time_t now = time(NULL); \
101 strftime(now_time_string, 20, "%Y.%m.%d %H:%M:%S", localtime(&now)); \
102 fprintf(fp_error, "[%s][%s() :%s:%d] " format "\n",\
104 __FUNCTION__, (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ),\
109 #define EM_DEBUG_ALARM_LOG_FILE_PATH tzplatform_mkpath(TZ_USER_DATA, "email/.email_data/.alarm.log")
110 #define EM_DEBUG_ALARM_LOG(format, arg...) \
112 FILE *fp_error = NULL;\
113 fp_error = fopen(EM_DEBUG_ALARM_LOG_FILE_PATH, "a");\
115 char now_time_string[30] = {0,}; \
116 time_t now = time(NULL); \
117 strftime(now_time_string, 20, "%Y.%m.%d %H:%M:%S", localtime(&now)); \
118 fprintf(fp_error, "[%s][%s() :%s:%d] " format "\n",\
120 __FUNCTION__, (rindex(__FILE__, '/')? rindex(__FILE__,'/')+1 : __FILE__ ),\
125 #define EM_DEBUG_PERROR(str) ({\
126 char buf[128] = {0};\
127 strerror_r(errno, buf, sizeof(buf));\
128 EM_DEBUG_EXCEPTION("%s: %s(%d)", str, buf, errno);\
131 #define EM_VALIDATION_SYSTEM_LOG(CLASSIFICATION, MAIL_ID, FORMAT, ARG...) {char now_time_string[30] = {0,}; \
132 time_t now = time(NULL); \
133 strftime(now_time_string, 20, "%Y.%m.%d %H:%M:%S", localtime(&now)); \
134 LOG(LOG_VERBOSE, "VLD_EMAIL", "[Email " CLASSIFICATION "]%s, %d," FORMAT "\n", now_time_string, MAIL_ID, ##ARG);}
136 #ifdef _USE_PROFILE_DEBUG_
137 #define EM_PROFILE_BEGIN(pfid) \
138 unsigned int __prf_l1_##pfid = __LINE__;\
139 struct timeval __prf_1_##pfid;\
140 struct timeval __prf_2_##pfid;\
142 gettimeofday(&__prf_1_##pfid, 0);\
143 EM_DEBUG_LOG("**PROFILE BEGIN** [EMAILFW: %s() :%s %u ~ ] " #pfid \
144 " -> Start Time: %u.%06u seconds\n",\
146 rindex(__FILE__,'/')+1, \
148 (unsigned int)__prf_1_##pfid.tv_sec,\
149 (unsigned int)__prf_1_##pfid.tv_usec );\
152 #define EM_PROFILE_END(pfid) \
153 unsigned int __prf_l2_##pfid = __LINE__;\
155 gettimeofday(&__prf_2_##pfid, 0);\
156 long __ds = __prf_2_##pfid.tv_sec - __prf_1_##pfid.tv_sec;\
157 long __dm = __prf_2_##pfid.tv_usec - __prf_1_##pfid.tv_usec;\
158 if ( __dm < 0 ) { __ds--; __dm = 1000000 + __dm; } \
159 EM_DEBUG_LOG("**PROFILE END** [EMAILFW: %s() :%s %u ~ %u] " #pfid \
160 " -> Elapsed Time: %u.%06u seconds\n",\
162 rindex(__FILE__, '/')+1,\
165 (unsigned int)(__ds),\
166 (unsigned int)(__dm));\
170 #define EM_PROFILE_BEGIN(pfid)
171 #define EM_PROFILE_END(pfid)
176 #else /* __FEATURE_DEBUG_LOG__ */
178 #define EM_DEBUG_LINE
179 #define EM_DEBUG_LOG(format, arg...)
180 #define EM_DEBUG_ASSERT(format, arg...)
181 #define EM_DEBUG_EXCEPTION(format, arg...)
184 #define EM_DEBUG_DB_EXEC(eval, expr, X) if (eval) { EM_DEBUG_DB X; expr;} else {;}
185 #define EM_PROFILE_BEGIN(pfid)
186 #define EM_PROFILE_END(pfid)
188 #endif /* __FEATURE_DEBUG_LOG__ */
190 /* Use it in api function */
191 #define EM_DEBUG_API_BEGIN(format, arg...) EM_DEBUG_LOG("BEGIN - "format, ##arg)
192 #define EM_DEBUG_API_END(format, arg...) EM_DEBUG_LOG("END - "format, ##arg)
194 #define EM_NULL_CHECK_FOR_VOID(expr) \
197 EM_DEBUG_LOG ("NULL_PARAM: ["#expr"]");\
202 #define EM_IF_NULL_RETURN_VALUE(expr, ret) \
205 EM_DEBUG_LOG("NULL_PARAM: ["#expr"]");\
210 #define EM_RETURN_ERR_CODE(err_ptr, err_code, ret) \
212 if(err_ptr) *err_ptr = err_code;\
216 #define EM_EXIT_ERR_CODE(err_ptr, err_code) \
218 if(err_ptr) *err_ptr = err_code;\
223 #define EM_SAFE_FREE(expr) \
231 #define EM_SAFE_CLOSE(fd) \
237 EM_DEBUG_EXCEPTION ("close errno [%d]", errno);\
242 #define EM_SAFE_STRDUP(s) \
244 char* _s = (char*)s;\
245 (_s)? strdup(_s) : NULL;\
248 #define EM_SAFE_STRCMP(dest, src) \
252 ((_src) && (_dest))? strcmp(_dest, _src) : -1;\
255 #define EM_SAFE_STRCASECMP(dest, src) \
259 ((_src) && (_dest))? strcasecmp(_dest, _src) : -1;\
262 #define EM_SAFE_STRCPY(dest, src) \
266 ((_src) && (_dest))? strcpy(_dest, _src) : NULL;\
269 #define EM_SAFE_STRNCPY(dest, src, size) \
274 ((_src) && (_dest))? strncpy(_dest, _src, _size) : NULL;\
277 #define EM_SAFE_STRCAT(dest, src) \
281 ((_src) && (_dest))? strcat(_dest, _src) : NULL;\
285 #define EM_SAFE_STRNCAT(dest, src, size) \
290 ((_src) && (_dest))? strncat(_dest, _src, _size) : NULL;\
294 #define EM_SAFE_STRLEN(s) \
296 char* _s = (char*)s;\
297 (_s)? strlen(_s) : 0;\
301 #define EM_IF_ACCOUNT_ID_NULL(expr, ret) {\
303 EM_DEBUG_EXCEPTION_SEC ("EM_IF_ACCOUNT_ID_NULL: Account ID [ %d ] ", expr);\
309 #define ERRNO_BUF_SIZE 64
311 #define EM_STRERROR(errno_buf) ({\
312 strerror_r(errno, errno_buf, sizeof(errno_buf));\
318 #endif /* __cplusplu */
320 #endif /* __EMAIL_DEBUG_LOG_H__ */