• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/programs/libcprops/log.h

Go to the documentation of this file.
00001 #ifndef _CP_LOG_H
00002 #define _CP_LOG_H
00003 
00004 /** @{ */
00005 /**
00006  * @file
00007  * libcprops logging facilities<p>
00008  *
00009  * cp_log_init(filename, level) should be called on startup with a log file
00010  * name and a log level. the following macros may be used for logging 
00011  * messages.<p>
00012  * 
00013  * before exiting, cp_log_close() should be called to ensure the log is 
00014  * flushed.
00015  * <ul>
00016  * <li> DEBUGMSG(fmt, ...) for printouts on LOG_LEVEL_DEBUG if compiled with -DDEBUG
00017  * <li> cp_info(fmt, ...) for printouts on LOG_LEVEL_INFO
00018  * <li> cp_warn(fmt, ...) for warning printouts - LOG_LEVEL_WARNING or lower
00019  * <li> cp_error(code, fmt, ...) for error messages - LOG_LEVEL_ERROR or lower
00020  * <li> cp_fatal(code, fmt, ...) for fatal error messages (LOG_LEVEL_FATAL)
00021  * </ul>
00022  */
00023 
00024 #include "common.h"
00025 #include "str.h"
00026 
00027 __BEGIN_DECLS
00028 
00029 #include "config.h"
00030 
00031 /** debug level */
00032 #define LOG_LEVEL_DEBUG                         0
00033 /** normal log level */
00034 #define LOG_LEVEL_INFO                          1
00035 /** relatively quiet - warnings only */
00036 #define LOG_LEVEL_WARNING                       2
00037 /** quit - severe errors only */
00038 #define LOG_LEVEL_ERROR                         3
00039 /** very quiet - report fatal errors only */
00040 #define LOG_LEVEL_FATAL                         4
00041 /** no logging */
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 /** precision of seconds: undefine or use 1-6 */
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  * unconditionally log a message
00079  */
00080 CPROPS_DLL
00081 void cp_log(const char *msg, ...);
00082 
00083 /**
00084  * unconditionally log a limited length message
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  * print out a LOG_LEVEL_WARNING log message 
00107  */
00108 CPROPS_DLL
00109 void cp_warn(char *msg, ...);
00110 
00111 /**
00112  * print out a LOG_LEVEL_ERROR log message
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  * print out a LOG_LEVEL_ERROR log message with an errno code
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  * print out a LOG_LEVEL_FATAL log message and exit. if log_level is 
00140  * LOG_LEVEL_SILENT, the error message is supressed but the process still
00141  * exits.
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 /** hex dump a cp_string */
00154 CPROPS_DLL
00155 void cp_dump(int log_level, cp_string *str);
00156 
00157 /** hex dump up to len bytes of a cp_string */
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 /* HAVE_REGEX_H */
00182 
00183 __END_DECLS
00184 
00185 /** @} */
00186 
00187 #endif
00188 

Generated on Fri Oct 22 2010 11:02:13 for SST by  doxygen 1.7.1