2008-02-27 20:56:47 +03:00
|
|
|
/*
|
|
|
|
* libcsync -- a library to sync a directory with another
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 by Andreas Schneider <mail@cynapses.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file csync_log.h
|
|
|
|
*
|
|
|
|
* @brief Logging interface of csync
|
|
|
|
*
|
|
|
|
* @defgroup csyncLogInternals csync logging internals
|
|
|
|
* @ingroup csyncInternalAPI
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CSYNC_LOG_H
|
|
|
|
#define _CSYNC_LOG_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-04-25 12:56:23 +04:00
|
|
|
#ifdef CSYNC_TEST
|
|
|
|
#undef WITH_LOG4C
|
|
|
|
#endif
|
|
|
|
|
2008-02-27 20:56:47 +03:00
|
|
|
#ifdef WITH_LOG4C
|
|
|
|
#include "log4c.h"
|
|
|
|
#else
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CSYNC_LOG_CATEGORY_NAME
|
|
|
|
#define CSYNC_LOG_CATEGORY_NAME "root"
|
|
|
|
#endif
|
|
|
|
|
2008-06-27 20:51:44 +04:00
|
|
|
/* GCC have printf type attribute check. */
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
|
|
|
|
#else
|
|
|
|
#define PRINTF_ATTRIBUTE(a,b)
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
|
2011-03-23 21:44:30 +03:00
|
|
|
/*#define CSYNC_LOG(priority, fmt, ...) \
|
|
|
|
csync_log((char *) CSYNC_LOG_CATEGORY_NAME, priority, fmt, ## __VA_ARGS__)*/
|
|
|
|
/*
|
|
|
|
* fix hundreds of these warnings:
|
|
|
|
* csync.c:272:75: warning: ISO C99 requires rest arguments to be used [enabled by default]
|
|
|
|
* The ## token in combination with __VA_ARGS__ is a gcc extension that's not part of ISO C99
|
|
|
|
* http://stackoverflow.com/questions/4100746/suppressing-iso-c99-requires-rest-arguments-to-be-used
|
|
|
|
*/
|
|
|
|
#define CSYNC_LOG(priority, ...) \
|
|
|
|
csync_log((char *) CSYNC_LOG_CATEGORY_NAME, priority, __VA_ARGS__)
|
2008-02-27 20:56:47 +03:00
|
|
|
|
|
|
|
#ifdef WITH_LOG4C
|
|
|
|
#define CSYNC_LOG_PRIORITY_FATAL LOG4C_PRIORITY_FATAL
|
|
|
|
#define CSYNC_LOG_PRIORITY_ALERT LOG4C_PRIORITY_ALERT
|
|
|
|
#define CSYNC_LOG_PRIORITY_CRIT LOG4C_PRIORITY_CRIT
|
|
|
|
#define CSYNC_LOG_PRIORITY_ERROR LOG4C_PRIORITY_ERROR
|
|
|
|
#define CSYNC_LOG_PRIORITY_WARN LOG4C_PRIORITY_WARN
|
|
|
|
#define CSYNC_LOG_PRIORITY_NOTICE LOG4C_PRIORITY_NOTICE
|
|
|
|
#define CSYNC_LOG_PRIORITY_INFO LOG4C_PRIORITY_INFO
|
|
|
|
#define CSYNC_LOG_PRIORITY_DEBUG LOG4C_PRIORITY_DEBUG
|
|
|
|
#define CSYNC_LOG_PRIORITY_TRACE LOG4C_PRIORITY_TRACE
|
|
|
|
#define CSYNC_LOG_PRIORITY_NOTSET LOG4C_PRIORITY_NOTSET
|
|
|
|
#define CSYNC_LOG_PRIORITY_UNKNOWN LOG4C_PRIORITY_UNKNOWN
|
|
|
|
#else
|
|
|
|
#define LOG4C_INLINE inline
|
|
|
|
#define CSYNC_LOG_PRIORITY_FATAL 000
|
|
|
|
#define CSYNC_LOG_PRIORITY_ALERT 100
|
|
|
|
#define CSYNC_LOG_PRIORITY_CRIT 200
|
|
|
|
#define CSYNC_LOG_PRIORITY_ERROR 300
|
|
|
|
#define CSYNC_LOG_PRIORITY_WARN 500
|
|
|
|
#define CSYNC_LOG_PRIORITY_NOTICE 500
|
|
|
|
#define CSYNC_LOG_PRIORITY_INFO 600
|
|
|
|
#define CSYNC_LOG_PRIORITY_DEBUG 700
|
|
|
|
#define CSYNC_LOG_PRIORITY_TRACE 800
|
|
|
|
#define CSYNC_LOG_PRIORITY_NOTSET 900
|
|
|
|
#define CSYNC_LOG_PRIORITY_UNKNOWN 1000
|
|
|
|
#endif
|
|
|
|
|
2009-05-22 22:23:54 +04:00
|
|
|
static LOG4C_INLINE void csync_log(char *catName, int a_priority,
|
|
|
|
const char* a_format,...) PRINTF_ATTRIBUTE(3, 4);
|
2008-02-27 20:56:47 +03:00
|
|
|
/**
|
|
|
|
* @brief The constructor of the logging mechanism
|
|
|
|
*
|
|
|
|
* @return 0 on success, less than 0 if an error occured.
|
|
|
|
*/
|
|
|
|
static LOG4C_INLINE int csync_log_init() {
|
|
|
|
#ifdef WITH_LOG4C
|
2009-05-22 22:23:54 +04:00
|
|
|
return log4c_init();
|
2008-02-27 20:56:47 +03:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Load resource configuration file
|
|
|
|
*
|
|
|
|
* @param Path to the file to load
|
|
|
|
*
|
|
|
|
* @return 0 on success, less than 0 if an error occured.
|
|
|
|
**/
|
|
|
|
static LOG4C_INLINE int csync_log_load(const char *path){
|
|
|
|
#ifdef WITH_LOG4C
|
2009-05-22 22:23:54 +04:00
|
|
|
return log4c_load(path);
|
2008-02-27 20:56:47 +03:00
|
|
|
#else
|
2008-04-25 13:26:20 +04:00
|
|
|
if (path == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-27 20:56:47 +03:00
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The destructor of the logging mechanism
|
|
|
|
*
|
|
|
|
* @return 0 on success, less than 0 if an error occured.
|
|
|
|
*/
|
|
|
|
static LOG4C_INLINE int csync_log_fini(){
|
|
|
|
#ifdef WITH_LOG4C
|
2009-05-22 22:23:54 +04:00
|
|
|
return log4c_fini();
|
2008-02-27 20:56:47 +03:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static LOG4C_INLINE int csync_log_setappender(char *catName, char *appName) {
|
|
|
|
#ifdef WITH_LOG4C
|
2009-05-22 22:23:54 +04:00
|
|
|
log4c_category_set_appender(log4c_category_get(catName),
|
|
|
|
log4c_appender_get(appName));
|
2008-04-25 13:26:20 +04:00
|
|
|
return 0;
|
2008-02-27 20:56:47 +03:00
|
|
|
#else
|
2008-04-25 13:26:20 +04:00
|
|
|
if (catName == NULL || appName == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
2008-02-27 20:56:47 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-05-22 22:23:54 +04:00
|
|
|
static LOG4C_INLINE void csync_log(char *catName, int a_priority,
|
|
|
|
const char* a_format,...) {
|
2008-02-27 20:56:47 +03:00
|
|
|
#ifdef WITH_LOG4C
|
|
|
|
const log4c_category_t* a_category = log4c_category_get(catName);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
va_list va;
|
|
|
|
va_start(va, a_format);
|
2008-04-25 13:26:20 +04:00
|
|
|
if (a_priority > 0) {
|
|
|
|
printf("%s - ", catName);
|
|
|
|
}
|
2008-02-27 20:56:47 +03:00
|
|
|
vprintf(a_format, va);
|
|
|
|
va_end(va);
|
2008-04-25 13:26:20 +04:00
|
|
|
printf("\n");
|
2008-02-27 20:56:47 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* }@
|
|
|
|
*/
|
|
|
|
#endif /* _CSYNC_LOG_H */
|
2009-05-22 22:23:54 +04:00
|
|
|
|
2009-05-13 12:12:07 +04:00
|
|
|
/* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */
|