category.h
Go to the documentation of this file.
/* $Id: category.h,v 1.12 2013/09/29 17:41:39 valtri Exp $
*
* category.h
*
* Copyright 2001-2003, Meiosys (www.meiosys.com). All rights reserved.
*
* See the COPYING file for the terms of usage and distribution.
*/
#ifndef log4c_category_h
#define log4c_category_h
#include <stdio.h>
#include <stdarg.h>
#include <log4c/defs.h>
#include <log4c/priority.h>
#include <log4c/location_info.h>
__LOG4C_BEGIN_DECLS
struct __log4c_appender;
struct __log4c_category;
typedef struct __log4c_category log4c_category_t;
LOG4C_API log4c_category_t* log4c_category_get(const char* a_name);
LOG4C_API int log4c_category_list(log4c_category_t** a_cats, int a_ncats);
LOG4C_API log4c_category_t* log4c_category_new(const char* a_name);
LOG4C_API void log4c_category_delete(log4c_category_t* a_category);
LOG4C_API const char* log4c_category_get_name(const log4c_category_t* a_category);
LOG4C_API const struct __log4c_appender* log4c_category_get_appender(
const log4c_category_t* a_category);
LOG4C_API int log4c_category_get_additivity(const log4c_category_t* a_category);
LOG4C_API int log4c_category_get_priority(const log4c_category_t* a_category);
LOG4C_API int log4c_category_get_chainedpriority(const log4c_category_t* a_category);
LOG4C_API const struct __log4c_appender* log4c_category_set_appender(
log4c_category_t* a_category,
struct __log4c_appender* a_appender);
LOG4C_API int log4c_category_set_priority(log4c_category_t* a_category,
int a_priority);
LOG4C_API int log4c_category_set_additivity(log4c_category_t* a_category,
int a_additivity);
LOG4C_API void log4c_category_print(const log4c_category_t* a_category, FILE* a_stream);
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_priority_enabled(const log4c_category_t* a_category,
int a_priority)
{
return log4c_category_get_chainedpriority(a_category) >= a_priority;
}
#else
#define log4c_category_is_priority_enabled(a,b) \
(log4c_category_get_chainedpriority(a) >= b)
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_fatal_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_FATAL);
}
#else
#define log4c_category_is_fatal_enabled(a) \
(log4c_category_is_priority_enabled(a,LOG4C_PRIORITY_FATAL))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_alert_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ALERT);
}
#else
#define log4c_category_is_alert_enabled(a) \
(log4c_category_is_priority_enabled(a,LOG4C_PRIORITY_ALERT))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_crit_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_CRIT);
}
#else
#define log4c_category_is_crit_enabled(a) \
(log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_CRIT))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_error_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ERROR);
}
#else
#define log4c_category_is_error_enabled(a) \
(log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_ERROR))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_warn_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_WARN);
}
#else
#define log4c_category_is_warn_enabled(a) \
log4c_category_is_warn_enabled(a) \
(log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_WARN))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_notice_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_NOTICE);
}
#else
#define log4c_category_is_notice_enabled(a) \
(log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_NOTICE))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_info_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_INFO);
}
#else
#define log4c_category_is_info_enabled(a) \
(log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_INFO))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_debug_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_DEBUG);
}
#else
#define log4c_category_is_debug_enabled(a) \
(log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_DEBUG))
#endif
#if !defined(_WIN32) && !defined(__HP_cc)
static inline int log4c_category_is_trace_enabled(const log4c_category_t* a_category)
{
return log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_TRACE);
}
#else
#define log4c_category_is_trace_enabled(a) \
(log4c_category_is_priority_enabled(a, LOG4C_PRIORITY_TRACE))
#endif
LOG4C_API void __log4c_category_vlog(const log4c_category_t* a_category,
const log4c_location_info_t* a_locinfo,
int a_priority,
const char* a_format,
va_list a_args);
/* msvc doesn't allow "inline" nor variable args in a macro
* so cannot #define these ones.
*/
static LOG4C_INLINE void log4c_category_vlog(const log4c_category_t* a_category,
int a_priority,
const char* a_format,
va_list a_args)
{
const log4c_location_info_t locinfo = LOG4C_LOCATION_INFO_INITIALIZER(NULL);
__log4c_category_vlog(a_category, &locinfo, a_priority, a_format, a_args);
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 3, 4)))
static void log4c_category_log(const log4c_category_t* a_category,
int a_priority,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, a_priority)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, a_priority, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 4, 5)))
static 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,
...)
{
if (log4c_category_is_priority_enabled(a_category, a_priority)) {
va_list va;
va_start(va, a_format);
__log4c_category_vlog(a_category, a_locinfo, a_priority, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_fatal(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_FATAL)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_FATAL, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_alert(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ALERT)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_ALERT, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_crit(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_CRIT)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_CRIT, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_error(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_ERROR)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_ERROR, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_warn(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_WARN)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_WARN, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_notice(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_NOTICE)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_NOTICE, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_info(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_INFO)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_INFO, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void log4c_category_debug(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_DEBUG)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_DEBUG, a_format, va);
va_end(va);
}
}
LOG4C_INLINE LOG4C_ATTRIBUTE((format(printf, 2, 3)))
static void __log4c_category_trace(const log4c_category_t* a_category,
const char* a_format,
...)
{
if (log4c_category_is_priority_enabled(a_category, LOG4C_PRIORITY_TRACE)) {
va_list va;
va_start(va, a_format);
log4c_category_vlog(a_category, LOG4C_PRIORITY_TRACE, a_format, va);
va_end(va);
}
}
#ifdef __GNUC__
#ifdef OLD_VARIADIC_MACRO
# define log4c_category_trace(a_category, a_format, args...) \
__log4c_category_trace(a_category, log4c_location "\n" a_format, ##args )
#else
# define log4c_category_trace(a_category, a_format, ...) \
__log4c_category_trace(a_category, log4c_location "\n" a_format, ##__VA_ARGS__ )
#endif /* OLD_VARIADIC_MACRO */
#else
# define log4c_category_trace __log4c_category_trace
#endif /* __GNUC__ */
#ifdef __GNUC__
# define log4c_category_define(a_category, a_name) \
typedef log4c_category_t log4c_category_define_##a_category __attribute__((deprecated)); \
static log4c_category_define_##a_category* a_category __attribute__ ((unused)) = NULL;
#else
# define log4c_category_define(a_category, a_name)
#endif
struct __sd_factory;
LOG4C_API struct __sd_factory* log4c_category_factory;
__LOG4C_END_DECLS
#endif
log4c_category_is_debug_enabled
static int log4c_category_is_debug_enabled(const log4c_category_t *a_category)
Definition: category.h:305
log4c_category_is_warn_enabled
static int log4c_category_is_warn_enabled(const log4c_category_t *a_category)
Definition: category.h:253
log4c_category_is_alert_enabled
static int log4c_category_is_alert_enabled(const log4c_category_t *a_category)
Definition: category.h:202
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_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
location_info.h
The internal representation of caller location information.
log4c_category_is_crit_enabled
static int log4c_category_is_crit_enabled(const log4c_category_t *a_category)
Definition: category.h:219
log4c_category_get_chainedpriority
int log4c_category_get_chainedpriority(const log4c_category_t *a_category)
Definition: category.c:122
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_fatal
static LOG4C_INLINE void log4c_category_fatal(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:416
__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_fatal_enabled
static int log4c_category_is_fatal_enabled(const log4c_category_t *a_category)
Definition: category.h:185
LOG4C_PRIORITY_FATAL
Definition: priority.h:29
log4c_category_set_additivity
int log4c_category_set_additivity(log4c_category_t *a_category, int a_additivity)
Definition: category.c:180
log4c_category_is_error_enabled
static int log4c_category_is_error_enabled(const log4c_category_t *a_category)
Definition: category.h:236
log4c_category_get_priority
int log4c_category_get_priority(const log4c_category_t *a_category)
Definition: category.c:116
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_get_additivity
int log4c_category_get_additivity(const log4c_category_t *a_category)
Definition: category.c:142
log4c_category_alert
static LOG4C_INLINE void log4c_category_alert(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:436
LOG4C_PRIORITY_NOTICE
Definition: priority.h:34
LOG4C_PRIORITY_INFO
Definition: priority.h:35
LOG4C_PRIORITY_CRIT
Definition: priority.h:31
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_PRIORITY_ERROR
Definition: priority.h:32
LOG4C_PRIORITY_ALERT
Definition: priority.h:30
log4c_category_print
void log4c_category_print(const log4c_category_t *a_category, FILE *a_stream)
Definition: category.c:193
LOG4C_LOCATION_INFO_INITIALIZER
#define LOG4C_LOCATION_INFO_INITIALIZER(user_data)
Definition: location_info.h:54
priority.h
The priority class provides importance levels with which one can categorize log messages.
log4c_category_get_appender
const struct __log4c_appender * log4c_category_get_appender(const log4c_category_t *a_category)
Definition: category.c:136
LOG4C_PRIORITY_TRACE
Definition: priority.h:37
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_name
const char * log4c_category_get_name(const log4c_category_t *a_category)
Definition: category.c:110
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_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_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_category_is_notice_enabled
static int log4c_category_is_notice_enabled(const log4c_category_t *a_category)
Definition: category.h:271
log4c_category_info
static LOG4C_INLINE void log4c_category_info(const log4c_category_t *a_category, const char *a_format,...)
Definition: category.h:536
log4c_location_info_t
logging location information
Definition: location_info.h:39
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_is_trace_enabled
static int log4c_category_is_trace_enabled(const log4c_category_t *a_category)
Definition: category.h:322
log4c_category_t
struct __log4c_category log4c_category_t
Definition: category.h:37
LOG4C_PRIORITY_WARN
Definition: priority.h:33
log4c_category_delete
void log4c_category_delete(log4c_category_t *a_category)
Definition: category.c:100
log4c_category_set_priority
int log4c_category_set_priority(log4c_category_t *a_category, int a_priority)
Definition: category.c:148