h5_log.c 3.27 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9
/*
  Copyright (c) 2006-2016, The Regents of the University of California,
  through Lawrence Berkeley National Laboratory (subject to receipt of any
  required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
  Institut (Switzerland).  All rights reserved.

  License: see file COPYING in top level of source distribution.
*/

10
#include "h5core/h5_log.h"
gsell's avatar
gsell committed
11
#include "h5core/h5_err.h"
gsell's avatar
gsell committed
12

13 14 15
extern int h5_myproc;


Gsell Achim's avatar
* C-API  
Gsell Achim committed
16 17
h5_int64_t			__h5_log_level = H5_VERBOSE_ERROR;
h5_int64_t			__h5_debug_mask = 0;
18

gsell's avatar
gsell committed
19 20 21
struct call_stack		h5_call_stack;

char *h5_rfmts[] = {
gsell's avatar
gsell committed
22 23 24 25 26
	[e_int]			= "%d",
	[e_ssize_t]		= "%ld",
	[e_char_p]		= "%s",
	[e_void_p]		= "%p",
	[e_h5_err_t]		= "%lld",
27 28
	[e_h5_int32_t]		= "%ld",
	[e_h5_uint32_t]		= "%lu",
gsell's avatar
gsell committed
29
	[e_h5_int64_t]		= "%lld",
30
	[e_h5_uint64_t]		= "%llu",
gsell's avatar
gsell committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
	[e_h5_id_t]		= "%lld",
	[e_h5_ssize_t]		= "%lld",
	[e_h5_errorhandler_t]	= "%p",
	[e_h5_file_p]		= "%p",
	[e_h5_file_t]		= "0x%08x",
	[e_h5_lvl_idx_t]	= "%d",
	[e_h5t_iterator_p]	= "%p",
	[e_h5_loc_id_t]		= "%ld",
	[e_h5_loc_idx_t]	= "%ld",
	[e_hid_t]		= "%lld",
	[e_H5O_type_t]		= "%ld",
	[e_h5_glb_elem_p]       = "%p",
        [e_h5_prop_p]           = "%p",
        [e_h5_prop_t]           = "0x%08x",
        [e_h5_prop_file_p]      = "%p",
        [e_h5_prop_file_t]      = "0x%08x",
	[e_herr_t]		= "%ld"
gsell's avatar
gsell committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
};

/*!
   \ingroup h5_core_errorhandling

   Set debug/verbosity level. On level 0 all output will be supressed (even
   error messages). On level 1 error messages, on level 2 warning messages
   and on level 3 informational messages will be printed. On level 4 debug
   messages will be printed.

   Values less than 0 are equivalent to 0. Values greater than 4 are equivalent
   to 4.

   \return \c H5_SUCCESS on success.
   \return \c H5_ERR_INVAL if debug level is invalid.
 */
h5_err_t
65
h5_set_loglevel (
66
        const h5_int64_t level     /*!< log level */
gsell's avatar
gsell committed
67
        ) {
Gsell Achim's avatar
* C-API  
Gsell Achim committed
68
	__h5_log_level = level & 0x7;
69 70 71 72 73 74 75
	return H5_SUCCESS;
}

h5_err_t
h5_set_debug_mask (
        const h5_int64_t mask     /*!< debug level */
        ) {
Gsell Achim's avatar
* C-API  
Gsell Achim committed
76
	__h5_debug_mask = mask;
gsell's avatar
gsell committed
77 78 79 80 81 82 83 84 85 86
	return H5_SUCCESS;
}

/*!
   \ingroup h5_core_errorhandling

   Get current debug/verbosity level.

   \return current debug level
 */
87
h5_int64_t
88
h5_get_loglevel (
gsell's avatar
gsell committed
89 90
        void
        ) {
Gsell Achim's avatar
* C-API  
Gsell Achim committed
91
	return __h5_log_level;
gsell's avatar
gsell committed
92
}
gsell's avatar
gsell committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

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);
}

h5_err_t
h5_warn (
        const char* fmt,
        ...
        ) {
Gsell Achim's avatar
* C-API  
Gsell Achim committed
113
	if (__h5_log_level >= 2) {
gsell's avatar
gsell committed
114 115 116 117 118 119 120 121 122 123 124 125 126
		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,
        ...
        ) {
Gsell Achim's avatar
* C-API  
Gsell Achim committed
127
	if (__h5_log_level >= 3) {
gsell's avatar
gsell committed
128 129 130 131 132 133 134 135 136 137 138 139
		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,
        ...
        ) {
Gsell Achim's avatar
* C-API  
Gsell Achim committed
140
	if (__h5_log_level >= 4) {
gsell's avatar
gsell committed
141 142 143 144 145 146 147 148 149 150
		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);
	}
}