log.h

Go to the documentation of this file.
00001 #ifndef _CP_LOG_H
00002 #define _CP_LOG_H
00003 
00024 #include "common.h"
00025 #include "str.h"
00026 
00027 __BEGIN_DECLS
00028 
00029 #include "config.h"
00030 
00032 #define LOG_LEVEL_DEBUG             0
00033 
00034 #define LOG_LEVEL_INFO              1
00035 
00036 #define LOG_LEVEL_WARNING           2
00037 
00038 #define LOG_LEVEL_ERROR             3
00039 
00040 #define LOG_LEVEL_FATAL             4
00041 
00042 #define LOG_LEVEL_SILENT            5
00043 
00044 #include <stdio.h>
00045 
00046 #ifdef DEBUG
00047 #define cp_assert(cond) (cond == 0 ? die(1, "assertion %s failed, in %s line %d\n", #cond, __FILE__, __LINE__) : 0)
00048 #else /* DEBUG */
00049 #define cp_assert(cond)
00050 #endif /* DEBUG */
00051 
00052 #ifdef __OpenBSD__
00053 #define MAX_LOG_MESSAGE_LEN 0x1000
00054 #else
00055 #define MAX_LOG_MESSAGE_LEN 0x10000
00056 #endif
00057 
00059 #define PRECISE_TIME "3" 
00060 #ifdef PRECISE_TIME
00061 #define PRECISE_TIME_FORMAT ".%0" PRECISE_TIME "ld"
00062 #else       //precise
00063 #define PRECISE_TIME_FORMAT ""
00064 #endif  
00065 
00066 CPROPS_DLL
00067 int cp_log_init(char *filename, int verbosity);
00068 
00069 CPROPS_DLL
00070 int cp_log_reopen();
00071 
00072 CPROPS_DLL
00073 int cp_log_close();
00074 
00075 CPROPS_DLL
00076 void die(int code, const char *msg, ...);
00077 
00078 CPROPS_DLL
00079 void cp_log_set_time_format(char *time_format);
00080 
00084 CPROPS_DLL
00085 void cp_log(const char *msg, ...);
00086 
00090 CPROPS_DLL
00091 void cp_nlog(size_t len, const char *msg, ...);
00092 
00093 #ifdef CP_HAS_VARIADIC_MACROS
00094 #define cp_debug(msg, ...) \
00095     (cp_debug_message(msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00096 CPROPS_DLL
00097 void cp_debug_message(char *msg, char *file, int line, ...);
00098 #else
00099 CPROPS_DLL
00100 void cp_debug(char *msg, ...);
00101 #endif
00102 
00103 CPROPS_DLL
00104 void cp_debuginfo(char *msg, ...);
00105 
00106 CPROPS_DLL
00107 void cp_info(char *msg, ...);
00108 
00112 CPROPS_DLL
00113 void cp_warn(char *msg, ...);
00114 
00118 #ifdef CP_HAS_VARIADIC_MACROS
00119 #define cp_error(code, msg, ...) \
00120         (cp_error_message(code, msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00121 CPROPS_DLL
00122 void cp_error_message(int code, char *msg, char *file, int line, ...);
00123 #else
00124 CPROPS_DLL
00125 void cp_error(int code, char *msg, ...);
00126 #endif
00127 
00131 #ifdef CP_HAS_VARIADIC_MACROS
00132 #define cp_perror(code, errno_code, msg, ...) \
00133         (cp_perror_message(code, errno_code, msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00134 CPROPS_DLL
00135 void cp_perror_message(int code, int errno_code, 
00136                        char *msg, char *file, int line, ...);
00137 #else
00138 CPROPS_DLL
00139 void cp_perror(int code, int errno_code, char *msg, ...);
00140 #endif
00141 
00147 #ifdef CP_HAS_VARIADIC_MACROS
00148 #define cp_fatal(code, msg, ...) \
00149         (cp_fatal_message(code, msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00150 CPROPS_DLL
00151 void cp_fatal_message(int code, char *msg, char *file, int line, ...);
00152 #else
00153 CPROPS_DLL
00154 void cp_fatal(int code, char *msg, ...);
00155 #endif
00156 
00158 CPROPS_DLL
00159 void cp_dump(int log_level, cp_string *str);
00160 
00162 CPROPS_DLL
00163 void cp_ndump(int log_level, cp_string *str, size_t len);
00164 
00165 #ifdef DEBUG
00166 #ifdef CP_HAS_VARIADIC_MACROS
00167 #define DEBUGMSG(msg, ...) DEBUGMSG_impl(msg, __FILE__, __LINE__ , ## __VA_ARGS__)
00168 CPROPS_DLL
00169 void DEBUGMSG_impl(char *msg, char *file, int line, ...);
00170 #else
00171 CPROPS_DLL
00172 void DEBUGMSG(char *msg, ...);
00173 #endif
00174 #else
00175 #ifdef CP_HAS_VARIADIC_MACROS
00176 #define DEBUGMSG(...)
00177 #else
00178 #define DEBUGMSG()
00179 #endif
00180 #endif
00181 
00182 #if defined(CP_HAS_REGEX_H) || defined(CP_HAS_PCRE)
00183 CPROPS_DLL
00184 int log_regex_compilation_error(int rc, char *msg);
00185 #endif /* CP_HAS_REGEX_H */
00186 
00187 __END_DECLS
00188 
00191 #endif
00192 

Generated on Mon Dec 5 23:00:22 2011 for cprops by  doxygen 1.4.7