From 983496104b94ca37d59f56c19766974c43903ead Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Wed, 22 Jun 2016 14:24:54 +0200 Subject: [PATCH] src/h5core/h5_log.c src/h5core/h5_init.h src/h5core/h5_log.h: - cleanup, minor changes --- src/h5core/h5_log.c | 80 ++++++++++++++++++++++++++++++++++++ src/h5core/private/h5_init.h | 2 +- src/h5core/private/h5_log.h | 5 ++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/h5core/h5_log.c b/src/h5core/h5_log.c index c5b4940..815df54 100644 --- a/src/h5core/h5_log.c +++ b/src/h5core/h5_log.c @@ -8,6 +8,7 @@ */ #include "h5core/h5_log.h" +#include "h5core/h5_err.h" #include "private/h5_init.h" h5_int32_t h5_log_level = H5_VERBOSE_ERROR; @@ -77,3 +78,82 @@ h5_get_loglevel ( ) { return h5_log_level; } + +void +h5priv_vprintf ( + FILE* f, + const char* prefix, + const char* __funcname, + const char* fmt, + va_list ap + ) { + char fmt2[2048]; + snprintf (fmt2, sizeof(fmt2), "[proc %d] %s: %s: %s\n", h5_myproc, prefix, + __funcname, fmt); + vfprintf (f, fmt2, ap); +} + +/*! + \ingroup h5_core_errorhandling + + Print error message to \c stderr. For use in error handlers only. + */ +void +h5_verror ( + const char* const fmt, + va_list ap + ) { + if (h5_log_level == 0) return; + char fmt2[2048]; + snprintf (fmt2, + sizeof(fmt2), "[proc %d] E: %s: %s\n", + h5_myproc, + h5_call_stack.entry[0].name, + fmt); + vfprintf (stderr, fmt2, ap); + +} + +h5_err_t +h5_warn ( + const char* fmt, + ... + ) { + if (h5_log_level >= 2) { + va_list ap; + va_start (ap, fmt); + h5priv_vprintf (stderr, "W", h5_get_funcname(), fmt, ap); + va_end (ap); + } + return H5_NOK; +} + +void +h5_info ( + const char* fmt, + ... + ) { + if (h5_log_level >= 3) { + va_list ap; + va_start (ap, fmt); + h5priv_vprintf (stdout, "I", h5_get_funcname(), fmt, ap); + va_end (ap); + } +} + +void +h5_debug ( + const char* const fmt, + ... + ) { + if (h5_log_level >= 4) { + char prefix[1024]; + snprintf (prefix, sizeof(prefix), "%*s %s", + h5_call_stack_get_level(), "", + h5_call_stack_get_name()); + va_list ap; + va_start (ap, fmt); + h5priv_vprintf (stdout, "D", prefix, fmt, ap); + va_end (ap); + } +} diff --git a/src/h5core/private/h5_init.h b/src/h5core/private/h5_init.h index 1546f6e..81c80e2 100644 --- a/src/h5core/private/h5_init.h +++ b/src/h5core/private/h5_init.h @@ -33,7 +33,7 @@ extern "C" { extern int h5_initialized; h5_err_t -h5_initialize (void); +h5priv_initialize (void); extern h5_dta_types_t h5_dta_types; extern int h5_myproc; diff --git a/src/h5core/private/h5_log.h b/src/h5core/private/h5_log.h index ccc93d8..8254bcf 100644 --- a/src/h5core/private/h5_log.h +++ b/src/h5core/private/h5_log.h @@ -16,7 +16,7 @@ #define H5_CORE_API_ENTER(type, fmt, ...) \ if (!h5_initialized) { \ - h5_initialize(); \ + h5priv_initialize(); \ } \ __FUNC_ENTER(type, H5_DEBUG_CORE_API, fmt, __VA_ARGS__) #define H5_CORE_API_LEAVE(value) __FUNC_LEAVE(value) @@ -50,4 +50,7 @@ #define H5_INLINE_FUNC_LEAVE(expr) __FUNC_LEAVE(expr) #define H5_INLINE_FUNC_RETURN(expr) __FUNC_RETURN(expr, 0) + + + #endif