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
22
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
31struct __log4c_appender;
32struct __log4c_category;
33
37typedef struct __log4c_category log4c_category_t;
38
46LOG4C_API log4c_category_t* log4c_category_get(const char* a_name);
47
57LOG4C_API int log4c_category_list(log4c_category_t** a_cats, int a_ncats);
58
68LOG4C_API log4c_category_t* log4c_category_new(const char* a_name);
69
75LOG4C_API void log4c_category_delete(log4c_category_t* a_category);
76
82LOG4C_API const char* log4c_category_get_name(const log4c_category_t* a_category);
83
90LOG4C_API const struct __log4c_appender* log4c_category_get_appender(
91 const log4c_category_t* a_category);
92
99LOG4C_API int log4c_category_get_additivity(const log4c_category_t* a_category);
100
106LOG4C_API int log4c_category_get_priority(const log4c_category_t* a_category);
107
119LOG4C_API int log4c_category_get_chainedpriority(const log4c_category_t* a_category);
120
128LOG4C_API const struct __log4c_appender* log4c_category_set_appender(
129 log4c_category_t* a_category,
130 struct __log4c_appender* a_appender);
139LOG4C_API int log4c_category_set_priority(log4c_category_t* a_category,
140 int a_priority);
141
149LOG4C_API int log4c_category_set_additivity(log4c_category_t* a_category,
150 int a_additivity);
157LOG4C_API void log4c_category_print(const log4c_category_t* a_category, FILE* a_stream);
158
166#if !defined(_WIN32) && !defined(__HP_cc)
167static 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)
185static 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)
202static 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)
219static 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)
236static 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)
253static 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)
271static 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)
288static 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)
305static 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)
322static 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
334LOG4C_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
346
347/* msvc doesn't allow "inline" nor variable args in a macro
348 * so cannot #define these ones.
349 */
350
351static 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
369LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 3, 4)))
370static 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
392LOG4C_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
415LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
416static 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
435LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
436static 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
455LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
456static 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
475LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
476static 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
495LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
496static 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
515LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
516static 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
535LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
536static 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
555LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
556static 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
575LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
576static 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
624struct __sd_factory;
625LOG4C_API struct __sd_factory* log4c_category_factory;
626
627__LOG4C_END_DECLS
628
629#endif
static LOG4C_INLINE void log4c_category_debug(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:556
int log4c_category_get_priority(const log4c_category_t *a_category)
Definition category.c:116
static int log4c_category_is_crit_enabled(const log4c_category_t *a_category)
Definition category.h:219
static LOG4C_INLINE void log4c_category_notice(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:516
static int log4c_category_is_alert_enabled(const log4c_category_t *a_category)
Definition category.h:202
const struct __log4c_appender * log4c_category_set_appender(log4c_category_t *a_category, struct __log4c_appender *a_appender)
Definition category.c:165
int log4c_category_get_additivity(const log4c_category_t *a_category)
Definition category.c:142
static LOG4C_INLINE void log4c_category_log(const log4c_category_t *a_category, int a_priority, const char *a_format,...)
Definition category.h:370
static LOG4C_INLINE void log4c_category_fatal(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:416
int log4c_category_set_additivity(log4c_category_t *a_category, int a_additivity)
Definition category.c:180
void log4c_category_delete(log4c_category_t *a_category)
Definition category.c:100
static LOG4C_INLINE void log4c_category_warn(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:496
static int log4c_category_is_error_enabled(const log4c_category_t *a_category)
Definition category.h:236
log4c_category_t * log4c_category_get(const char *a_name)
Definition category.c:50
log4c_category_t * log4c_category_new(const char *a_name)
Definition category.c:75
struct __log4c_category log4c_category_t
Definition category.h:37
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
int log4c_category_list(log4c_category_t **a_cats, int a_ncats)
Definition category.c:67
static int log4c_category_is_priority_enabled(const log4c_category_t *a_category, int a_priority)
Definition category.h:167
static LOG4C_INLINE void log4c_category_error(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:476
static LOG4C_INLINE void log4c_category_crit(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:456
static int log4c_category_is_debug_enabled(const log4c_category_t *a_category)
Definition category.h:305
static int log4c_category_is_warn_enabled(const log4c_category_t *a_category)
Definition category.h:253
static LOG4C_INLINE void log4c_category_alert(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:436
const char * log4c_category_get_name(const log4c_category_t *a_category)
Definition category.c:110
static int log4c_category_is_fatal_enabled(const log4c_category_t *a_category)
Definition category.h:185
int log4c_category_set_priority(log4c_category_t *a_category, int a_priority)
Definition category.c:148
void log4c_category_print(const log4c_category_t *a_category, FILE *a_stream)
Definition category.c:193
int log4c_category_get_chainedpriority(const log4c_category_t *a_category)
Definition category.c:122
static int log4c_category_is_notice_enabled(const log4c_category_t *a_category)
Definition category.h:271
static int log4c_category_is_trace_enabled(const log4c_category_t *a_category)
Definition category.h:322
const struct __log4c_appender * log4c_category_get_appender(const log4c_category_t *a_category)
Definition category.c:136
static int log4c_category_is_info_enabled(const log4c_category_t *a_category)
Definition category.h:288
static LOG4C_INLINE void log4c_category_info(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:536
static LOG4C_INLINE void __log4c_category_trace(const log4c_category_t *a_category, const char *a_format,...)
Definition category.h:576
The internal representation of caller location information.
#define LOG4C_LOCATION_INFO_INITIALIZER(user_data)
Definition location_info.h:54
The priority class provides importance levels with which one can categorize log messages.
@ LOG4C_PRIORITY_FATAL
Definition priority.h:29
@ LOG4C_PRIORITY_INFO
Definition priority.h:35
@ LOG4C_PRIORITY_WARN
Definition priority.h:33
@ LOG4C_PRIORITY_ERROR
Definition priority.h:32
@ LOG4C_PRIORITY_DEBUG
Definition priority.h:36
@ LOG4C_PRIORITY_CRIT
Definition priority.h:31
@ LOG4C_PRIORITY_NOTICE
Definition priority.h:34
@ LOG4C_PRIORITY_TRACE
Definition priority.h:37
@ LOG4C_PRIORITY_ALERT
Definition priority.h:30
logging location information
Definition location_info.h:40