diff options
author | Werner Koch <wk@gnupg.org> | 2010-03-11 13:34:11 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2010-03-11 13:34:11 +0100 |
commit | 37870234a195fb76f36284ac4bdb5dc172078724 (patch) | |
tree | f65b4c42925edb20ff4149a977d12a4d31d432a0 /common/logging.c | |
parent | Change logging to use estream. The makes logging to a socket also (diff) | |
download | gnupg2-37870234a195fb76f36284ac4bdb5dc172078724.tar.xz gnupg2-37870234a195fb76f36284ac4bdb5dc172078724.zip |
Use a custom log handler for libassuan.
Diffstat (limited to 'common/logging.c')
-rw-r--r-- | common/logging.c | 115 |
1 files changed, 66 insertions, 49 deletions
diff --git a/common/logging.c b/common/logging.c index c0e01da11..3b767cb97 100644 --- a/common/logging.c +++ b/common/logging.c @@ -415,7 +415,7 @@ log_get_stream () } static void -do_logv (int level, const char *fmt, va_list arg_ptr) +do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr) { if (!logstream) { @@ -478,7 +478,10 @@ do_logv (int level, const char *fmt, va_list arg_ptr) if (fmt) { - es_vfprintf_unlocked (logstream, fmt, arg_ptr); + if (ignore_arg_ptr) + es_fputs_unlocked (fmt, logstream); + else + es_vfprintf_unlocked (logstream, fmt, arg_ptr); if (*fmt && fmt[strlen(fmt)-1] != '\n') missing_lf = 1; } @@ -503,76 +506,91 @@ do_logv (int level, const char *fmt, va_list arg_ptr) static void -do_log( int level, const char *fmt, ... ) +do_log (int level, const char *fmt, ...) { - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( level, fmt, arg_ptr ); - va_end(arg_ptr); + va_list arg_ptr ; + + va_start (arg_ptr, fmt) ; + do_logv (level, 0, fmt, arg_ptr); + va_end (arg_ptr); } void log_logv (int level, const char *fmt, va_list arg_ptr) { - do_logv (level, fmt, arg_ptr); + do_logv (level, 0, fmt, arg_ptr); } + void -log_info( const char *fmt, ... ) +log_string (int level, const char *string) { - va_list arg_ptr ; + /* We need to provide a dummy arg_ptr. volatile is needed to + suppress compiler warnings. */ + volatile va_list dummy_arg_ptr; - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_INFO, fmt, arg_ptr ); - va_end(arg_ptr); + do_logv (level, 1, string, dummy_arg_ptr); } + void -log_error( const char *fmt, ... ) +log_info (const char *fmt, ...) { - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_ERROR, fmt, arg_ptr ); - va_end(arg_ptr); - /* protect against counter overflow */ - if( errorcount < 30000 ) - errorcount++; + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_INFO, 0, fmt, arg_ptr); + va_end (arg_ptr); } void -log_fatal( const char *fmt, ... ) +log_error (const char *fmt, ...) { - va_list arg_ptr ; + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_ERROR, 0, fmt, arg_ptr); + va_end (arg_ptr); + /* Protect against counter overflow. */ + if (errorcount < 30000) + errorcount++; +} + - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_FATAL, fmt, arg_ptr ); - va_end(arg_ptr); - abort(); /* never called, but it makes the compiler happy */ +void +log_fatal (const char *fmt, ...) +{ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_FATAL, 0, fmt, arg_ptr); + va_end (arg_ptr); + abort (); /* Never called; just to make the compiler happy. */ } + void -log_bug( const char *fmt, ... ) +log_bug (const char *fmt, ...) { - va_list arg_ptr ; + va_list arg_ptr ; - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_BUG, fmt, arg_ptr ); - va_end(arg_ptr); - abort(); /* never called, but it makes the compiler happy */ + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_BUG, 0, fmt, arg_ptr); + va_end (arg_ptr); + abort (); /* Never called; just to make the compiler happy. */ } + void -log_debug( const char *fmt, ... ) +log_debug (const char *fmt, ...) { - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_DEBUG, fmt, arg_ptr ); - va_end(arg_ptr); + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_DEBUG, 0, fmt, arg_ptr); + va_end (arg_ptr); } @@ -580,12 +598,13 @@ void log_printf (const char *fmt, ...) { va_list arg_ptr; - + va_start (arg_ptr, fmt); - do_logv (fmt ? JNLIB_LOG_CONT : JNLIB_LOG_BEGIN, fmt, arg_ptr); + do_logv (fmt ? JNLIB_LOG_CONT : JNLIB_LOG_BEGIN, 0, fmt, arg_ptr); va_end (arg_ptr); } + /* Print a hexdump of BUFFER. With TEXT of NULL print just the raw dump, with TEXT just an empty string, print a trailing linefeed, otherwise print an entire debug line. */ @@ -610,17 +629,15 @@ log_printhex (const char *text, const void *buffer, size_t length) void bug_at( const char *file, int line, const char *func ) { - do_log( JNLIB_LOG_BUG, - ("... this is a bug (%s:%d:%s)\n"), file, line, func ); - abort(); /* never called, but it makes the compiler happy */ + do_log (JNLIB_LOG_BUG, ("... this is a bug (%s:%d:%s)\n"), file, line, func); + abort (); /* Never called; just to make the compiler happy. */ } #else void bug_at( const char *file, int line ) { - do_log( JNLIB_LOG_BUG, - _("you found a bug ... (%s:%d)\n"), file, line); - abort(); /* never called, but it makes the compiler happy */ + do_log (JNLIB_LOG_BUG, _("you found a bug ... (%s:%d)\n"), file, line); + abort (); /* Never called; just to make the compiler happy. */ } #endif |