summaryrefslogtreecommitdiff
path: root/lib/gnutls_global.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2013-11-15 09:53:21 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2013-11-15 09:53:21 +0100
commit84fbcb7c2f1fa9c53e7d4328fdd77f2832bbf9a9 (patch)
tree7cda9add2d056d6fb2ac8a2b2ce4849d38153718 /lib/gnutls_global.c
parent50650ac4650f7a461d603dddc17656cde65fb456 (diff)
downloadgnutls-84fbcb7c2f1fa9c53e7d4328fdd77f2832bbf9a9.tar.gz
The environment variable GNUTLS_DEBUG_LEVEL if set to a number will enable logging to stderr.
Diffstat (limited to 'lib/gnutls_global.c')
-rw-r--r--lib/gnutls_global.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index c7c03c3464..83cdd9f5ae 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -51,6 +51,11 @@ gnutls_log_func _gnutls_log_func = NULL;
gnutls_audit_log_func _gnutls_audit_log_func = NULL;
int _gnutls_log_level = 0; /* default log level */
+static void default_log_func(int level, const char* str)
+{
+ fprintf(stderr, "gnutls[%d]: %s\n", level, str);
+}
+
/**
* gnutls_global_set_log_function:
* @log_func: it's a log function
@@ -191,10 +196,19 @@ static int _gnutls_init = 0;
int gnutls_global_init(void)
{
int result = 0;
- int res;
+ int res, level;
+ const char* e;
if (_gnutls_init++)
goto out;
+
+ e = getenv("GNUTLS_DEBUG_LEVEL");
+ if (e != NULL) {
+ level = atoi(e);
+ gnutls_global_set_log_level(level);
+ gnutls_global_set_log_function(default_log_func);
+ fprintf(stderr, "Enabled GnuTLS logging on stderr\n");
+ }
if (gl_sockets_startup(SOCKETS_1_1))
return gnutls_assert_val(GNUTLS_E_FILE_ERROR);