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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
31
static char pidstring[15];
32
static char *pgm_name;
33
static int errorcount;
38
* Set the logfile to use (not yet implemneted) or, if logfile is NULL,
39
* the Fd where logoutputs should go.
42
log_set_logfile( const char *name, int fd )
47
if( logfp && logfp != stderr && logfp != stdout )
54
logfp = fdopen( fd, "a" );
57
log_fatal("can't open fd %d for logging: %s\n", fd, strerror(errno));
71
log_set_name( const char *name )
75
pgm_name = m_strdup(name);
83
return pgm_name? pgm_name : "";
88
log_set_pid( int pid )
91
sprintf(pidstring,"[%u]", (unsigned)pid );
97
log_get_errorcount( int clear)
112
log_set_strict(int val)
120
g10_log_print_prefix(const char *text)
125
fprintf(logfp, "%s%s: %s", pgm_name, pidstring, text );
127
fprintf(logfp, "?%s: %s", pidstring, text );
130
#endif /* __riscos__ */
135
g10_log_info( const char *fmt, ... )
139
g10_log_print_prefix("");
140
va_start( arg_ptr, fmt ) ;
141
vfprintf(logfp,fmt,arg_ptr) ;
145
#endif /* __riscos__ */
150
g10_log_warning( const char *fmt, ... )
157
g10_log_print_prefix(_("ERROR: "));
160
g10_log_print_prefix(_("WARNING: "));
162
va_start( arg_ptr, fmt ) ;
163
vfprintf(logfp,fmt,arg_ptr) ;
167
#endif /* __riscos__ */
172
g10_log_error( const char *fmt, ... )
176
g10_log_print_prefix("");
177
va_start( arg_ptr, fmt ) ;
178
vfprintf(logfp,fmt,arg_ptr) ;
183
#endif /* __riscos__ */
188
g10_log_fatal( const char *fmt, ... )
192
g10_log_print_prefix("fatal: ");
193
va_start( arg_ptr, fmt ) ;
194
vfprintf(logfp,fmt,arg_ptr) ;
199
#endif /* __riscos__ */
204
g10_log_bug( const char *fmt, ... )
209
g10_log_print_prefix("Ohhhh jeeee: ");
210
va_start( arg_ptr, fmt ) ;
211
vfprintf(stderr,fmt,arg_ptr) ;
218
#if defined (__riscos__) \
219
|| ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
221
g10_log_bug0( const char *file, int line, const char *func )
223
log_bug(_("... this is a bug (%s:%d:%s)\n"), file, line, func );
227
g10_log_bug0( const char *file, int line )
229
log_bug(_("you found a bug ... (%s:%d)\n"), file, line);
234
g10_log_debug( const char *fmt, ... )
238
g10_log_print_prefix("DBG: ");
239
va_start( arg_ptr, fmt ) ;
240
vfprintf(logfp,fmt,arg_ptr) ;
244
#endif /* __riscos__ */
250
g10_log_hexdump( const char *text, const char *buf, size_t len )
254
g10_log_print_prefix(text);
255
for(i=0; i < len; i++ )
256
fprintf(logfp, " %02X", ((const byte*)buf)[i] );
260
#endif /* __riscos__ */