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 LOG4C_API log4c_category_t* log4c_category_get(const char* a_name);
00047
00057 LOG4C_API int log4c_category_list(log4c_category_t** a_cats, int a_ncats);
00058
00068 LOG4C_API log4c_category_t* log4c_category_new(const char* a_name);
00069
00075 LOG4C_API void log4c_category_delete(log4c_category_t* a_category);
00076
00082 LOG4C_API const char* log4c_category_get_name(const log4c_category_t* a_category);
00083
00090 LOG4C_API const struct __log4c_appender* log4c_category_get_appender(
00091 const log4c_category_t* a_category);
00092
00099 LOG4C_API int log4c_category_get_additivity(const log4c_category_t* a_category);
00100
00106 LOG4C_API int log4c_category_get_priority(const log4c_category_t* a_category);
00107
00119 LOG4C_API int log4c_category_get_chainedpriority(const log4c_category_t* a_category);
00120
00128 LOG4C_API const struct __log4c_appender* log4c_category_set_appender(
00129 log4c_category_t* a_category,
00130 struct __log4c_appender* a_appender);
00139 LOG4C_API int log4c_category_set_priority(log4c_category_t* a_category,
00140 int a_priority);
00141
00149 LOG4C_API int log4c_category_set_additivity(log4c_category_t* a_category,
00150 int a_additivity);
00157 LOG4C_API void log4c_category_print(const log4c_category_t* a_category, FILE* a_stream);
00158
00166 #if !defined(_WIN32) && !defined(__HP_cc)
00167 static inline int log4c_category_is_priority_enabled(const log4c_category_t* a_category,
00168 int a_priority)
00169 {
00170 return log4c_category_get_chainedpriority(a_category) >= a_priority;
00171 }
00172 #else
00173 #define log4c_category_is_priority_enabled(a,b) \
00174 (log4c_category_get_chainedpriority(a) >= b)
00175 #endif
00176
00184 #if !defined(_WIN32) && !defined(__HP_cc)
00185 static inline int log4c_category_is_fatal_enabled(const log4c_category_t* a_category)
00186 {
00187 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_FATAL);
00188 }
00189 #else
00190 #define log4c_category_is_fatal_enabled(a) \
00191 (log4c_category_is_priority_enabled(a,LOG4C_PRIORITY_FATAL))
00192 #endif
00193
00201 #if !defined(_WIN32) && !defined(__HP_cc)
00202 static inline int log4c_category_is_alert_enabled(const log4c_category_t* a_category)
00203 {
00204 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ALERT);
00205 }
00206 #else
00207 #define log4c_category_is_alert_enabled(a) \
00208 (log4c_category_is_priority_enabled(a,LOG4C_PRIORITY_ALERT))
00209 #endif
00210
00218 #if !defined(_WIN32) && !defined(__HP_cc)
00219 static inline int log4c_category_is_crit_enabled(const log4c_category_t* a_category)
00220 {
00221 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_CRIT);
00222 }
00223 #else
00224 #define log4c_category_is_crit_enabled(a) \
00225 (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_CRIT))
00226 #endif
00227
00235 #if !defined(_WIN32) && !defined(__HP_cc)
00236 static inline int log4c_category_is_error_enabled(const log4c_category_t* a_category)
00237 {
00238 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ERROR);
00239 }
00240 #else
00241 #define log4c_category_is_error_enabled(a) \
00242 (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_ERROR))
00243 #endif
00244
00252 #if !defined(_WIN32) && !defined(__HP_cc)
00253 static inline int log4c_category_is_warn_enabled(const log4c_category_t* a_category)
00254 {
00255 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_WARN);
00256 }
00257 #else
00258 #define log4c_category_is_warn_enabled(a) \
00259 log4c_category_is_warn_enabled(a) \
00260 (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_WARN))
00261 #endif
00262
00270 #if !defined(_WIN32) && !defined(__HP_cc)
00271 static inline int log4c_category_is_notice_enabled(const log4c_category_t* a_category)
00272 {
00273 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_NOTICE);
00274 }
00275 #else
00276 #define log4c_category_is_notice_enabled(a) \
00277 (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_NOTICE))
00278 #endif
00279
00287 #if !defined(_WIN32) && !defined(__HP_cc)
00288 static inline int log4c_category_is_info_enabled(const log4c_category_t* a_category)
00289 {
00290 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_INFO);
00291 }
00292 #else
00293 #define log4c_category_is_info_enabled(a) \
00294 (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_INFO))
00295 #endif
00296
00304 #if !defined(_WIN32) && !defined(__HP_cc)
00305 static inline int log4c_category_is_debug_enabled(const log4c_category_t* a_category)
00306 {
00307 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_DEBUG);
00308 }
00309 #else
00310 #define log4c_category_is_debug_enabled(a) \
00311 (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_DEBUG))
00312 #endif
00313
00321 #if !defined(_WIN32) && !defined(__HP_cc)
00322 static inline int log4c_category_is_trace_enabled(const log4c_category_t* a_category)
00323 {
00324 return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_TRACE);
00325 }
00326 #else
00327 #define log4c_category_is_trace_enabled(a) \
00328 (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_TRACE))
00329 #endif
00330
00334 LOG4C_API void __log4c_category_vlog(const log4c_category_t* a_category,
00335 const log4c_location_info_t* a_locinfo,
00336 int a_priority,
00337 const char* a_format,
00338 va_list a_args);
00339
00347
00348
00349
00350
00351 static LOG4C_INLINE void log4c_category_vlog(const log4c_category_t* a_category,
00352 int a_priority,
00353 const char* a_format,
00354 va_list a_args)
00355 {
00356 const log4c_location_info_t locinfo = LOG4C_LOCATION_INFO_INITIALIZER(NULL);
00357
00358 __log4c_category_vlog(a_category, &locinfo, a_priority, a_format, a_args);
00359 }
00360
00369 static LOG4C_INLINE void log4c_category_log(const log4c_category_t* a_category,
00370 int a_priority,
00371 const char* a_format,
00372 ...)
00373 {
00374 if (log4c_category_is_priority_enabled(a_category, a_priority)) {
00375 va_list va;
00376 va_start(va, a_format);
00377 log4c_category_vlog(a_category, a_priority, a_format, va);
00378 va_end(va);
00379 }
00380 }
00381
00391 static LOG4C_INLINE void log4c_category_log_locinfo(
00392 const log4c_category_t* a_category,
00393 const log4c_location_info_t* a_locinfo,
00394 int a_priority,
00395 const char* a_format,
00396 ...)
00397 {
00398 if (log4c_category_is_priority_enabled(a_category, a_priority)) {
00399 va_list va;
00400 va_start(va, a_format);
00401 __log4c_category_vlog(a_category, a_locinfo, a_priority, a_format, va);
00402 va_end(va);
00403 }
00404 }
00405
00413 static LOG4C_INLINE void log4c_category_fatal(const log4c_category_t* a_category,
00414 const char* a_format,
00415 ...)
00416 {
00417 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_FATAL)) {
00418 va_list va;
00419 va_start(va, a_format);
00420 log4c_category_vlog(a_category, LOG4C_PRIORITY_FATAL, a_format, va);
00421 va_end(va);
00422 }
00423 }
00424
00432 static LOG4C_INLINE void log4c_category_alert(const log4c_category_t* a_category,
00433 const char* a_format,
00434 ...)
00435 {
00436 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ALERT)) {
00437 va_list va;
00438 va_start(va, a_format);
00439 log4c_category_vlog(a_category, LOG4C_PRIORITY_ALERT, a_format, va);
00440 va_end(va);
00441 }
00442 }
00443
00451 static LOG4C_INLINE void log4c_category_crit(const log4c_category_t* a_category,
00452 const char* a_format,
00453 ...)
00454 {
00455 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_CRIT)) {
00456 va_list va;
00457 va_start(va, a_format);
00458 log4c_category_vlog(a_category, LOG4C_PRIORITY_CRIT, a_format, va);
00459 va_end(va);
00460 }
00461 }
00462
00470 static LOG4C_INLINE void log4c_category_error(const log4c_category_t* a_category,
00471 const char* a_format,
00472 ...)
00473 {
00474 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ERROR)) {
00475 va_list va;
00476 va_start(va, a_format);
00477 log4c_category_vlog(a_category, LOG4C_PRIORITY_ERROR, a_format, va);
00478 va_end(va);
00479 }
00480 }
00481
00489 static LOG4C_INLINE void log4c_category_warn(const log4c_category_t* a_category,
00490 const char* a_format,
00491 ...)
00492 {
00493 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_WARN)) {
00494 va_list va;
00495 va_start(va, a_format);
00496 log4c_category_vlog(a_category, LOG4C_PRIORITY_WARN, a_format, va);
00497 va_end(va);
00498 }
00499 }
00500
00508 static LOG4C_INLINE void log4c_category_notice(const log4c_category_t* a_category,
00509 const char* a_format,
00510 ...)
00511 {
00512 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_NOTICE)) {
00513 va_list va;
00514 va_start(va, a_format);
00515 log4c_category_vlog(a_category, LOG4C_PRIORITY_NOTICE, a_format, va);
00516 va_end(va);
00517 }
00518 }
00519
00527 static LOG4C_INLINE void log4c_category_info(const log4c_category_t* a_category,
00528 const char* a_format,
00529 ...)
00530 {
00531 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_INFO)) {
00532 va_list va;
00533 va_start(va, a_format);
00534 log4c_category_vlog(a_category, LOG4C_PRIORITY_INFO, a_format, va);
00535 va_end(va);
00536 }
00537 }
00538
00546 static LOG4C_INLINE void log4c_category_debug(const log4c_category_t* a_category,
00547 const char* a_format,
00548 ...)
00549 {
00550 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_DEBUG)) {
00551 va_list va;
00552 va_start(va, a_format);
00553 log4c_category_vlog(a_category, LOG4C_PRIORITY_DEBUG, a_format, va);
00554 va_end(va);
00555 }
00556 }
00557
00565 static LOG4C_INLINE void __log4c_category_trace(const log4c_category_t* a_category,
00566 const char* a_format,
00567 ...)
00568 {
00569 if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_TRACE)) {
00570 va_list va;
00571 va_start(va, a_format);
00572 log4c_category_vlog(a_category, LOG4C_PRIORITY_TRACE, a_format, va);
00573 va_end(va);
00574 }
00575 }
00576
00577 #ifdef __GNUC__
00578
00579 #ifdef OLD_VARIADIC_MACRO
00580
00581 # define log4c_category_trace(a_category, a_format, args...) \
00582 __log4c_category_trace(a_category, log4c_location "\n" a_format, ##args )
00583
00584 #else
00585
00586 # define log4c_category_trace(a_category, a_format, ...) \
00587 __log4c_category_trace(a_category, log4c_location "\n" a_format, ##__VA_ARGS__ )
00588
00589 #endif
00590
00591
00592 #else
00593 # define log4c_category_trace __log4c_category_trace
00594 #endif
00595
00602 #ifdef __GNUC__
00603 # define log4c_category_define(a_category, a_name) \
00604 typedef log4c_category_t log4c_category_define_##a_category __attribute__((deprecated)); \
00605 static log4c_category_define_##a_category* a_category __attribute__ ((unused)) = NULL;
00606 #else
00607 # define log4c_category_define(a_category, a_name)
00608 #endif
00609
00613 struct __sd_factory;
00614 LOG4C_API struct __sd_factory* log4c_category_factory;
00615
00616 __LOG4C_END_DECLS
00617
00618 #endif