00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef log4c_category_h
00011 #define log4c_category_h
00012
00023 #include <stdio.h>
00024 #include <stdarg.h>
00025 #include <log4c/defs.h>
00026 #include <log4c/priority.h>
00027 #include <log4c/location_info.h>
00028
00029 __LOG4C_BEGIN_DECLS
00030
00031 struct __log4c_appender;
00032 struct __log4c_category;
00033
00037 typedef struct __log4c_category log4c_category_t;
00038
00046 extern log4c_category_t* log4c_category_get(const char* a_name);
00047
00057 extern log4c_category_t* log4c_category_new(const char* a_name);
00058
00064 extern void log4c_category_delete(log4c_category_t* a_category);
00065
00071 extern const char* log4c_category_get_name(const log4c_category_t* a_category);
00072
00079 extern const struct __log4c_appender* log4c_category_get_appender(
00080 const log4c_category_t* a_category);
00081
00088 extern int log4c_category_get_additivity(const log4c_category_t* a_category);
00089
00095 extern int log4c_category_get_priority(const log4c_category_t* a_category);
00096
00108 extern int log4c_category_get_chainedpriority(const log4c_category_t* a_category);
00109
00117 extern const struct __log4c_appender* log4c_category_set_appender(
00118 log4c_category_t* a_category,
00119 struct __log4c_appender* a_appender);
00128 extern int log4c_category_set_priority(log4c_category_t* a_category,
00129 int a_priority);
00130
00138 extern int log4c_category_set_additivity(log4c_category_t* a_category,
00139 int a_additivity);
00146 extern void log4c_category_print(const log4c_category_t* a_category, FILE* a_stream);
00147
00155 static inline int log4c_category_is_priority_enabled(const log4c_category_t* a_category,
00156 int a_priority)
00157 {
00158 return log4c_category_get_chainedpriority(a_category) >= a_priority;
00159 }
00160
00168 static inline int log4c_category_is_fatal_enabled(const log4c_category_t* a_category)
00169 {
00170 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_FATAL);
00171 }
00172
00180 static inline int log4c_category_is_alert_enabled(const log4c_category_t* a_category)
00181 {
00182 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ALERT);
00183 }
00184
00192 static inline int log4c_category_is_crit_enabled(const log4c_category_t* a_category)
00193 {
00194 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_CRIT);
00195 }
00196
00204 static inline int log4c_category_is_error_enabled(const log4c_category_t* a_category)
00205 {
00206 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ERROR);
00207 }
00208
00216 static inline int log4c_category_is_warn_enabled(const log4c_category_t* a_category)
00217 {
00218 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_WARN);
00219 }
00220
00228 static inline int log4c_category_is_notice_enabled(const log4c_category_t* a_category)
00229 {
00230 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_NOTICE);
00231 }
00232
00240 static inline int log4c_category_is_info_enabled(const log4c_category_t* a_category)
00241 {
00242 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_INFO);
00243 }
00244
00252 static inline int log4c_category_is_debug_enabled(const log4c_category_t* a_category)
00253 {
00254 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_DEBUG);
00255 }
00256
00264 static inline int log4c_category_is_trace_enabled(const log4c_category_t* a_category)
00265 {
00266 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_TRACE);
00267 }
00268
00272 extern void __log4c_category_vlog(const log4c_category_t* a_category,
00273 const log4c_location_info_t* a_locinfo,
00274 int a_priority,
00275 const char* a_format,
00276 va_list a_args);
00277
00284 static inline void log4c_category_vlog(const log4c_category_t* a_category,
00285 int a_priority,
00286 const char* a_format,
00287 va_list a_args)
00288 {
00289 const log4c_location_info_t locinfo = LOG4C_LOCATION_INFO_INITIALIZER;
00290
00291 __log4c_category_vlog(a_category, &locinfo, a_priority, a_format, a_args);
00292 }
00293
00302 static inline void log4c_category_log(const log4c_category_t* a_category,
00303 int a_priority,
00304 const char* a_format,
00305 ...)
00306 {
00307 if (log4c_category_is_priority_enabled(a_category, a_priority)) {
00308 va_list va;
00309 va_start(va, a_format);
00310 log4c_category_vlog(a_category, a_priority, a_format, va);
00311 va_end(va);
00312 }
00313 }
00314
00322 static inline void log4c_category_fatal(const log4c_category_t* a_category,
00323 const char* a_format,
00324 ...)
00325 {
00326 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_FATAL)) {
00327 va_list va;
00328 va_start(va, a_format);
00329 log4c_category_vlog(a_category, LOG4C_PRIORITY_FATAL, a_format, va);
00330 va_end(va);
00331 }
00332 }
00333
00341 static inline void log4c_category_alert(const log4c_category_t* a_category,
00342 const char* a_format,
00343 ...)
00344 {
00345 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ALERT)) {
00346 va_list va;
00347 va_start(va, a_format);
00348 log4c_category_vlog(a_category, LOG4C_PRIORITY_ALERT, a_format, va);
00349 va_end(va);
00350 }
00351 }
00352
00360 static inline void log4c_category_crit(const log4c_category_t* a_category,
00361 const char* a_format,
00362 ...)
00363 {
00364 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_CRIT)) {
00365 va_list va;
00366 va_start(va, a_format);
00367 log4c_category_vlog(a_category, LOG4C_PRIORITY_CRIT, a_format, va);
00368 va_end(va);
00369 }
00370 }
00371
00379 static inline void log4c_category_error(const log4c_category_t* a_category,
00380 const char* a_format,
00381 ...)
00382 {
00383 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ERROR)) {
00384 va_list va;
00385 va_start(va, a_format);
00386 log4c_category_vlog(a_category, LOG4C_PRIORITY_ERROR, a_format, va);
00387 va_end(va);
00388 }
00389 }
00390
00398 static inline void log4c_category_warn(const log4c_category_t* a_category,
00399 const char* a_format,
00400 ...)
00401 {
00402 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_WARN)) {
00403 va_list va;
00404 va_start(va, a_format);
00405 log4c_category_vlog(a_category, LOG4C_PRIORITY_WARN, a_format, va);
00406 va_end(va);
00407 }
00408 }
00409
00417 static inline void log4c_category_notice(const log4c_category_t* a_category,
00418 const char* a_format,
00419 ...)
00420 {
00421 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_NOTICE)) {
00422 va_list va;
00423 va_start(va, a_format);
00424 log4c_category_vlog(a_category, LOG4C_PRIORITY_NOTICE, a_format, va);
00425 va_end(va);
00426 }
00427 }
00428
00436 static inline void log4c_category_info(const log4c_category_t* a_category,
00437 const char* a_format,
00438 ...)
00439 {
00440 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_INFO)) {
00441 va_list va;
00442 va_start(va, a_format);
00443 log4c_category_vlog(a_category, LOG4C_PRIORITY_INFO, a_format, va);
00444 va_end(va);
00445 }
00446 }
00447
00455 static inline void log4c_category_debug(const log4c_category_t* a_category,
00456 const char* a_format,
00457 ...)
00458 {
00459 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_DEBUG)) {
00460 va_list va;
00461 va_start(va, a_format);
00462 log4c_category_vlog(a_category, LOG4C_PRIORITY_DEBUG, a_format, va);
00463 va_end(va);
00464 }
00465 }
00466
00474 static inline void __log4c_category_trace(const log4c_category_t* a_category,
00475 const char* a_format,
00476 ...)
00477 {
00478 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_TRACE)) {
00479 va_list va;
00480 va_start(va, a_format);
00481 log4c_category_vlog(a_category, LOG4C_PRIORITY_TRACE, a_format, va);
00482 va_end(va);
00483 }
00484 }
00485
00486 #ifdef __GNUC__
00487 # define log4c_category_trace(a_category, a_format, ...) \
00488 __log4c_category_trace(a_category, log4c_location "\n" a_format, ##__VA_ARGS__ )
00489 #else
00490 # define log4c_category_trace __log4c_category_trace
00491 #endif
00492
00500 #ifdef __GNUC__
00501 # define log4c_category_define(a_category, a_name) \
00502 static log4c_category_t* a_category = NULL; \
00503 static void __attribute__ ((constructor)) __log4c_init_category##a_category(void) \
00504 { a_category = log4c_category_get(a_name); }
00505 #else
00506 # define log4c_category_define(a_category, a_name)
00507 #endif
00508
00512 struct __sd_factory;
00513 extern struct __sd_factory* log4c_category_factory;
00514
00515 __LOG4C_END_DECLS
00516
00517 #endif