1
/* logging.c - useful logging functions
2
* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
/* This file should replace logger.c in the future - for now it is not
24
* It is a quite simple implemenation but sufficient for most purposes.
33
#include "libutil-config.h"
49
write2stderr( const char *s )
51
write( 2, s, strlen(s) );
56
do_die(int rc, const char *text )
58
write2stderr("\nFatal error: ");
67
do_logv( int level, const char *fmt, va_list arg_ptr )
70
case MY_LOG_CONT: break;
71
case MY_LOG_INFO: break;
72
case MY_LOG_WARN: break;
73
case MY_LOG_ERROR: break;
74
case MY_LOG_FATAL: fputs("Fatal: ",stderr ); break;
75
case MY_LOG_BUG: fputs("Ohhhh jeeee: ", stderr); break;
76
case MY_LOG_DEBUG: fputs("DBG: ", stderr ); break;
77
default: fprintf(stderr,"[Unknown log level %d]: ", level ); break;
79
vfprintf(stderr,fmt,arg_ptr) ;
81
if( level == MY_LOG_FATAL )
83
if( level == MY_LOG_BUG )
88
do_log( int level, const char *fmt, ... )
92
va_start( arg_ptr, fmt ) ;
93
do_logv( level, fmt, arg_ptr );
100
log_info( const char *fmt, ... )
104
va_start( arg_ptr, fmt ) ;
105
do_logv( MY_LOG_INFO, fmt, arg_ptr );
110
log_error( const char *fmt, ... )
114
va_start( arg_ptr, fmt ) ;
115
do_logv( MY_LOG_ERROR, fmt, arg_ptr );
121
log_fatal( const char *fmt, ... )
125
va_start( arg_ptr, fmt ) ;
126
do_logv( MY_LOG_FATAL, fmt, arg_ptr );
128
abort(); /* never called, bugs it makes the compiler happy */
132
log_bug( const char *fmt, ... )
136
va_start( arg_ptr, fmt ) ;
137
do_logv( MY_LOG_BUG, fmt, arg_ptr );
139
abort(); /* never called, bugs it makes the compiler happy */
143
log_debug( const char *fmt, ... )
147
va_start( arg_ptr, fmt ) ;
148
do_logv( MY_LOG_DEBUG, fmt, arg_ptr );
153
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
155
bug_at( const char *file, int line, const char *func )
158
("... this is a bug (%s:%d:%s)\n"), file, line, func );
159
abort(); /* never called, but it makes the compiler happy */
163
bug_at( const char *file, int line )
166
_("you found a bug ... (%s:%d)\n"), file, line);
167
abort(); /* never called, but it makes the compiler happy */