aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_common.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-04 11:09:39 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-04 11:09:39 +0000
commite305c764722394c18d55e084c7be4b64ff799fa4 (patch)
tree24f9dd8cc6f5393a9084d8149e53af5e850b25e7 /src/include/gnunet_common.h
parentba59bf06eefaefa447fbca9059adefe9ac0ef167 (diff)
downloadgnunet-e305c764722394c18d55e084c7be4b64ff799fa4.tar.gz
gnunet-e305c764722394c18d55e084c7be4b64ff799fa4.zip
LRN's big logging rewrite (#1805):
* GNUNET_BOTTOM_LOGLEVEL and GNUNET_TOP_LOGLEVEL set global levels Use bottom level to force logging to be more verbose than configured Use top level to force logging to be less verbose than configured Obviously, bottom <= top * GNUNET_LOG sets per-component levels GNUNET_LOG looks like this: name[/bottom[/top]]/... name starts with a non-digit character, must not include '/' bottom and top must consist only of digits, or be empty a description is only used if it matches the component exactly as a special exception (for now) the name '*' matches any component per-component loglevels override global loglevels global levels override whatever is given via arguments or in config Examples: test_client/8/8/ run test_client with DEBUG level (usually leads to a timeout, by the way) */2/2/core/8/8/transport/4/4 run everything with WARNING, core - with DEBUG, transport - with INFO *//1/peerinfo/4/ run everything with top loglevel ERROR, global/configured bottom loglevel, and peerinfo - with bottom loglevel INFO and global/configured top loglevel statistics/ does nothing * Added GNUNET_ERROR_TYPE_UNSPECIFIED enum value, to hold -1. Its corresponding string is NULL. * Changed the logger calls as Grothoff suggested - to use static int to hold the result of runtime evaluation of logability. Logging can be unconditionally disabled in advance by defining GNUNET_LOG_CALL_STATUS to 0, and enabled in advance by defining it to 1. * Added GNUNET_CULL_LOGGING, which, if defined, completely culls out all logging calls at compile time. * Log definition parsing is only done once, results are cached. * Changed definition format, now it looks like this: [component|*|];[file|*|];[function|*|];[from_line[-to_line]];level/[component...] All field separators are mandatory (but some fields could be empty or be '*'). Line definition must be either empty or "number" or "number-number" Level definition must not be empty, and is a string representation of the level (i.e. DEBUG, WARNING, INFO, etc). Definition entry must end with a slash, whether or not there's another entry after it. File name is matched to the end of __FILE__, which allows file name to match not only the base name, but also directories leading to it. * Removed default WARNING loglevel from program and service utility code. Now they default to NULL (UNSPECIFIED) level, which can be overriden by GNUNET_LOG definition, if no level is specified via config or commandline. Log levels from config or commandline are overriden by GNUNET_FORCE_LOG. If GNUNET_*LOG are undefined, and no levels came from config or commandline, logger internally defaults to WARNING level. Add --enable-logging configure option
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r--src/include/gnunet_common.h62
1 files changed, 59 insertions, 3 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index f4844821c..6b3ffe2af 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -138,6 +138,7 @@ typedef int (*GNUNET_FileNameCallback) (void *cls, const char *filename);
138 */ 138 */
139enum GNUNET_ErrorType 139enum GNUNET_ErrorType
140{ 140{
141 GNUNET_ERROR_TYPE_UNSPECIFIED = -1,
141 GNUNET_ERROR_TYPE_NONE = 0, 142 GNUNET_ERROR_TYPE_NONE = 0,
142 GNUNET_ERROR_TYPE_ERROR = 1, 143 GNUNET_ERROR_TYPE_ERROR = 1,
143 GNUNET_ERROR_TYPE_WARNING = 2, 144 GNUNET_ERROR_TYPE_WARNING = 2,
@@ -161,6 +162,15 @@ typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind,
161 const char *component, const char *date, 162 const char *component, const char *date,
162 const char *message); 163 const char *message);
163 164
165
166/**
167 * Number of log calls to ignore.
168 */
169extern unsigned int skip_log;
170#if !defined(GNUNET_CULL_LOGGING)
171int
172GNUNET_get_log_call_status (int caller_level, const char *comp, const char *file, const char *function, int line);
173#endif
164/** 174/**
165 * Main log function. 175 * Main log function.
166 * 176 *
@@ -169,9 +179,29 @@ typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind,
169 * @param ... arguments for format string 179 * @param ... arguments for format string
170 */ 180 */
171void 181void
172GNUNET_log (enum GNUNET_ErrorType kind, const char *message, ...); 182GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...);
173 183
184/* from glib */
185#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
186#define _GNUNET_BOOLEAN_EXPR(expr) \
187 __extension__ ({ \
188 int _gnunet_boolean_var_; \
189 if (expr) \
190 _gnunet_boolean_var_ = 1; \
191 else \
192 _gnunet_boolean_var_ = 0; \
193 _gnunet_boolean_var_; \
194})
195#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR(expr), 1))
196#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR(expr), 0))
197#else
198#define GN_LIKELY(expr) (expr)
199#define GN_UNLIKELY(expr) (expr)
200#endif
174 201
202#if !defined(GNUNET_LOG_CALL_STATUS)
203#define GNUNET_LOG_CALL_STATUS -1
204#endif
175 205
176/** 206/**
177 * Log function that specifies an alternative component. 207 * Log function that specifies an alternative component.
@@ -183,9 +213,35 @@ GNUNET_log (enum GNUNET_ErrorType kind, const char *message, ...);
183 * @param ... arguments for format string 213 * @param ... arguments for format string
184 */ 214 */
185void 215void
186GNUNET_log_from (enum GNUNET_ErrorType kind, const char *comp, 216GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
187 const char *message, ...); 217 const char *message, ...);
188 218
219#if !defined(GNUNET_CULL_LOGGING)
220#define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\
221 static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\
222 if (GN_UNLIKELY(log_call_enabled == -1))\
223 log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), comp, __FILE__, __FUNCTION__, log_line);\
224 if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
225 else {\
226 if (GN_UNLIKELY(log_call_enabled))\
227 GNUNET_log_from_nocheck (kind, comp, __VA_ARGS__);\
228 }\
229} while (0)
230
231#define GNUNET_log(kind,...) do { int log_line = __LINE__;\
232 static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\
233 if (GN_UNLIKELY(log_call_enabled == -1))\
234 log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), NULL, __FILE__, __FUNCTION__, log_line);\
235 if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
236 else {\
237 if (GN_UNLIKELY(log_call_enabled))\
238 GNUNET_log_nocheck (kind, __VA_ARGS__);\
239 }\
240} while (0)
241#else
242#define GNUNET_log(...)
243#define GNUNET_log_from(...)
244#endif
189 245
190/** 246/**
191 * Ignore the next n calls to the log function. 247 * Ignore the next n calls to the log function.