log4c  1.2.1
category.h
Go to the documentation of this file.
1 /* $Id$
2  *
3  * category.h
4  *
5  * Copyright 2001-2003, Meiosys (www.meiosys.com). All rights reserved.
6  *
7  * See the COPYING file for the terms of usage and distribution.
8  */
9 
10 #ifndef log4c_category_h
11 #define log4c_category_h
12 
23 #include <stdio.h>
24 #include <stdarg.h>
25 #include <log4c/defs.h>
26 #include <log4c/priority.h>
27 #include <log4c/location_info.h>
28 
29 __LOG4C_BEGIN_DECLS
30 
31 struct __log4c_appender;
32 struct __log4c_category;
33 
37 typedef struct __log4c_category log4c_category_t;
38 
46 LOG4C_API log4c_category_t* log4c_category_get(const char* a_name);
47 
57 LOG4C_API int log4c_category_list(log4c_category_t** a_cats, int a_ncats);
58 
68 LOG4C_API log4c_category_t* log4c_category_new(const char* a_name);
69 
75 LOG4C_API void log4c_category_delete(log4c_category_t* a_category);
76 
82 LOG4C_API const char* log4c_category_get_name(const log4c_category_t* a_category);
83 
90 LOG4C_API const struct __log4c_appender* log4c_category_get_appender(
91  const log4c_category_t* a_category);
92 
99 LOG4C_API int log4c_category_get_additivity(const log4c_category_t* a_category);
100 
106 LOG4C_API int log4c_category_get_priority(const log4c_category_t* a_category);
107 
119 LOG4C_API int log4c_category_get_chainedpriority(const log4c_category_t* a_category);
120 
128 LOG4C_API const struct __log4c_appender* log4c_category_set_appender(
129  log4c_category_t* a_category,
130  struct __log4c_appender* a_appender);
139 LOG4C_API int log4c_category_set_priority(log4c_category_t* a_category,
140  int a_priority);
141 
149 LOG4C_API int log4c_category_set_additivity(log4c_category_t* a_category,
150  int a_additivity);
157 LOG4C_API void log4c_category_print(const log4c_category_t* a_category, FILE* a_stream);
158 
166 #if !defined(_WIN32) && !defined(__HP_cc)
167 static inline int log4c_category_is_priority_enabled(const log4c_category_t* a_category,
168  int a_priority)
169 {
170  return log4c_category_get_chainedpriority(a_category) >= a_priority;
171 }
172 #else
173 #define log4c_category_is_priority_enabled(a,b) \
174  (log4c_category_get_chainedpriority(a) >= b)
175 #endif
176 
184 #if !defined(_WIN32) && !defined(__HP_cc)
185 static inline int log4c_category_is_fatal_enabled(const log4c_category_t* a_category)
186 {
188 }
189 #else
190 #define log4c_category_is_fatal_enabled(a) \
191  (log4c_category_is_priority_enabled(a,LOG4C_PRIORITY_FATAL))
192 #endif
193 
201 #if !defined(_WIN32) && !defined(__HP_cc)
202 static inline int log4c_category_is_alert_enabled(const log4c_category_t* a_category)
203 {
205 }
206 #else
207 #define log4c_category_is_alert_enabled(a) \
208  (log4c_category_is_priority_enabled(a,LOG4C_PRIORITY_ALERT))
209 #endif
210 
218 #if !defined(_WIN32) && !defined(__HP_cc)
219 static inline int log4c_category_is_crit_enabled(const log4c_category_t* a_category)
220 {
222 }
223 #else
224 #define log4c_category_is_crit_enabled(a) \
225  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_CRIT))
226 #endif
227 
235 #if !defined(_WIN32) && !defined(__HP_cc)
236 static inline int log4c_category_is_error_enabled(const log4c_category_t* a_category)
237 {
239 }
240 #else
241 #define log4c_category_is_error_enabled(a) \
242  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_ERROR))
243 #endif
244 
252 #if !defined(_WIN32) && !defined(__HP_cc)
253 static inline int log4c_category_is_warn_enabled(const log4c_category_t* a_category)
254 {
256 }
257 #else
258 #define log4c_category_is_warn_enabled(a) \
259  log4c_category_is_warn_enabled(a) \
260  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_WARN))
261 #endif
262 
270 #if !defined(_WIN32) && !defined(__HP_cc)
271 static inline int log4c_category_is_notice_enabled(const log4c_category_t* a_category)
272 {
274 }
275 #else
276 #define log4c_category_is_notice_enabled(a) \
277  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_NOTICE))
278 #endif
279 
287 #if !defined(_WIN32) && !defined(__HP_cc)
288 static inline int log4c_category_is_info_enabled(const log4c_category_t* a_category)
289 {
291 }
292 #else
293 #define log4c_category_is_info_enabled(a) \
294  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_INFO))
295 #endif
296 
304 #if !defined(_WIN32) && !defined(__HP_cc)
305 static inline int log4c_category_is_debug_enabled(const log4c_category_t* a_category)
306 {
308 }
309 #else
310 #define log4c_category_is_debug_enabled(a) \
311  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_DEBUG))
312 #endif
313 
321 #if !defined(_WIN32) && !defined(__HP_cc)
322 static inline int log4c_category_is_trace_enabled(const log4c_category_t* a_category)
323 {
325 }
326 #else
327 #define log4c_category_is_trace_enabled(a) \
328  (log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_TRACE))
329 #endif
330 
334 LOG4C_API void __log4c_category_vlog(const log4c_category_t* a_category,
335  const log4c_location_info_t* a_locinfo,
336  int a_priority,
337  const char* a_format,
338  va_list a_args);
339 
347 /* msvc doesn't allow "inline" nor variable args in a macro
348  * so cannot #define these ones.
349  */
350 
351 static LOG4C_INLINE void log4c_category_vlog(const log4c_category_t* a_category,
352  int a_priority,
353  const char* a_format,
354  va_list a_args)
355 {
357 
358  __log4c_category_vlog(a_category, &locinfo, a_priority, a_format, a_args);
359 }
360 
369 static LOG4C_INLINE void log4c_category_log(const log4c_category_t* a_category,
370  int a_priority,
371  const char* a_format,
372  ...)
373 {
374  if (log4c_category_is_priority_enabled(a_category, a_priority)) {
375  va_list va;
376  va_start(va, a_format);
377  log4c_category_vlog(a_category, a_priority, a_format, va);
378  va_end(va);
379  }
380 }
381 
391 static LOG4C_INLINE void log4c_category_log_locinfo(
392  const log4c_category_t* a_category,
393  const log4c_location_info_t* a_locinfo,
394  int a_priority,
395  const char* a_format,
396  ...)
397 {
398  if (log4c_category_is_priority_enabled(a_category, a_priority)) {
399  va_list va;
400  va_start(va, a_format);
401  __log4c_category_vlog(a_category, a_locinfo, a_priority, a_format, va);
402  va_end(va);
403  }
404 }
405 
413 static LOG4C_INLINE void log4c_category_fatal(const log4c_category_t* a_category,
414  const char* a_format,
415  ...)
416 {
418  va_list va;
419  va_start(va, a_format);
420  log4c_category_vlog(a_category, LOG4C_PRIORITY_FATAL, a_format, va);
421  va_end(va);
422  }
423 }
424 
432 static LOG4C_INLINE void log4c_category_alert(const log4c_category_t* a_category,
433  const char* a_format,
434  ...)
435 {
437  va_list va;
438  va_start(va, a_format);
439  log4c_category_vlog(a_category, LOG4C_PRIORITY_ALERT, a_format, va);
440  va_end(va);
441  }
442 }
443 
451 static LOG4C_INLINE void log4c_category_crit(const log4c_category_t* a_category,
452  const char* a_format,
453  ...)
454 {
456  va_list va;
457  va_start(va, a_format);
458  log4c_category_vlog(a_category, LOG4C_PRIORITY_CRIT, a_format, va);
459  va_end(va);
460  }
461 }
462 
470 static LOG4C_INLINE void log4c_category_error(const log4c_category_t* a_category,
471  const char* a_format,
472  ...)
473 {
475  va_list va;
476  va_start(va, a_format);
477  log4c_category_vlog(a_category, LOG4C_PRIORITY_ERROR, a_format, va);
478  va_end(va);
479  }
480 }
481 
489 static LOG4C_INLINE void log4c_category_warn(const log4c_category_t* a_category,
490  const char* a_format,
491  ...)
492 {
494  va_list va;
495  va_start(va, a_format);
496  log4c_category_vlog(a_category, LOG4C_PRIORITY_WARN, a_format, va);
497  va_end(va);
498  }
499 }
500 
508 static LOG4C_INLINE void log4c_category_notice(const log4c_category_t* a_category,
509  const char* a_format,
510  ...)
511 {
513  va_list va;
514  va_start(va, a_format);
515  log4c_category_vlog(a_category, LOG4C_PRIORITY_NOTICE, a_format, va);
516  va_end(va);
517  }
518 }
519 
527 static LOG4C_INLINE void log4c_category_info(const log4c_category_t* a_category,
528  const char* a_format,
529  ...)
530 {
532  va_list va;
533  va_start(va, a_format);
534  log4c_category_vlog(a_category, LOG4C_PRIORITY_INFO, a_format, va);
535  va_end(va);
536  }
537 }
538 
546 static LOG4C_INLINE void log4c_category_debug(const log4c_category_t* a_category,
547  const char* a_format,
548  ...)
549 {
551  va_list va;
552  va_start(va, a_format);
553  log4c_category_vlog(a_category, LOG4C_PRIORITY_DEBUG, a_format, va);
554  va_end(va);
555  }
556 }
557 
565 static LOG4C_INLINE void __log4c_category_trace(const log4c_category_t* a_category,
566  const char* a_format,
567  ...)
568 {
570  va_list va;
571  va_start(va, a_format);
572  log4c_category_vlog(a_category, LOG4C_PRIORITY_TRACE, a_format, va);
573  va_end(va);
574  }
575 }
576 
577 #ifdef __GNUC__
578 
579 #ifdef OLD_VARIADIC_MACRO
580 
581 # define log4c_category_trace(a_category, a_format, args...) \
582  __log4c_category_trace(a_category, log4c_location "\n" a_format, ##args )
583 
584 #else
585 
586 # define log4c_category_trace(a_category, a_format, ...) \
587  __log4c_category_trace(a_category, log4c_location "\n" a_format, ##__VA_ARGS__ )
588 
589 #endif /* OLD_VARIADIC_MACRO */
590 
591 
592 #else
593 # define log4c_category_trace __log4c_category_trace
594 #endif /* __GNUC__ */
595 
602 #ifdef __GNUC__
603 # define log4c_category_define(a_category, a_name) \
604  typedef log4c_category_t log4c_category_define_##a_category __attribute__((deprecated)); \
605  static log4c_category_define_##a_category* a_category __attribute__ ((unused)) = NULL;
606 #else
607 # define log4c_category_define(a_category, a_name)
608 #endif
609 
613 struct __sd_factory;
614 LOG4C_API struct __sd_factory* log4c_category_factory;
615 
616 __LOG4C_END_DECLS
617 
618 #endif