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
log4c_category_alert
static LOG4C_INLINE void log4c_category_alert(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:436
logging_event.h
the internal representation of logging events.
category.h
central class in the log4c package.
log4c_category_fatal
static LOG4C_INLINE void log4c_category_fatal(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:416
log4c_category_info
static LOG4C_INLINE void log4c_category_info(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:536
location_info.h
The internal representation of caller location information.
log4c_category_print
void log4c_category_print(const log4c_category_t *a_category, FILE *a_stream)
Definition: category.c:193
log4c_category_is_notice_enabled
static int log4c_category_is_notice_enabled(const log4c_category_t *a_category)
Definition: category.h:271
log4c_appender_t
struct __log4c_appender log4c_appender_t
Definition: appender.h:34
LOG4C_PRIORITY_UNKNOWN
@ LOG4C_PRIORITY_UNKNOWN
Definition: priority.h:39
log4c_category_delete
void log4c_category_delete(log4c_category_t *a_category)
Definition: category.c:100
priority.h
The priority class provides importance levels with which one can categorize log messages.
rc.h
log4c resource configuration
log4c_category_get_additivity
int log4c_category_get_additivity(const log4c_category_t *a_category)
Definition: category.c:142
LOG4C_PRIORITY_FATAL
@ LOG4C_PRIORITY_FATAL
Definition: priority.h:29
log4c_category_is_alert_enabled
static int log4c_category_is_alert_enabled(const log4c_category_t *a_category)
Definition: category.h:202
log4c_category_get_name
const char * log4c_category_get_name(const log4c_category_t *a_category)
Definition: category.c:110
log4c_category_is_warn_enabled
static int log4c_category_is_warn_enabled(const log4c_category_t *a_category)
Definition: category.h:253
LOG4C_PRIORITY_NOTSET
@ LOG4C_PRIORITY_NOTSET
Definition: priority.h:38
log4c_category_error
static LOG4C_INLINE void log4c_category_error(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:476
log4c_category_get_appender
const struct __log4c_appender * log4c_category_get_appender(const log4c_category_t *a_category)
Definition: category.c:136
log4c_category_log_locinfo
static LOG4C_INLINE void log4c_category_log_locinfo(const log4c_category_t *a_category, const log4c_location_info_t *a_locinfo, int a_priority, const char *a_format,...)
Definition: category.h:393
LOG4C_PRIORITY_WARN
@ LOG4C_PRIORITY_WARN
Definition: priority.h:33
log4c_category_is_trace_enabled
static int log4c_category_is_trace_enabled(const log4c_category_t *a_category)
Definition: category.h:322
log4c_category_list
int log4c_category_list(log4c_category_t **a_cats, int a_ncats)
Definition: category.c:67
log4c_category_set_appender
const struct __log4c_appender * log4c_category_set_appender(log4c_category_t *a_category, struct __log4c_appender *a_appender)
Definition: category.c:165
log4c_category_new
log4c_category_t * log4c_category_new(const char *a_name)
Definition: category.c:75
LOG4C_PRIORITY_CRIT
@ LOG4C_PRIORITY_CRIT
Definition: priority.h:31
__log4c_category_trace
static LOG4C_INLINE void __log4c_category_trace(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:576
log4c_category_is_debug_enabled
static int log4c_category_is_debug_enabled(const log4c_category_t *a_category)
Definition: category.h:305
log4c_category_t
struct __log4c_category log4c_category_t
Definition: category.h:37
LOG4C_PRIORITY_ERROR
@ LOG4C_PRIORITY_ERROR
Definition: priority.h:32
LOG4C_PRIORITY_NOTICE
@ LOG4C_PRIORITY_NOTICE
Definition: priority.h:34
log4c_category_set_priority
int log4c_category_set_priority(log4c_category_t *a_category, int a_priority)
Definition: category.c:148
log4c_rc
log4c_rc_t *const log4c_rc
Definition: rc.h:49
log4c_category_notice
static LOG4C_INLINE void log4c_category_notice(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:516
log4c_priority_to_string
const char * log4c_priority_to_string(int a_priority)
Definition: priority.c:32
log4c_category_log
static LOG4C_INLINE void log4c_category_log(const log4c_category_t *a_category, int a_priority, const char *a_format,...)
Definition: category.h:370
log4c_category_crit
static LOG4C_INLINE void log4c_category_crit(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:456
LOG4C_PRIORITY_DEBUG
@ LOG4C_PRIORITY_DEBUG
Definition: priority.h:36
log4c_category_get
log4c_category_t * log4c_category_get(const char *a_name)
Definition: category.c:50
log4c_category_get_chainedpriority
int log4c_category_get_chainedpriority(const log4c_category_t *a_category)
Definition: category.c:122
log4c_category_debug
static LOG4C_INLINE void log4c_category_debug(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:556
log4c_logging_event_t
logging event object
Definition: logging_event.h:50
log4c_category_warn
static LOG4C_INLINE void log4c_category_warn(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:496
log4c_category_get_priority
int log4c_category_get_priority(const log4c_category_t *a_category)
Definition: category.c:116
log4c_appender_append
int log4c_appender_append(log4c_appender_t *a_appender, log4c_logging_event_t *a_event)
Definition: appender.c:256
log4c_category_is_fatal_enabled
static int log4c_category_is_fatal_enabled(const log4c_category_t *a_category)
Definition: category.h:185
LOG4C_PRIORITY_INFO
@ LOG4C_PRIORITY_INFO
Definition: priority.h:35
LOG4C_PRIORITY_TRACE
@ LOG4C_PRIORITY_TRACE
Definition: priority.h:37
LOG4C_PRIORITY_ALERT
@ LOG4C_PRIORITY_ALERT
Definition: priority.h:30
log4c_category_is_error_enabled
static int log4c_category_is_error_enabled(const log4c_category_t *a_category)
Definition: category.h:236
appender.h
Implement this interface for your own strategies for printing log statements.
log4c_category_set_additivity
int log4c_category_set_additivity(log4c_category_t *a_category, int a_additivity)
Definition: category.c:180
LOG4C_LOCATION_INFO_INITIALIZER
#define LOG4C_LOCATION_INFO_INITIALIZER(user_data)
Definition: location_info.h:54
log4c_category_is_info_enabled
static int log4c_category_is_info_enabled(const log4c_category_t *a_category)
Definition: category.h:288
log4c_category_is_priority_enabled
static int log4c_category_is_priority_enabled(const log4c_category_t *a_category, int a_priority)
Definition: category.h:167
log4c_category_is_crit_enabled
static int log4c_category_is_crit_enabled(const log4c_category_t *a_category)
Definition: category.h:219
log4c_appender_get_name
const char * log4c_appender_get_name(const log4c_appender_t *a_appender)
Definition: appender.c:157
log4c_location_info_t
logging location information
Definition: location_info.h:40