00001 #include <stdio.h>
00002 #include <stdarg.h>
00003 #include "errlog.h"
00004 #include "cmdparams.h"
00005
00006 #define kERRLOG "errlog"
00007 #define kHSTLOG "hstlog"
00008
00009
00010 FILE *errlog_errlogfile = NULL;
00011 FILE *errlog_hstlogfile = NULL;
00012
00013
00014 void errlog_errwrite (char *fmt, ...) {
00015 va_list ap;
00016 int m, n;
00017 char c, string[4096], newstr[5120];
00018
00019 va_start (ap, fmt);
00020 vsprintf (string, fmt, ap);
00021
00022 newstr[n = m = 0] = '\0';
00023 while (c = string[n++]) {
00024 newstr[m++] = c;
00025 if (c == '%') newstr[m++] = c;
00026 newstr[m] = '\0';
00027 }
00028
00029 if (errlog_errlogfile) {
00030 fprintf (errlog_errlogfile, newstr);
00031 fflush (errlog_errlogfile);
00032 } else {
00033 fprintf (stderr, newstr);
00034 fflush (stderr);
00035 }
00036 va_end (ap);
00037 }
00038
00039
00040 void errlog_hstwrite (char *fmt, ...) {
00041 va_list ap;
00042 int m, n;
00043 char c, string[4096], newstr[5120];
00044
00045 va_start (ap, fmt);
00046 vsprintf (string, fmt, ap);
00047
00048 newstr[n = m = 0] = '\0';
00049 while (c = string[n++]) {
00050 newstr[m++] = c;
00051 if (c == '%') newstr[m++] = c;
00052 newstr[m] = '\0';
00053 }
00054
00055 if (errlog_hstlogfile) {
00056 fprintf (errlog_hstlogfile, newstr);
00057 fflush (errlog_hstlogfile);
00058 } else {
00059 fprintf (stdout, newstr);
00060 fflush (stdout);
00061 }
00062 va_end (ap);
00063 }
00064
00065 int errlog_paramerr(LogPrint_t log, char *pname, ErrNo_t error, const char *series, long long recnum)
00066 {
00067 (*log)("** error '%d' in parameter '%s', series '%s', recnum '%lld' **\n",
00068 error,
00069 pname,
00070 series,
00071 recnum);
00072 return error;
00073 }
00074
00075 int errlog_paramdef(LogPrint_t log,
00076 char *pname,
00077 WarnNo_t warn,
00078 double defaultp,
00079 double *p,
00080 const char *series,
00081 long long recnum)
00082 {
00083
00084 *p = defaultp;
00085 (*log)(" ** warning '%d' - default value '%g' used for parameter '%s' in series '%s', recnum '%lld' **\n",
00086 defaultp,
00087 pname,
00088 series,
00089 recnum);
00090 return warn;
00091 }
00092
00093 int errlog_staterr(LogPrint_t log, char *msg, ErrNo_t error, const char *series, long long recnum)
00094 {
00095
00096 (*log)("** error '%d' (%s), series '%s', recnum '%lld'**\n",
00097 error,
00098 msg,
00099 series,
00100 recnum);
00101 return error;
00102 }
00103
00104 void errlog_seterrlog(CmdParams_t *cmdparams)
00105 {
00106 char *lf = cmdparams_get_str(cmdparams, kERRLOG, NULL);
00107 {
00108 if (lf)
00109 {
00110 errlog_errlogfile = fopen(lf, "a");
00111 }
00112 }
00113 }
00114
00115 void errlog_sethstlog(CmdParams_t *cmdparams)
00116 {
00117 char *lf = cmdparams_get_str(cmdparams, kHSTLOG, NULL);
00118 {
00119 if (lf)
00120 {
00121 errlog_hstlogfile = fopen(lf, "a");
00122 }
00123 }
00124 }