Commit 88579e67 authored by Pascal Bühler's avatar Pascal Bühler

Simplify logging of errors and debug

Previously logging of debug and errors did not always work as expected.
Now there are three configure options to control output. The idea is not to
be overly complicated but to give some simple options that work.

--enable-log-stdout
This will out put all debug and error logging to stdout

--with-log-file=<filename>
This will output all debug and error logging to the given filename

--enable-debug-logging
This enable debug logging for all internal debug modules. This is very
verbose and should only be used for debugging and development.
parent e345cbe0
......@@ -87,16 +87,16 @@ socket(0, 0, 0);
AC_MSG_RESULT(no)])
fi
AC_MSG_CHECKING(whether to compile in debugging)
AC_ARG_ENABLE(debug,
[AS_HELP_STRING([--disable-debug],
[do not compile in dynamic debugging system])],
[], enable_debug=yes)
if test "$enable_debug" = "yes"; then
AC_DEFINE(ENABLE_DEBUGGING, 1,
[Define to compile in dynamic debugging system.])
AC_MSG_CHECKING(whether to enable debug logging in all modules)
AC_ARG_ENABLE(debug-logging,
[AS_HELP_STRING([--enable-debug-logging],
[Enable debug logging in all modules])],
[], enable_debug_logging=no)
if test "$enable_debug_logging" = "yes"; then
AC_DEFINE(ENABLE_DEBUG_LOGGING, 1,
[Define to enabled debug logging for all mudules.])
fi
AC_MSG_RESULT($enable_debug)
AC_MSG_RESULT($enable_debug_logging)
AC_MSG_CHECKING(whether to use ISMAcryp code)
AC_ARG_ENABLE(generic-aesicm,
......@@ -167,24 +167,32 @@ AC_CHECK_LIB([pcap],[pcap_create],
AC_SUBST(HAVE_PCAP)
])
AC_MSG_CHECKING(whether to use stdout for error reporting)
AC_ARG_ENABLE(stdout,
[AS_HELP_STRING([--enable-stdout], [use stdout for debug/error reporting])],
[], enable_stdout=no)
if test "$enable_stdout" = "yes"; then
AC_DEFINE(ERR_REPORTING_STDOUT, 1, [Define to use logging to stdout.])
AC_MSG_CHECKING(whether to redirect logging to stdout)
AC_ARG_ENABLE(log-stdout,
[AS_HELP_STRING([--enable-log-stdout], [redirecting logging to stdout])],
[], enable_log_stdout=no)
if test "$enable_log_stdout" = "yes"; then
AC_DEFINE(ERR_REPORTING_STDOUT, 1, [Define to redirect logging to stdout.])
fi
AC_MSG_RESULT($enable_stdout)
AC_MSG_CHECKING(whether to use /dev/console for error reporting)
AC_ARG_ENABLE(console,
[AS_HELP_STRING([--enable-console], [use /dev/console for error reporting])],
[], enable_console=no)
if test "$enable_console" = "yes"; then
AC_DEFINE(USE_ERR_REPORTING_FILE, 1, [Write errors to this file])
AC_DEFINE(ERR_REPORTING_FILE, "/dev/console", [Report errors to this file.])
fi
AC_MSG_RESULT($enable_console)
AC_MSG_RESULT($enable_log_stdout)
AC_MSG_CHECKING(wheather to use a file for logging)
AC_ARG_WITH(log-file,
[AS_HELP_STRING([--with-log-file], [Use file for logging])],
[AS_CASE([x$with_log_file],
[x], [valid_with_log_file="no"],
[xyes], [valid_with_log_file="no"],
[valid_with_error_file="yes"])
AS_IF([test "$valid_with_log_file" = "no"],
[AC_MSG_RESULT([invalid])
AC_MSG_FAILURE([Invalid value for --with-log-file: "$with_log_file"])],
[AC_DEFINE_UNQUOTED([ERR_REPORTING_FILE], ["$with_log_file"], [Logging statments will be writen to this file.])
AC_MSG_RESULT([using log file: "$with_log_file"])])],
[AC_MSG_RESULT([no])])
AS_IF(
[test "$enable_log_stdout" = "yes" && test "x$with_log_file" != "x"],
[AC_MSG_FAILURE([Can only use one of --enable-log-stdout and --with-log-file; they are mutually exclusive])])
AC_CONFIG_HEADER(crypto/include/config.h:config_in.h)
......
......@@ -68,39 +68,32 @@ extern "C" {
*/
typedef enum {
srtp_err_level_emergency = 0,
srtp_err_level_alert,
srtp_err_level_critical,
srtp_err_level_error,
srtp_err_level_warning,
srtp_err_level_notice,
srtp_err_level_info,
srtp_err_level_debug,
srtp_err_level_none
srtp_err_level_debug
} srtp_err_reporting_level_t;
/*
* err_reporting_init prepares the error system. If
* ERR_REPORTING_SYSLOG is defined, it will open syslog.
* ERR_REPORTING_STDOUT is defined, it will log to stdout.
*
* The ident argument is a string that will be prepended to
* all syslog messages. It is conventionally argv[0].
*/
srtp_err_status_t srtp_err_reporting_init(const char *ident);
srtp_err_status_t srtp_err_reporting_init();
/*
* keydaemon_report_error reports a 'printf' formatted error
* string, followed by a an arg list. The priority argument
* is equivalent to that defined for syslog.
* srtp_err_report reports a 'printf' formatted error
* string, followed by a an arg list. The level argument
* is one of srtp_err_reporting_level_t.
*
* Errors will be reported to ERR_REPORTING_FILE, if defined, and to
* syslog, if ERR_REPORTING_SYSLOG is defined.
* Errors will be reported to stdout, if ERR_REPORTING_STDOUT
* is defined.
*
*/
void
srtp_err_report(int priority, const char *format, ...);
srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...);
/*
......@@ -112,27 +105,20 @@ typedef struct {
const char *name; /* printable name for debug module */
} srtp_debug_module_t;
#ifdef ENABLE_DEBUGGING
#ifdef ENABLE_DEBUG_LOGGING
#define debug_on(mod) (mod).on = 1
#define debug_print(mod, format, arg) \
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
#define debug_print2(mod, format, arg1, arg2) \
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg1, arg2)
#define debug_off(mod) (mod).on = 0
#else
/* use err_report() to report debug message */
#define debug_print(mod, format, arg) \
if (mod.on) srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
#define debug_print2(mod, format, arg1, arg2) \
if (mod.on) srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg1, arg2)
#else
/* define macros to do nothing */
#define debug_print(mod, format, arg)
#define debug_on(mod)
#define debug_off(mod)
#endif
#ifdef __cplusplus
......
......@@ -122,7 +122,7 @@ srtp_err_status_t srtp_crypto_kernel_init ()
}
/* initialize error reporting system */
status = srtp_err_reporting_init("crypto");
status = srtp_err_reporting_init();
if (status) {
return status;
}
......@@ -210,45 +210,34 @@ srtp_err_status_t srtp_crypto_kernel_status ()
srtp_err_status_t status;
srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list;
srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list;
srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list;
/* for each cipher type, describe and test */
while (ctype != NULL) {
printf("cipher: %s\n", ctype->cipher_type->description);
printf(" self-test: ");
srtp_err_report(srtp_err_level_info, "cipher: %s\n", ctype->cipher_type->description);
srtp_err_report(srtp_err_level_info, " self-test: ");
status = srtp_cipher_type_self_test(ctype->cipher_type);
if (status) {
printf("failed with error code %d\n", status);
srtp_err_report(srtp_err_level_error, "failed with error code %d\n", status);
exit(status);
}
printf("passed\n");
srtp_err_report(srtp_err_level_info, "passed\n");
ctype = ctype->next;
}
/* for each auth type, describe and test */
while (atype != NULL) {
printf("auth func: %s\n", atype->auth_type->description);
printf(" self-test: ");
srtp_err_report(srtp_err_level_info, "auth func: %s\n", atype->auth_type->description);
srtp_err_report(srtp_err_level_info, " self-test: ");
status = srtp_auth_type_self_test(atype->auth_type);
if (status) {
printf("failed with error code %d\n", status);
srtp_err_report(srtp_err_level_error, "failed with error code %d\n", status);
exit(status);
}
printf("passed\n");
srtp_err_report(srtp_err_level_info, "passed\n");
atype = atype->next;
}
/* describe each debug module */
printf("debug modules loaded:\n");
while (dm != NULL) {
printf(" %s ", dm->mod->name);
if (dm->mod->on) {
printf("(on)\n");
} else{
printf("(off)\n");
}
dm = dm->next;
}
srtp_crypto_kernel_list_debug_modules();
return srtp_err_status_ok;
}
......@@ -258,13 +247,13 @@ srtp_err_status_t srtp_crypto_kernel_list_debug_modules ()
srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list;
/* describe each debug module */
printf("debug modules loaded:\n");
srtp_err_report(srtp_err_level_info, "debug modules loaded:\n");
while (dm != NULL) {
printf(" %s ", dm->mod->name);
srtp_err_report(srtp_err_level_info, " %s ", dm->mod->name);
if (dm->mod->on) {
printf("(on)\n");
srtp_err_report(srtp_err_level_info, "(on)\n");
} else{
printf("(off)\n");
srtp_err_report(srtp_err_level_info, "(off)\n");
}
dm = dm->next;
}
......
......@@ -48,26 +48,15 @@
#include "err.h"
/* srtp_err_level reflects the level of errors that are reported */
srtp_err_reporting_level_t srtp_err_level = srtp_err_level_none;
/* srtp_err_file is the FILE to which errors are reported */
static FILE *srtp_err_file = NULL;
srtp_err_status_t srtp_err_reporting_init (const char *ident)
srtp_err_status_t srtp_err_reporting_init ()
{
/*
* Believe it or not, openlog doesn't return an error on failure.
* But then, neither does the syslog() call...
*/
#ifdef ERR_REPORTING_STDOUT
srtp_err_file = stdout;
#elif defined(USE_ERR_REPORTING_FILE)
#elif defined(ERR_REPORTING_FILE)
/* open file for error reporting */
srtp_err_file = fopen(ERR_REPORTING_FILE, "w");
if (srtp_err_file == NULL) {
......@@ -78,22 +67,12 @@ srtp_err_status_t srtp_err_reporting_init (const char *ident)
return srtp_err_status_ok;
}
void srtp_err_report (int priority, const char *format, ...)
void srtp_err_report (srtp_err_reporting_level_t level, const char *format, ...)
{
va_list args;
if (priority <= srtp_err_level) {
va_start(args, format);
if (srtp_err_file != NULL) {
vfprintf(srtp_err_file, format, args);
/* fprintf(srtp_err_file, "\n"); */
}
va_end(args);
va_start(args, format);
if (srtp_err_file != NULL) {
vfprintf(srtp_err_file, format, args);
}
}
void srtp_err_reporting_set_level (srtp_err_reporting_level_t lvl)
{
srtp_err_level = lvl;
va_end(args);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment