#include <stdio.h>#include <stdlib.h>#include <string.h>#include <syslog.h>#include <errno.h>#include <stdarg.h>#include <ctype.h>#include "logger.h"#include "MALLOC.h"Include dependency graph for logger.c:

Go to the source code of this file.
Data Structures | |
| struct | LOGGER_globals |
Functions | |
| FILE * | LOGGER_get_file (void) |
| int | LOGGER_set_output_mode (int modechoice) |
| int | LOGGER_set_output_file (FILE *f) |
| int | LOGGER_set_syslog_mode (int syslogmode) |
| int | LOGGER_set_logfile (char *lfname) |
| int | LOGGER_set_wraplength (int length) |
| int | LOGGER_set_wrap (int level) |
| int | LOGGER_close_logfile (void) |
| int | LOGGER_clean_output (char *string, char **buffer) |
| int | LOGGER_log (char *format,...) |
Variables | |
| static int | _LOGGER_mode = _LOGGER_SYSLOG |
| static int | _LOGGER_syslog_mode = LOG_MAIL|LOG_INFO |
| static FILE * | _LOGGER_outf |
| static struct LOGGER_globals | LOGGER_glb = { 0, 0 } |
| int LOGGER_clean_output | ( | char * | string, | |
| char ** | buffer | |||
| ) |
Definition at line 193 of file logger.c.
References LOGGER_glb, MALLOC, NULL, p, LOGGER_globals::wrap, and LOGGER_globals::wraplength.
Referenced by LOGGER_log().
00194 { 00195 char *newstr; 00196 char *p, *q; 00197 char *next_space; 00198 00199 int pc; 00200 int slen = strlen( string ); 00201 int line_size; 00202 int maxsize = slen *2; 00203 00204 /* First up, allocate maxsize bytes for a temporary new string.*/ 00205 newstr = MALLOC(slen *2 +1); 00206 if ( newstr == NULL ) 00207 { 00208 /* FIXME - Report an error here ... to -somewhere-*/ 00209 return -1; 00210 } 00211 00212 p = newstr; 00213 q = string; 00214 pc = 0; 00215 line_size = 0; 00216 00217 while (slen--) 00218 { 00219 00220 /* Do we need to apply any wrapping to the output? If so then we*/ 00221 /* shall embark on a journey of strange space and distance*/ 00222 /* evaluations to determine if we should wrap now or later*/ 00223 00224 if ( LOGGER_glb.wrap > 0 ) 00225 { 00226 if (isspace((int)*q)) 00227 { 00228 next_space = strpbrk( (q+1), "\t\r\n\v " ); 00229 if (next_space != NULL) 00230 { 00231 if ((line_size +(next_space -q)) >= LOGGER_glb.wraplength) 00232 { 00233 *p = '\n'; 00234 p++; 00235 pc++; 00236 line_size = 0; 00237 } 00238 } 00239 } 00240 00241 if ( line_size >= LOGGER_glb.wraplength ) 00242 { 00243 *p = '\n'; 00244 p++; 00245 pc++; 00246 line_size = 0; 00247 } 00248 } 00249 00250 /* If the string has a % in it, then we need to encode it as*/ 00251 /* a DOUBLE % symbol.*/ 00252 00253 if (*q == '%') { 00254 /* if (strchr("fdlsxXn",*(q+1)))*/ 00255 /* {*/ 00256 *p = '%'; 00257 p++; 00258 pc++; 00259 /* }*/ 00260 } 00261 00262 /* Copy the character of the string in*/ 00263 *p = *q; 00264 00265 /* Move everything along.*/ 00266 q++; 00267 p++; 00268 pc++; 00269 line_size++; 00270 00271 if ( pc > (maxsize -1) ) { 00272 break; 00273 } 00274 } 00275 00276 *p = '\0'; 00277 00278 /* This will have to be deallocated later!*/ 00279 if (newstr) *buffer = newstr; 00280 00281 return 0; 00282 }
Here is the caller graph for this function:

