00001 #ifndef __uth_log_h__
00002 #define __uth_log_h__
00003
00008
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <stdarg.h>
00012 #include <errno.h>
00013 #include <string.h>
00014 #include <assert.h>
00015 #ifdef PARALLEL
00016 #include "pch_intf.h"
00017 #endif
00018
00019 #ifdef __cplusplus
00020 extern "C"
00021 {
00022 #endif
00023
00030 #ifndef UTM_SAFE_FREE_PTR
00031 # define UTM_SAFE_FREE_PTR(ptr) if((ptr)!=NULL) { free((ptr));(ptr)=NULL; };
00032 #endif
00033
00034 #ifndef UTM_SAFE_FREE_PTR_ARRAY
00035 # define UTM_SAFE_FREE_PTR_ARRAY(p_ar,n) if((p_ar)!=NULL){int i=0; for(;i<n;++i){UTM_SAFE_FREE_PTR(p_ar[i]);}};
00036 #endif
00037
00038
00039
00040 #ifndef mf_print_array
00041 #define mf_print_array(ar,size,typ) { for(int i=0; i < size; ++i){ fprintf(utv_log_out,typ,ar[i]); fprintf(utv_log_out,", "); } fprintf(utv_log_out,"\n"); }
00042 #endif
00043
00044
00045 #ifndef _WIN32
00046 #define MF_FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
00047 #else
00048 #define MF_FILE_NAME (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
00049 #endif
00050
00051
00052 extern FILE* utv_log_out;
00053
00054 const char *utr_log_pre();
00055
00056 #ifdef NDEBUG
00057 # define mf_debug(M, ...)
00058 # define mf_check_debug(A, M, ...)
00059 # define mfp_debug(M, ...)
00060 # define mfp_check_debug(A, M, ...)
00061 #define mf_log_err(M, ...) fprintf(utv_log_out, "%s[ERROR] (%s:%d ) " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__)
00062
00063 #define mf_fatal_err(M, ...) { fprintf(utv_log_out, "[FATAL ERROR] (%s:%d ) " M "\n", MF_FILE_NAME, __LINE__, ##__VA_ARGS__); fflush(utv_log_out); exit(-3); }
00064
00065 #define mf_log_warn(M, ...) fprintf(utv_log_out, "%s[WARN] (%s:%d ) " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__)
00066
00067 #define mf_log_info(M, ...) fprintf(utv_log_out, "%s[INFO] (%s:%d ) " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__)
00068
00069 #define mf_log_test_fail(M, ...) fprintf(utv_log_out, "%s[TEST FAILED] (%s:%d ) " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__)
00070
00071 #define mf_check(A, M, ...) if(!(A)) { mf_log_err(M, ##__VA_ARGS__); assert(!M); exit(-1);}
00072
00073 #define mf_sentinel(M, ...) { mf_log_err(M, ##__VA_ARGS__); }
00074
00075 #define mf_check_mem(A) mf_check((A), "%s[ERROR]Out of memory.", utr_log_pre())
00076
00077 #define mf_check_info(A, M, ...) if(!(A)) { mf_log_info(M,##__VA_ARGS__); }
00078
00079 #define mf_test(A, M, ...) if(!(A)) { mf_log_test_fail(M, ##__VA_ARGS__); assert(!M);}
00080 #else
00081 # define mf_debug(M, ...) fprintf(utv_log_out, "%s[DEBUG] %s:%d: " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__)
00082 # define mf_check_debug(A, M, ...) if(!(A)) { mf_debug(M, ##__VA_ARGS__); assert(!M); }
00083 # ifdef PARALLEL
00084 # define mfp_debug mf_debug
00085 # define mfp_check_debug mf_check_debug
00086 # else
00087 # define mfp_debug mf_debug
00088 # define mfp_check_debug mf_check_debug
00089 # endif
00090
00091 #define mf_log_err(M, ...) { fprintf(utv_log_out, "%s[ERROR] (%s:%d ) " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__) ; fflush(utv_log_out); }
00092
00093 #define mf_fatal_err(M, ...) { fprintf(utv_log_out, "%s[FATAL ERROR] (%s:%d ) " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__); fflush(utv_log_out); exit(-3); }
00094
00095 #define mf_log_warn(M, ...) fprintf(utv_log_out, "%s[WARN] " M "\n", utr_log_pre(), ##__VA_ARGS__)
00096
00097 #define mf_log_info(M, ...) fprintf(utv_log_out, "%s[INFO] " M "\n", utr_log_pre() , ##__VA_ARGS__)
00098
00099 #define mf_log_test_fail(M, ...) fprintf(utv_log_out, "%s[TEST FAILED] (%s:%d ) " M "\n", utr_log_pre(), MF_FILE_NAME, __LINE__, ##__VA_ARGS__)
00100
00101 #define mf_check(A, M, ...) if(!(A)) { mf_log_err(M, ##__VA_ARGS__); assert(!M); exit(-1);}
00102
00103 #define mf_sentinel(M, ...) { mf_log_err(M, ##__VA_ARGS__); }
00104
00105 #define mf_check_mem(A) mf_check((A), "%s[ERROR]Out of memory.", utr_log_pre())
00106
00107 #define mf_check_info(A, M, ...) if(!(A)) { mf_log_info(M,##__VA_ARGS__); }
00108
00109 #define mf_test(A, M, ...) if(!(A)) { mf_log_test_fail(M, ##__VA_ARGS__); assert(!M);}
00110 #endif
00111
00112
00113
00114
00115
00116
00117
00118
00120
00121 #ifdef __cplusplus
00122 }
00123 #endif
00124
00125
00126 #endif // __uth_log_h__