mondemandlib.h

Go to the documentation of this file.
00001 #ifndef __MONDEMAND_H__
00002 #define __MONDEMAND_H__
00003 
00010 #include "m_hash.h"
00011 #include "mondemand_trace.h"
00012 #include "mondemand_transport.h"
00013 
00014 #include <stdarg.h>
00015 
00016 #ifdef __cplusplus
00017 #define HAVE_ISO_VARARGS HAVE_ISO_CXX_VARARGS
00018 #define HAVE_GNUC_VARARGS HAVE_GNUC_CXX_VARARGS
00019 #else
00020 #define HAVE_ISO_VARARGS HAVE_ISO_C_VARARGS
00021 #define HAVE_GNUC_VARARGS HAVE_GNUC_C_VARARGS
00022 #endif
00023 
00024 /*
00025  * priorities map to the syslog priorities.
00026  */
00027 #define M_LOG_EMERG       0       /* system is unusable */
00028 #define M_LOG_ALERT       1       /* action must be taken immediately */
00029 #define M_LOG_CRIT        2       /* critical conditions */
00030 #define M_LOG_ERR         3       /* error conditions */
00031 #define M_LOG_WARNING     4       /* warning conditions */
00032 #define M_LOG_NOTICE      5       /* normal but significant condition */
00033 #define M_LOG_INFO        6       /* informational */
00034 #define M_LOG_DEBUG       7       /* debug-level messages */
00035 #define M_LOG_ALL         8       /* all messages, including traces */
00036 
00037 /* convenience */
00038 #define M_LOG_WARN M_LOG_WARNING
00039 #define M_LOG_ERROR M_LOG_ERR
00040 
00041 /* these are used to print human readable log levels */
00042 static const char * const MonDemandLogLevelStrings[] = {
00043   "emerg",
00044   "alert",
00045   "crit",
00046   "error",
00047   "warning",
00048   "notice",
00049   "info",
00050   "debug",
00051   "all"
00052 };
00053 
00054 
00055 /* forward declaration of opaque structs */
00056 struct mondemand_client;
00057 
00058 
00065 struct mondemand_client *
00066 mondemand_client_create(const char *program_identifier);
00067 
00068 
00076 void mondemand_client_destroy(struct mondemand_client *client);
00077 
00078 
00087 void
00088 mondemand_set_immediate_send_level(struct mondemand_client *client,
00089                                    const int level);
00090 
00099 void
00100 mondemand_set_no_send_level(struct mondemand_client *client, const int level);
00101 
00102 
00107 const char *
00108 mondemand_get_context(struct mondemand_client *client, const char *key);
00109 
00110 
00116 const char **
00117 mondemand_get_context_keys(struct mondemand_client *client);
00118 
00119 
00128 int
00129 mondemand_set_context(struct mondemand_client *client,
00130                       const char *key, const char *value);
00131 
00132 
00138 void
00139 mondemand_remove_context(struct mondemand_client *client, const char *key);
00140 
00141 
00147 void
00148 mondemand_remove_all_contexts(struct mondemand_client *client);
00149 
00150 
00157 int
00158 mondemand_add_transport(struct mondemand_client *client,
00159                         struct mondemand_transport *transport);
00160 
00161 
00162 /*\fn mondemand_level_is_enabled(struct mondemand_client *client,
00163  *                               const int log_level)
00164  * \brief this checks if a log level is enabled, which is useful to callers
00165  *        in case they want to check whether or not to bother to log.
00166  */
00167 int
00168 mondemand_level_is_enabled(struct mondemand_client *client,
00169                            const int log_level);
00170 
00174 int mondemand_flush_logs(struct mondemand_client *client);
00175 
00179 int mondemand_flush_stats(struct mondemand_client *client);
00180 
00185 int mondemand_flush_stats_no_reset(struct mondemand_client *client);
00186 
00190 int mondemand_flush(struct mondemand_client *client);
00191 
00192 
00193 /*=====================================================================*/
00194 /* Useful Macros                                                       */
00195 /*=====================================================================*/
00196 
00197 #if HAVE_ISO_VARARGS
00198 
00199 /* macros for ISO style varargs */
00200 
00201 #define mondemand_log(m, level, tid, ...) \
00202   mondemand_log_real(m, __FILE__, __LINE__, level, tid, __VA_ARGS__)
00203 
00204 #define mondemand_emerg(m, tid, ...) \
00205   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_EMERG, tid, __VA_ARGS__)
00206 
00207 #define mondemand_alert(m, tid, ...) \
00208   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_ALERT, tid, __VA_ARGS__)
00209 
00210 #define mondemand_crit(m, tid, ...) \
00211   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_CRIT, tid, __VA_ARGS__)
00212 
00213 #define mondemand_error(m, tid, ...) \
00214   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_ERR, tid, __VA_ARGS__)
00215 
00216 #define mondemand_warning(m, tid, ...) \
00217   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_WARNING, tid, __VA_ARGS__)
00218 
00219 #define mondemand_notice(m, tid, ...) \
00220   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_NOTICE, tid, __VA_ARGS__)
00221 
00222 #define mondemand_info(m, tid, ...) \
00223   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_INFO, tid, __VA_ARGS__)
00224 
00225 #define mondemand_debug(m, tid, ...) \
00226   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_DEBUG, tid, __VA_ARGS__)
00227 
00228 
00229 #elif HAVE_GNUC_VARARGS
00230 
00231 /* macros for gnuc style varargs */
00232 
00233 #define mondemand_log(m, level, tid, format...) \
00234   mondemand_log_real(m, __FILE__, __LINE__, level, tid, format)
00235 
00236 #define mondemand_emerg(m, tid, format...) \
00237   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_EMERG, tid, format)
00238 
00239 #define mondemand_alert(m, tid, format...) \
00240   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_ALERT, tid, format)
00241 
00242 #define mondemand_crit(m, tid, format...) \
00243   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_CRIT, tid, format)
00244 
00245 #define mondemand_error(m, tid, format...) \
00246   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_ERR, tid, format)
00247 
00248 #define mondemand_warning(m, tid, format...) \
00249   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_WARNING, tid, format)
00250 
00251 #define mondemand_notice(m, tid, format...) \
00252   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_NOTICE, tid, format)
00253 
00254 #define mondemand_info(m, tid, format...) \
00255   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_INFO, tid, format)
00256 
00257 #define mondemand_debug(m, tid, format...) \
00258   mondemand_log_real(m, __FILE__, __LINE__, M_LOG_DEBUG, tid, format)
00259 
00260 #endif
00261 
00262 /* increments a counter by 1 using the filename:line */
00263 #define mondemand_increment(m) \
00264   mondemand_stats_inc(m, __FILE__, __LINE__, NULL, 1)
00265 
00266 /* increments a counter by value using the filename:line */
00267 #define mondemand_increment_value(m, v) \
00268   mondemand_stats_inc(m, __FILE__, __LINE__, NULL, v)
00269 
00270 /* increments the specified key by 1 */
00271 #define mondemand_increment_key(m, k) \
00272   mondemand_stats_inc(m, __FILE__, __LINE__, k, 1);
00273 
00274 /* increments the specified key by value */
00275 #define mondemand_increment_key_by_val(m, k, v) \
00276   mondemand_stats_inc(m, __FILE__, __LINE__, k, v)
00277 
00278 /* decrements a counter by 1 using filename:line */
00279 #define mondemand_decrement(m) \
00280   mondemand_stats_dec(m, __FILE__, __LINE__, NULL, 1)
00281 
00282 /* decrements a counter by value using filename:line */
00283 #define mondemand_decrement_value(m, v) \
00284   mondemand_stats_dec(m, __FILE__, __LINE__, NULL, v)
00285 
00286 /* decrements the named key by 1 */
00287 #define mondemand_decrement_key(m, k) \
00288   mondemand_stats_dec(m, __FILE__, __LINE__, k, 1);
00289 
00290 /* decrements the named key by value */
00291 #define mondemand_decrement_key_by_val(m, k, v) \
00292   mondemand_stats_dec(m, __FILE__, __LINE__, k, v)
00293 
00294 /* sets a counter by value using filename:line */
00295 #define mondemand_set_by_val(m, v) \
00296   mondemand_stats_set(m, __FILE__, __LINE__, NULL, v)
00297 
00298 /* set the specified key to the value specified */
00299 #define mondemand_set_key_by_val(m, k, v) \
00300   mondemand_stats_set(m, __FILE__, __LINE__, k, v)
00301 
00302 
00303 /*=====================================================================*/
00304 /* Semi-private functions                                              */
00305 /*=====================================================================*/
00306 
00314 int mondemand_log_real(struct mondemand_client *client,
00315                        const char *filename, const int line, const int level,
00316                        const struct mondemand_trace_id trace_id,
00317                        const char *format, ...);
00318 
00328 int mondemand_log_real_va(struct mondemand_client *client,
00329                           const char *filename, const int line, 
00330                           const int level,
00331                           const struct mondemand_trace_id trace_id,
00332                           const char *format, va_list args);
00333 
00340 int mondemand_stats_inc(struct mondemand_client *client,
00341                         const char *filename, const int line,
00342                         const char *key, const int value);
00343 
00350 int mondemand_stats_dec(struct mondemand_client *client,
00351                         const char *filename, const int line,
00352                         const char *key, const int value);
00353 
00360 int mondemand_stats_set(struct mondemand_client *client,
00361                         const char *filename, const int line,
00362                         const char *key, const int value);
00363 
00364 
00365 #endif /* __MONDEMAND_H_ */
00366 

Generated on Tue May 12 14:40:00 2009 for mondemand by  doxygen 1.4.7