log4c  1.2.4
category.h
Go to the documentation of this file.
1 /* $Id: category.h,v 1.12 2013/09/29 17:41:39 valtri Exp $
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 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 3, 4)))
370 static void log4c_category_log(const log4c_category_t* a_category,
371  int a_priority,
372  const char* a_format,
373  ...)
374 {
375  if (log4c_category_is_priority_enabled(a_category, a_priority)) {
376  va_list va;
377  va_start(va, a_format);
378  log4c_category_vlog(a_category, a_priority, a_format, va);
379  va_end(va);
380  }
381 }
382 
392 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 4, 5)))
394  const log4c_category_t* a_category,
395  const log4c_location_info_t* a_locinfo,
396  int a_priority,
397  const char* a_format,
398  ...)
399 {
400  if (log4c_category_is_priority_enabled(a_category, a_priority)) {
401  va_list va;
402  va_start(va, a_format);
403  __log4c_category_vlog(a_category, a_locinfo, a_priority, a_format, va);
404  va_end(va);
405  }
406 }
407 
415 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
416 static void log4c_category_fatal(const log4c_category_t* a_category,
417  const char* a_format,
418  ...)
419 {
421  va_list va;
422  va_start(va, a_format);
423  log4c_category_vlog(a_category, LOG4C_PRIORITY_FATAL, a_format, va);
424  va_end(va);
425  }
426 }
427 
435 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
436 static void log4c_category_alert(const log4c_category_t* a_category,
437  const char* a_format,
438  ...)
439 {
441  va_list va;
442  va_start(va, a_format);
443  log4c_category_vlog(a_category, LOG4C_PRIORITY_ALERT, a_format, va);
444  va_end(va);
445  }
446 }
447 
455 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
456 static void log4c_category_crit(const log4c_category_t* a_category,
457  const char* a_format,
458  ...)
459 {
461  va_list va;
462  va_start(va, a_format);
463  log4c_category_vlog(a_category, LOG4C_PRIORITY_CRIT, a_format, va);
464  va_end(va);
465  }
466 }
467 
475 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
476 static void log4c_category_error(const log4c_category_t* a_category,
477  const char* a_format,
478  ...)
479 {
481  va_list va;
482  va_start(va, a_format);
483  log4c_category_vlog(a_category, LOG4C_PRIORITY_ERROR, a_format, va);
484  va_end(va);
485  }
486 }
487 
495 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
496 static void log4c_category_warn(const log4c_category_t* a_category,
497  const char* a_format,
498  ...)
499 {
501  va_list va;
502  va_start(va, a_format);
503  log4c_category_vlog(a_category, LOG4C_PRIORITY_WARN, a_format, va);
504  va_end(va);
505  }
506 }
507 
515 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
516 static void log4c_category_notice(const log4c_category_t* a_category,
517  const char* a_format,
518  ...)
519 {
521  va_list va;
522  va_start(va, a_format);
523  log4c_category_vlog(a_category, LOG4C_PRIORITY_NOTICE, a_format, va);
524  va_end(va);
525  }
526 }
527 
535 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
536 static void log4c_category_info(const log4c_category_t* a_category,
537  const char* a_format,
538  ...)
539 {
541  va_list va;
542  va_start(va, a_format);
543  log4c_category_vlog(a_category, LOG4C_PRIORITY_INFO, a_format, va);
544  va_end(va);
545  }
546 }
547 
555 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
556 static void log4c_category_debug(const log4c_category_t* a_category,
557  const char* a_format,
558  ...)
559 {
561  va_list va;
562  va_start(va, a_format);
563  log4c_category_vlog(a_category, LOG4C_PRIORITY_DEBUG, a_format, va);
564  va_end(va);
565  }
566 }
567 
575 LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
576 static void __log4c_category_trace(const log4c_category_t* a_category,
577  const char* a_format,
578  ...)
579 {
581  va_list va;
582  va_start(va, a_format);
583  log4c_category_vlog(a_category, LOG4C_PRIORITY_TRACE, a_format, va);
584  va_end(va);
585  }
586 }
587 
588 #ifdef __GNUC__
589 
590 #ifdef OLD_VARIADIC_MACRO
591 
592 # define log4c_category_trace(a_category, a_format, args...) \
593  __log4c_category_trace(a_category, log4c_location "\n" a_format, ##args )
594 
595 #else
596 
597 # define log4c_category_trace(a_category, a_format, ...) \
598  __log4c_category_trace(a_category, log4c_location "\n" a_format, ##__VA_ARGS__ )
599 
600 #endif /* OLD_VARIADIC_MACRO */
601 
602 
603 #else
604 # define log4c_category_trace __log4c_category_trace
605 #endif /* __GNUC__ */
606 
613 #ifdef __GNUC__
614 # define log4c_category_define(a_category, a_name) \
615  typedef log4c_category_t log4c_category_define_##a_category __attribute__((deprecated)); \
616  static log4c_category_define_##a_category* a_category __attribute__ ((unused)) = NULL;
617 #else
618 # define log4c_category_define(a_category, a_name)
619 #endif
620 
624 struct __sd_factory;
625 LOG4C_API struct __sd_factory* log4c_category_factory;
626 
627 __LOG4C_END_DECLS
628 
629 #endif