00001 #ifndef _CP_LOG_H
00002 #define _CP_LOG_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "common.h"
00025 #include "str.h"
00026
00027 __BEGIN_DECLS
00028
00029 #include "config.h"
00030
00031
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 #define cp_assert(cond) (cond == 0 ? die(1, "assertion %s failed, in %s line %d\n", #cond, __FILE__, __LINE__) : 0)
00047
00048 #ifdef __OpenBSD__
00049 #define MAX_LOG_MESSAGE_LEN 0x1000
00050 #else
00051 #define MAX_LOG_MESSAGE_LEN 0x10000
00052 #endif
00053
00054
00055 #define PRECISE_TIME "3"
00056 #ifdef PRECISE_TIME
00057 #define PRECISE_TIME_FORMAT ".%0" PRECISE_TIME "ld"
00058 #else //precise
00059 #define PRECISE_TIME_FORMAT ""
00060 #endif
00061
00062 CPROPS_DLL
00063 int cp_log_init(char *filename, int verbosity);
00064
00065 CPROPS_DLL
00066 int cp_log_reopen(void);
00067
00068 CPROPS_DLL
00069 int cp_log_close(void);
00070
00071 CPROPS_DLL
00072 void die(int code, const char *msg, ...);
00073
00074 CPROPS_DLL
00075 void cp_log_set_time_format(char *time_format);
00076
00077
00078
00079
00080 CPROPS_DLL
00081 void cp_log(const char *msg, ...);
00082
00083
00084
00085
00086 CPROPS_DLL
00087 void cp_nlog(size_t len, const char *msg, ...);
00088
00089 #ifdef CP_HAS_VARIADIC_MACROS
00090 #define cp_debug(msg, ...) \
00091 (cp_debug_message(msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00092 CPROPS_DLL
00093 void cp_debug_message(char *msg, char *file, int line, ...);
00094 #else
00095 CPROPS_DLL
00096 void cp_debug(char *msg, ...);
00097 #endif
00098
00099 CPROPS_DLL
00100 void cp_debuginfo(char *msg, ...);
00101
00102 CPROPS_DLL
00103 void cp_info(char *msg, ...);
00104
00105
00106
00107
00108 CPROPS_DLL
00109 void cp_warn(char *msg, ...);
00110
00111
00112
00113
00114 #ifdef CP_HAS_VARIADIC_MACROS
00115 #define cp_error(code, msg, ...) \
00116 (cp_error_message(code, msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00117 CPROPS_DLL
00118 void cp_error_message(int code, char *msg, char *file, int line, ...);
00119 #else
00120 CPROPS_DLL
00121 void cp_error(int code, char *msg, ...);
00122 #endif
00123
00124
00125
00126
00127 #ifdef CP_HAS_VARIADIC_MACROS
00128 #define cp_perror(code, errno_code, msg, ...) \
00129 (cp_perror_message(code, errno_code, msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00130 CPROPS_DLL
00131 void cp_perror_message(int code, int errno_code,
00132 char *msg, char *file, int line, ...);
00133 #else
00134 CPROPS_DLL
00135 void cp_perror(int code, int errno_code, char *msg, ...);
00136 #endif
00137
00138
00139
00140
00141
00142
00143 #ifdef CP_HAS_VARIADIC_MACROS
00144 #define cp_fatal(code, msg, ...) \
00145 (cp_fatal_message(code, msg, __FILE__, __LINE__ , ## __VA_ARGS__))
00146 CPROPS_DLL
00147 void cp_fatal_message(int code, char *msg, char *file, int line, ...);
00148 #else
00149 CPROPS_DLL
00150 void cp_fatal(int code, char *msg, ...);
00151 #endif
00152
00153
00154 CPROPS_DLL
00155 void cp_dump(int log_level, cp_string *str);
00156
00157
00158 CPROPS_DLL
00159 void cp_ndump(int log_level, cp_string *str, size_t len);
00160
00161 #ifdef DEBUG
00162 #ifdef CP_HAS_VARIADIC_MACROS
00163 #define DEBUGMSG(msg, ...) DEBUGMSG_impl(msg, __FILE__, __LINE__ , ## __VA_ARGS__)
00164 CPROPS_DLL
00165 void DEBUGMSG_impl(char *msg, char *file, int line, ...);
00166 #else
00167 CPROPS_DLL
00168 void DEBUGMSG(char *msg, ...);
00169 #endif
00170 #else
00171 #ifdef CP_HAS_VARIADIC_MACROS
00172 #define DEBUGMSG(...)
00173 #else
00174 #define DEBUGMSG()
00175 #endif
00176 #endif
00177
00178 #if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
00179 CPROPS_DLL
00180 int log_regex_compilation_error(int rc, char *msg);
00181 #endif
00182
00183 __END_DECLS
00184
00185
00186
00187 #endif
00188