From 33dce847285b9368ff9737835cf20126dc6b63c7 Mon Sep 17 00:00:00 2001 From: Tushar Gohad Date: Fri, 18 Jul 2014 04:42:38 -0700 Subject: [PATCH] Add syslog based logging routines Signed-off-by: Tushar Gohad --- configure.ac | 8 ++++---- include/config.h.in | 18 ++++++------------ include/erasurecode/erasurecode_helpers.h | 14 +++++++++++--- include/erasurecode/erasurecode_stdinc.h | 3 +++ 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index c64eeb4..21c7df7 100644 --- a/configure.ac +++ b/configure.ac @@ -29,11 +29,11 @@ dnl Check for C library headers AC_HEADER_STDC AC_CHECK_HEADERS(sys/types.h stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h \ string.h strings.h inttypes.h stdint.h ctype.h math.h iconv.h \ - signal.h dlfcn.h pthread.h unistd.h limits.h errno.h) -AC_CHECK_FUNCS(malloc calloc realloc free) + signal.h dlfcn.h pthread.h unistd.h limits.h errno.h syslog.h) +AC_CHECK_FUNCS(malloc calloc realloc free openlog) -# Check for jerasure/gf_complete headers -AC_CHECK_HEADERS(jerasure.h cauchy.h galois.h liberation.h reed_sol.h gf_complete.h) +# Check for gf_complete headers +AC_CHECK_HEADERS(galois.h gf_complete.h) # Enable this check when gf_complete is external AC_CHECK_LIB([gf_complete], [gf_init_easy], diff --git a/include/config.h.in b/include/config.h.in index c1c8e14..c55b014 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -9,9 +9,6 @@ /* Define to 1 if you have the `calloc' function. */ #undef HAVE_CALLOC -/* Define to 1 if you have the header file. */ -#undef HAVE_CAUCHY_H - /* Define to 1 if you have the header file. */ #undef HAVE_CTYPE_H @@ -36,12 +33,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if you have the header file. */ -#undef HAVE_JERASURE_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_LIBERATION_H - /* "Defined if gf-complete is installed" */ #undef HAVE_LIBGF_COMPLETE @@ -63,15 +54,15 @@ /* Support mmx instructions */ #undef HAVE_MMX +/* Define to 1 if you have the `openlog' function. */ +#undef HAVE_OPENLOG + /* Define to 1 if you have the header file. */ #undef HAVE_PTHREAD_H /* Define to 1 if you have the `realloc' function. */ #undef HAVE_REALLOC -/* Define to 1 if you have the header file. */ -#undef HAVE_REED_SOL_H - /* Define to 1 if you have the header file. */ #undef HAVE_SIGNAL_H @@ -114,6 +105,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYSLOG_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H diff --git a/include/erasurecode/erasurecode_helpers.h b/include/erasurecode/erasurecode_helpers.h index 9b1fc2b..66addb1 100644 --- a/include/erasurecode/erasurecode_helpers.h +++ b/include/erasurecode/erasurecode_helpers.h @@ -32,7 +32,7 @@ #include "erasurecode_backend.h" #include "erasurecode_stdinc.h" -/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ +/* ==~=*=~==~=*=~==~=*=~==~=*=~==~= Logging =~==~=*=~==~=*=~==~=*=~==~=*=~== */ #if __STDC_VERSION__ < 199901L #if __GNUC__ >= 2 @@ -42,8 +42,16 @@ #endif #endif -#define log_error(str) \ - fprintf(stderr, "%s:%d (%s): %s\n", __FILE__, __LINE__, __func__, str) +#define _LOG1(level, ...) \ + syslog (level, __VA_ARGS__) + +#define _LOG2(level, ...) \ + syslog (level, "%s:%d:%s\n", __FILE__, __LINE__, __VA_ARGS__) + +#define log_info(str, ...) _LOG1(LOG_INFO, str) +#define log_warn(str, ...) _LOG1(LOG_WARNING, str) +#define log_error(str, ...) _LOG1(LOG_ERR, str) +#define log_debug(str, ...) _LOG2(LOG_DEBUG, str) /* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ diff --git a/include/erasurecode/erasurecode_stdinc.h b/include/erasurecode/erasurecode_stdinc.h index cf96626..42697c0 100644 --- a/include/erasurecode/erasurecode_stdinc.h +++ b/include/erasurecode/erasurecode_stdinc.h @@ -27,6 +27,9 @@ #include "config.h" +#ifdef HAVE_SYSLOG_H +#include +#endif #ifdef HAVE_SYS_TYPES_H #include #endif