| int LOGGER_close_logfile | ( | void | ) |
Definition at line 172 of file logger.c.
References _LOGGER_outf, and result.
00173 { 00174 int result = 0; 00175 00176 if (_LOGGER_outf) fclose(_LOGGER_outf); 00177 00178 return result; 00179 }
| FILE* LOGGER_get_file | ( | void | ) |
Definition at line 50 of file logger.c.
References _LOGGER_outf.
00051 { 00052 return _LOGGER_outf; 00053 }
| int LOGGER_log | ( | char * | format, | |
| ... | ||||
| ) |
Definition at line 292 of file logger.c.
References _LOGGER_FILE, _LOGGER_mode, _LOGGER_outf, _LOGGER_STDERR, _LOGGER_STDOUT, _LOGGER_SYSLOG, _LOGGER_syslog_mode, FREE, LOGGER_clean_output(), output(), and vsnprintf().
Referenced by OLE_convert_directory(), OLE_decode_file(), OLE_decode_stream(), OLE_follow_chain(), OLE_follow_minichain(), OLE_get_block(), OLE_load_chain(), OLE_load_FAT(), OLE_load_minichain(), OLE_open_directory(), OLE_open_file(), OLE_set_debug(), OLE_store_stream(), OLEUNWRAP_decode_attachment(), OLEUNWRAP_decodestream(), OLEUNWRAP_save_stream(), PLD_strreplace_general(), ripole(), and ROLE_report_filename_decoded().
00293 { 00294 va_list ptr; 00295 char tmpoutput[10240]; 00296 char linebreak[]="\n"; 00297 char nolinebreak[]=""; 00298 char *lineend; 00299 char *output; 00300 00301 00302 /* get our variable arguments*/ 00303 va_start(ptr,format); 00304 00305 /* produce output, and spit to the log file*/ 00306 #ifdef NO_SNPRINTF 00307 vsprintf(tmpoutput, format, ptr); 00308 #else 00309 vsnprintf(tmpoutput,10240,format,ptr); 00310 #endif 00311 00312 LOGGER_clean_output( tmpoutput, &output ); 00313 00314 if ( output[strlen(output)-1] == '\n' ) { 00315 lineend = nolinebreak; 00316 } 00317 else { 00318 lineend = linebreak; 00319 } 00320 00321 if ( output[strlen(output)-1] == '\n' ) { lineend = nolinebreak; } else { lineend = linebreak; } 00322 00323 /* Send the output to the appropriate output destination*/ 00324 switch (_LOGGER_mode) { 00325 case _LOGGER_STDERR: 00326 fprintf(stderr,"%s%s",output, lineend ); 00327 break; 00328 case _LOGGER_SYSLOG: 00329 #ifndef _MSC_VER 00330 syslog(_LOGGER_syslog_mode,output); 00331 #endif 00332 break; 00333 case _LOGGER_STDOUT: 00334 fprintf(stdout,"%s%s",output, lineend); 00335 fflush(stdout); 00336 break; 00337 case _LOGGER_FILE: 00338 fprintf(_LOGGER_outf,"%s%s",output,lineend); 00339 fflush(_LOGGER_outf); 00340 break; 00341 default: 00342 fprintf(stdout,"LOGGER-Default: %s%s",output,lineend); 00343 } 00344 00345 00346 if (output) FREE(output); 00347 00348 return 0; 00349 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int LOGGER_set_logfile | ( | char * | lfname | ) |
Definition at line 109 of file logger.c.
References _LOGGER_outf, errno, result, and strerror().
00110 { 00111 int result = 0; 00112 00113 _LOGGER_outf = fopen(lfname,"a"); 00114 if (!_LOGGER_outf) 00115 { 00116 #ifndef _MSC_VER 00117 syslog(1,"LOGGER_set_logfile: ERROR - Cannot open logfile '%s' (%s)",lfname,strerror(errno)); 00118 #else 00119 fprintf(stderr, "LOGGER_set_logfile: ERROR - Cannot open logfile '%s' (%s)\n", lfname, strerror(errno)); 00120 #endif 00121 result = -1; 00122 } 00123 00124 return result; 00125 }
Here is the call graph for this function:

| int LOGGER_set_output_file | ( | FILE * | f | ) |
Definition at line 78 of file logger.c.
References _LOGGER_outf.
00079 { 00080 _LOGGER_outf = f; 00081 return 0; 00082 }
Definition at line 64 of file logger.c.
References _LOGGER_mode.
Referenced by ripole().
00065 { 00066 _LOGGER_mode = modechoice; 00067 return 0; 00068 }
Here is the caller graph for this function:

Definition at line 92 of file logger.c.
References _LOGGER_syslog_mode.
00093 { 00094 _LOGGER_syslog_mode = syslogmode; 00095 return 0; 00096 }
Definition at line 153 of file logger.c.
References LOGGER_glb, and LOGGER_globals::wrap.
00154 { 00155 if ( level >= 0 ) 00156 { 00157 LOGGER_glb.wrap = level; 00158 } 00159 00160 return LOGGER_glb.wrap; 00161 }
Definition at line 136 of file logger.c.
References LOGGER_glb, and LOGGER_globals::wraplength.
00137 { 00138 if ( length >= 0 ) 00139 { 00140 LOGGER_glb.wraplength = length; 00141 } 00142 00143 return LOGGER_glb.wraplength; 00144 }
int _LOGGER_mode = _LOGGER_SYSLOG [static] |
FILE* _LOGGER_outf [static] |
Definition at line 27 of file logger.c.
Referenced by LOGGER_close_logfile(), LOGGER_get_file(), LOGGER_log(), LOGGER_set_logfile(), and LOGGER_set_output_file().
int _LOGGER_syslog_mode = LOG_MAIL|LOG_INFO [static] |
struct LOGGER_globals LOGGER_glb = { 0, 0 } [static] |
Definition at line 37 of file logger.c.
Referenced by LOGGER_clean_output(), LOGGER_set_wrap(), and LOGGER_set_wraplength().
1.5.1