1 /* logger.c - log 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
32 static char pidstring[15];
33 static char *pgm_name;
34 static int errorcount;
39 * Set the logfile to use (not yet implemneted) or, if logfile is NULL,
40 * the Fd where logoutputs should go.
43 log_set_logfile( const char *name, int fd )
48 if( logfp && logfp != stderr && logfp != stdout )
55 logfp = fdopen( fd, "a" );
58 log_fatal("can't open fd %d for logging: %s\n", fd, strerror(errno));
72 log_set_name( const char *name )
76 pgm_name = xstrdup(name);
84 return pgm_name? pgm_name : "";
89 log_set_pid( int pid )
92 sprintf(pidstring,"[%u]", (unsigned)pid );
98 log_get_errorcount( int clear)
113 log_set_strict(int val)
121 g10_log_print_prefix(const char *text)
126 fprintf(logfp, "%s%s: %s", pgm_name, pidstring, text );
128 fprintf(logfp, "?%s: %s", pidstring, text );
131 #endif /* __riscos__ */
136 g10_log_info( const char *fmt, ... )
140 g10_log_print_prefix("");
141 va_start( arg_ptr, fmt ) ;
142 vfprintf(logfp,fmt,arg_ptr) ;
146 #endif /* __riscos__ */
151 g10_log_warning( const char *fmt, ... )
158 g10_log_print_prefix(_("ERROR: "));
161 g10_log_print_prefix(_("WARNING: "));
163 va_start( arg_ptr, fmt ) ;
164 vfprintf(logfp,fmt,arg_ptr) ;
168 #endif /* __riscos__ */
173 g10_log_error( const char *fmt, ... )
177 g10_log_print_prefix("");
178 va_start( arg_ptr, fmt ) ;
179 vfprintf(logfp,fmt,arg_ptr) ;
184 #endif /* __riscos__ */
189 g10_log_fatal( const char *fmt, ... )
193 g10_log_print_prefix("fatal: ");
194 va_start( arg_ptr, fmt ) ;
195 vfprintf(logfp,fmt,arg_ptr) ;
200 #endif /* __riscos__ */
205 g10_log_bug( const char *fmt, ... )
210 g10_log_print_prefix("Ohhhh jeeee: ");
211 va_start( arg_ptr, fmt ) ;
212 vfprintf(stderr,fmt,arg_ptr) ;
219 #if defined (__riscos__) \
220 || ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
222 g10_log_bug0( const char *file, int line, const char *func )
224 log_bug(_("... this is a bug (%s:%d:%s)\n"), file, line, func );
228 g10_log_bug0( const char *file, int line )
230 log_bug(_("you found a bug ... (%s:%d)\n"), file, line);
235 g10_log_debug( const char *fmt, ... )
239 g10_log_print_prefix("DBG: ");
240 va_start( arg_ptr, fmt ) ;
241 vfprintf(logfp,fmt,arg_ptr) ;
245 #endif /* __riscos__ */
251 g10_log_hexdump( const char *text, const char *buf, size_t len )
255 g10_log_print_prefix(text);
256 for(i=0; i < len; i++ )
257 fprintf(logfp, " %02X", ((const byte*)buf)[i] );
261 #endif /* __riscos__ */