]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
Logging of messages to the logfile. Sergey.
authorhadaq <hadaq>
Wed, 4 Aug 2010 09:16:09 +0000 (09:16 +0000)
committerhadaq <hadaq>
Wed, 4 Aug 2010 09:16:09 +0000 (09:16 +0000)
hadaq/evtbuild.c

index f1ee7438803914f375af25097eb3d4c299381790..1a73a86cd5f0939574642298d014eb0c441e180d 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.124 2010-07-30 09:18:59 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.125 2010-08-04 09:16:09 hadaq Exp $";
 
 #define _POSIX_C_SOURCE 199309L
 #define SYSLOG_NAMES
@@ -17,6 +17,7 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 #include <sys/stat.h>
 #include <sys/vfs.h>
 #include <sys/time.h>
+#include <sys/utsname.h>
 #include <time.h>
 #include <dirent.h>
 
@@ -45,6 +46,7 @@ static RFILE *fRemote = NULL;
 #define MAXINPATH 100
 
 #define DAQVERSION 2                   /* needed by Hydra unpackers */
+
 #define NEVTIDS 64UL                   /* must be 2^n */
 #define NEVTIDS_IN_FILE 0UL            /* must be 2^n */
 #define EVENT_NUM_OFFSET 100
@@ -73,6 +75,8 @@ static int trig_mismatch;
 
 static int evtBrokenFlag = 0;
 
+static char msglog[300];
+
 typedef struct TheArgsS {
        unsigned long nrOfMsgs;
        char outPath[PARAM_MAX_VALUE_LEN];
@@ -134,12 +138,13 @@ typedef struct TheArgsS {
        char shmname[PARAM_MAX_VALUE_LEN];
        unsigned int ebnum;
        char runinfo2ora[PARAM_MAX_VALUE_LEN];
-       char evtstat[PARAM_MAX_VALUE_LEN];      /* file name for statistics of discarded event */
+       char logname[PARAM_MAX_VALUE_LEN];      /* file name for statistics of discarded event */
 
        char fileName[PARAM_MAX_VALUE_LEN];
        unsigned short multiDisks;      /*  Write files to diferent disks */
 
        unsigned long maxTrigMissmatch;
+       char hostname[PARAM_MAX_VALUE_LEN];
 } TheArgs;
 
 typedef struct TheStatsS {
@@ -288,6 +293,19 @@ static void usage(const char *progName)
        syslog(LOG_ERR, "       [--ebnum num]                Number of the event builder.");
 }
 
+static void storeLogInfo(TheArgs *theArgs, const char *msg)
+{
+
+       FILE *fp;
+       char ltime[20];                         /* local time */
+       time_t t = time(NULL);
+       strftime(ltime, 20, "%b %02d %02H:%02M:%02S", localtime(&t));
+
+       fp = fopen(theArgs->logname, "a+");
+       fprintf(fp, "%s %10s %s %2s %13s %s\n", ltime, theArgs->hostname, "EB", theArgs->shmname, "daq_evtbuild:", msg);
+       fclose(fp);
+}
+
 static int makeTrigType(TheArgs *my)
 {
        int retVal = 0;
@@ -342,11 +360,13 @@ static int makeQueues(TheArgs *my)
        for (i = 0; i < my->queueVarSizeCnt; i++) {
 
                if (0 == (sscanf(my->queueVarSize[i], "%d:%s", &queueNum, newQueueSize))) {
+                       storeLogInfo(my, "<E> makeQueues: queueVarSize option is wrong.");
                        syslog(LOG_ERR, "evtbuild.c: makeQueues: %s", "queueVarSize option is wrong.");
                        retVal = -1;
                        break;
                } else {
                        if (queueNum >= my->nrOfMsgs) {
+                               storeLogInfo(my, "<E> makeQueues: queue number in queueVarSize option exceeds maximum number of data sources.");
                                syslog(LOG_ERR, "evtbuild.c: makeQueues: %s",
                                           "queue number in queueVarSize option exceeds maximum number of data sources.");
                                retVal = -1;
@@ -479,7 +499,7 @@ static void argsDefault(TheArgs *my)
 
        /* read path from DAQ_SETUP and define full file name */
        sprintf(my->runinfo2ora, "%s_runinfo2ora.txt", getenv("DAQ_SETUP"));
-       sprintf(my->evtstat, "%s_evtstat.txt", getenv("DAQ_SETUP"));
+       sprintf(my->logname, "%s%s_log.txt", getenv("DAQ_SETUP"), my->shmname);
 
        my->multiDisks = 0;                     /* Write files only on one disk */
 
@@ -495,6 +515,9 @@ static void argsDefault(TheArgs *my)
        my->debugOptsCnt = 0;
 
        my->maxTrigMissmatch = 100000;
+
+       /* Get host name */
+       gethostname(my->hostname, 30);
 }
 
 static int argsFromCL(TheArgs *my, int argc, char *argv[])
@@ -661,6 +684,7 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                        break;
                }
        }
+
        if (optind < argc) {
                printf("non-option ARGV-elements: ");
                while (optind < argc)
@@ -668,6 +692,8 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                printf("\n");
        }
 
+       sprintf(my->logname, "%s%s_log.txt", getenv("DAQ_SETUP"), my->shmname);
+
        return 0;
 }
 
@@ -679,7 +705,8 @@ static int argsCheck(TheArgs *my)
 
        /* check my->maxFileSz */
        if ((strcmp(my->outDev, "null") != 0) && (my->maxFileSz <= 0 || my->maxFileSz >= 2 * 1024 * 1024 * 1024UL)) {
-               fprintf(stderr, "<E> evtbuild.c, argsCheck(): --filesize must be >0MB and <2000MB\n");
+               storeLogInfo(my, "<E> argsCheck: --filesize must be >0MB and <2000MB.");
+               fprintf(stderr, "<E> evtbuild.c, argsCheck: --filesize must be >0MB and <2000MB\n");
                return 1;
        }
 
@@ -687,38 +714,43 @@ static int argsCheck(TheArgs *my)
        if ((my->resdownscale != 0 && (my->resnumevents == -1 || (strcmp(my->respath, "") == 0))) ||
                (my->resnumevents != -1 && (my->resdownscale == 0 || (strcmp(my->respath, "") == 0))) ||
                ((strcmp(my->respath, "") != 0) && (my->resnumevents == -1 || my->resdownscale == 0))) {
-
-               fprintf(stderr,
-                               "<E> evtbuild.c, argsCheck(): options --resdownscale --resnumevents --respath must be specified together\n");
+               storeLogInfo(my, "<E> argsCheck: options --resdownscale --resnumevents --respath must be specified together.");
+               fprintf(stderr, "<E> evtbuild.c, argsCheck: options --resdownscale --resnumevents --respath must be specified together\n");
                return 1;
        }
 
        /* check my->resdownscale */
-       if ((strcmp(my->respath, "") != 0) && (my->resdownscale <= 0 || my->resdownscale >= 100001)) {
-               fprintf(stderr, "<E> evtbuild.c, argsCheck(): --resdownscale must be >0 and <100001\n");
+       if ((strcmp(my->respath, "") != 0) && (my->resdownscale <= 0 || my->resdownscale > 100000)) {
+               storeLogInfo(my, "<E> argsCheck: --resdownscale must be >0 and <=100000.");
+               fprintf(stderr, "<E> evtbuild.c, argsCheck: --resdownscale must be >0 and <=100000\n");
                return 1;
        }
 
        /* check my->resnumevents */
-       if ((strcmp(my->respath, "") != 0) && (my->resnumevents <= 99 || my->resnumevents >= 1000000001)) {
-               fprintf(stderr, "<E> evtbuild.c, argsCheck(): --resnumevents must be >99 and <1000000001\n");
+       if ((strcmp(my->respath, "") != 0) && (my->resnumevents <= 99 || my->resnumevents > 1000000000)) {
+               storeLogInfo(my, "<E> argsCheck: --resnumevents must be >99 and <=1000000000.");
+               fprintf(stderr, "<E> evtbuild.c, argsCheck: --resnumevents must be >99 and <=1000000000\n");
                return 1;
        }
 
        /* check my->secsizelimit */
        if ((strcmp(my->respath, "") != 0) &&
-               (my->secsizelimit <= -0.0001 || my->secsizelimit >= 0.0001) && (my->secsizelimit <= 10 || my->secsizelimit >= 100001)) {
-               fprintf(stderr, "<E> evtbuild.c, argsCheck(): --secsizelimit must be >10 and <100000 MB\n");
+               (my->secsizelimit <= -0.0001 || my->secsizelimit >= 0.0001) && (my->secsizelimit <= 10 || my->secsizelimit > 100000)) {
+               storeLogInfo(my, "<E> argsCheck: --secsizelimit must be >10 and <=100000 MB.");
+               fprintf(stderr, "<E> evtbuild.c, argsCheck: --secsizelimit must be >10 and <=100000 MB\n");
                return 1;
        }
 
        /* check my->ressizelimit */
        if ((strcmp(my->respath, "") != 0) && (my->ressizelimit <= 5 || my->ressizelimit >= 1000)) {
-               fprintf(stderr, "<E> evtbuild.c, argsCheck(): --ressizelimit must be >5 and <1000\n");
+               storeLogInfo(my, "<E> argsCheck: --ressizelimit must be >5 and <1000.");
+               fprintf(stderr, "<E> evtbuild.c, argsCheck: --ressizelimit must be >5 and <1000\n");
                return 1;
        }
 
        if (((my->maxFileSz) < (my->queueSize[0]))) {
+               storeLogInfo(my, "<E> argsCheck: --filesize must be larger than queuesize(-q).");
+               storeLogInfo(my, "<W> argsCheck: the queue size must be given in MBytes.");
                fprintf(stderr, "<E> evtbuild.c, argsCheck(): --filesize must be larger than queuesize(-q)\n");
                fprintf(stderr, "<W> evtbuild.c, argsCheck(): the queue size must be given in MBytes\n");
                return 1;
@@ -726,12 +758,14 @@ static int argsCheck(TheArgs *my)
 
        /* the condition ressizelimit has to be together with respath */
        if ((my->ressizelimit) != 0 && (strcmp(my->respath, "") == 0)) {
+               storeLogInfo(my, "<E> argsCheck: --respath is not given.");
                fprintf(stderr, "<E> evtbuild.c, argsCheck(): --respath is not given\n");
                return 1;
        }
 
        /* Check queue sizes */
        if (1 * 1024 * 1024 * 1024UL < (my->queueSize[0])) {
+               storeLogInfo(my, "<W> argsCheck: the queue size must be given in MBytes.");
                fprintf(stderr, "<W> evtbuild.c, argsCheck(): the queue size must be given in MBytes\n");
                return 1;
        }
@@ -749,6 +783,7 @@ static int argsCheck(TheArgs *my)
                } else if (strcmp(my->debugOpts[i], "size") == 0) {
                        my->debug_size = 1;
                } else {
+                       storeLogInfo(my, "<E> wrong argument is given in the option -D|--debug.");
                        printf("Error: wrong argument is given in the option -D|--debug.\n");
                        return 1;
                }
@@ -861,6 +896,7 @@ static int fillDebug(TheArgs *theArgs, TheStats *theStats, TheDebug * theDebug,
                }
        } else {
                printf("fillDebug: Event has unknown status!\n");
+               storeLogInfo(theArgs, "<E> fillDebug: Event has unknown status!");
        }
 
        evtBrokenFlag = 1;
@@ -987,6 +1023,8 @@ static void printPopTrigMissmatch(TheArgs *theArgs, TheStats *theStats, TheDebug
 {
        int i;
 
+       storeLogInfo(theArgs, "<E> trigger missmatch is too large. Exit.");
+
        printf("\n\n");
        fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d.\n", theArgs->maxTrigMissmatch);
 
@@ -1053,6 +1091,8 @@ static void printBrokenTrigMissmatch(TheArgs *theArgs, TheStats *theStats)
 {
        int i;
 
+       storeLogInfo(theArgs, "<E> trigger missmatch is too large. Exit.");
+
        printf("\n\n");
        fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d.\n", theArgs->maxTrigMissmatch);
        printf("\n");
@@ -1131,12 +1171,14 @@ unsigned long getRunId(TheArgs *my)
 
                if (Worker_getStatistic(buf, "runId", &myRunId) == -1) {
                        fprintf(stderr, "<E> evtbuild.c: getRunId: Worker_getStatistic: cannot get runId!\n");
+                       storeLogInfo(my, "<N> getRunId: Worker_getStatistic: cannot get runId yet!");
                        sleep(1);
                } else {
 
                        t = time(NULL);
                        dT = t - t0;
                        if (dT > 2) {
+                               storeLogInfo(my, "<I> getRunId: Still waiting for runId from EPICS IOC...");
                                printf("Still waiting for runId from EPICS IOC...\n");
                                t0 = t;
                        }
@@ -1150,21 +1192,9 @@ unsigned long getRunId(TheArgs *my)
        return myRunId;
 }
 
-static void storeEvtStat(TheArgs *myArgs, unsigned long evtstat)
-{
-
-       FILE *fp;
-       char ltime[20];                         /* local time */
-       time_t t = time(NULL);
-       strftime(ltime, 20, "%Y-%m-%d %H:%M:%S", localtime(&t));
-
-       fp = fopen(myArgs->evtstat, "a+");
-       fprintf(fp, "%s %d %s %d %d %d\n", "daq_evtbuild:", (int) getpid(), ltime, myArgs->runNr, myArgs->ebnum, evtstat);
-       fclose(fp);
-}
-
 static void statsDump(TheArgs *theArgs, TheStats *my, int interval)
 {
+
        static unsigned long lastEC = 0;
        static unsigned long lastEE = 0;
        static unsigned long lastTE = 0;
@@ -1215,8 +1245,10 @@ static void statsDump(TheArgs *theArgs, TheStats *my, int interval)
                                fputc('\n', stderr);
                        }
 
-                       if (*my->evtsDiscarded - lastED > 0)
-                               storeEvtStat(theArgs, *my->evtsDiscarded - lastED);
+                       if (*my->evtsDiscarded - lastED > 0) {
+                               sprintf(msglog, "<W> discarded events: %d", *my->evtsDiscarded - lastED);
+                               storeLogInfo(theArgs, msglog);
+                       }
 
                        lastEC = *my->evtsComplete;
                        lastEE = *my->evtsDataError;
@@ -1581,6 +1613,7 @@ static void changeDisk(int once, TheArgs *theArgs, TheStats *theStats)
 
                        if (Worker_getStatistic(buf, "diskNum", &diskNr) == -1) {
                                diskNr = 0;
+                               storeLogInfo(theArgs, "<E> ChangeDisk: Worker_getStatistic failed for diskNum!");
                                syslog(LOG_ERR, "Worker_getStatistic failed for diskNum!");
                        }
 
@@ -1617,7 +1650,6 @@ static void changeDisk(int once, TheArgs *theArgs, TheStats *theStats)
 
 static int openFile(TheArgs *theArgs, TheStats *theStats)
 {
-
        char fileName[_POSIX_PATH_MAX];
        static char outPath[_POSIX_PATH_MAX];
        static char outLustrePath[_POSIX_PATH_MAX];
@@ -1707,6 +1739,8 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
                }
 
                if (NULL == (outFile = fopen(theArgs->outPath, "wb"))) {
+                       sprintf(msglog, "<E> %s, %d: fopen: failed to open file %s: %s", __FILE__, __LINE__, theArgs->outPath, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
                        syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
                        outFile = NULL;
                        return -1;
@@ -1717,6 +1751,10 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
                                errno = ENOSPC;
                                outFile = NULL;
                                unlink(theArgs->outPath);
+
+                               sprintf(msglog, "<E>  %s, %d: no space left to open new file %s: %s", __FILE__, __LINE__, theArgs->outPath,
+                                               strerror(errno));
+                               storeLogInfo(theArgs, msglog);
                                syslog(LOG_ERR, "opening file %s: %s", theArgs->outPath, strerror(errno));
                                return -1;
                        }
@@ -1731,6 +1769,8 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
                        return -1;
                }
        } else {
+               sprintf(msglog, "<E> %s, %d: unknown outputDev %s", __FILE__, __LINE__, theArgs->outDev);
+               storeLogInfo(theArgs, msglog);
                syslog(LOG_ERR, "unknown outputDev \"%s\"", theArgs->outDev);
                return -1;
        }
@@ -1814,7 +1854,10 @@ static int openFile(TheArgs *theArgs, TheStats *theStats)
 
                fprintf(stderr, "<D> evtbuild.c, rfio_fnewfile(): trying to open remote file %s\n", rfioPath);
                if (0 != rfio_fnewfile(fRemote, rfioPath)) {
-                       syslog(LOG_ERR, "%s, %d: cannot open remote file %s: %s", __FILE__, __LINE__, rfioPath, strerror(errno));
+                       sprintf(msglog, "<E> %s, %d: rfio_fnewfile: failed to open file %s: %s", __FILE__, __LINE__, rfioPath, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
+                       syslog(LOG_ERR, "%s, %d: rfio_fnewfile: failed to open remote file %s: %s", __FILE__, __LINE__, rfioPath,
+                                  strerror(errno));
                        exit(EXIT_FAILURE);
                }
        }
@@ -1882,7 +1925,10 @@ static int openRESFile(TheArgs *theArgs)
        outRESFile = NULL;
 
        if (NULL == (outRESFile = fopen(theArgs->respath, "wb"))) {
-               syslog(LOG_ERR, "%s, %d: opening file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
+               sprintf(msglog, "<E> %s, %d: openRESFile: failed to open file %s: %s", __FILE__, __LINE__, theArgs->respath,
+                               strerror(errno));
+               storeLogInfo(theArgs, msglog);
+               syslog(LOG_ERR, "%s, %d: failed to open file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
                outRESFile = NULL;
                return -1;
        } else {
@@ -1891,12 +1937,16 @@ static int openRESFile(TheArgs *theArgs)
                if ((theArgs->maxFileSz) / buf->f_bsize > buf->f_bavail) {
                        errno = ENOSPC;
                        if (0 != fclose(outRESFile)) {
-                               syslog(LOG_ERR, "%s, %d: trying fclose 'outRESFile': %s", __FILE__, __LINE__, strerror(errno));
+                               sprintf(msglog, "<E> %s, %d: openRESFile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+                               storeLogInfo(theArgs, msglog);
+                               syslog(LOG_ERR, "%s, %d: failed to fclose 'outRESFile': %s", __FILE__, __LINE__, strerror(errno));
                        }
                        outRESFile = NULL;
                        unlink(theArgs->respath);
 
-                       syslog(LOG_ERR, "%s, %d: opening file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
+                       sprintf(msglog, "<E> %s, %d: openRESFile: failed to open file: %s", __FILE__, __LINE__, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
+                       syslog(LOG_ERR, "%s, %d: failed to open file %s: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
                        return -1;
                }
        }
@@ -1904,9 +1954,8 @@ static int openRESFile(TheArgs *theArgs)
        return 0;
 }
 
-static int writeFile(void *evt)
+static int writeFile(TheArgs *theArgs, void *evt)
 {
-
        int writeFileR;
 
        Evt_setSeqNr(evt, seqNr++);
@@ -1920,8 +1969,11 @@ static int writeFile(void *evt)
 #ifdef RFIO
        /* write to Data Mover via RFIO */
        if (fRemote != NULL) {
-               if (0 >= rfio_fwrite(evt, 1, Evt_paddedSize(evt), fRemote))
-                       syslog(LOG_ERR, "%s, %d: writing file via RFIO: %s", __FILE__, __LINE__, strerror(errno));
+               if (0 >= rfio_fwrite(evt, 1, Evt_paddedSize(evt), fRemote)) {
+                       sprintf(msglog, "<E> %s, %d: rfio_fwrite: failed to write: %s", __FILE__, __LINE__, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
+                       syslog(LOG_ERR, "%s, %d: failed to write file via RFIO: %s", __FILE__, __LINE__, strerror(errno));
+               }
        }
 #endif
 
@@ -1951,7 +2003,7 @@ static int writeRESFile(void *evt)
        return writeFileR;
 }
 
-static int closeFile()
+static int closeFile(TheArgs *theArgs)
 {
        int closeFileR;
        int closeLustreFileR;
@@ -1967,7 +2019,9 @@ static int closeFile()
        if (outFile != NULL) {
                closeFileR = fclose(outFile);
                if (0 != closeFileR) {
-                       syslog(LOG_ERR, "%s, %d: trying fclose 'outFile': %s", __FILE__, __LINE__, strerror(errno));
+                       sprintf(msglog, "<E> %s, %d: closeFile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
+                       syslog(LOG_ERR, "%s, %d: failed to fclose 'outFile': %s", __FILE__, __LINE__, strerror(errno));
                }
        } else if (outTape != NULL) {
                closeFileR = closeAnsiTape(outTape);
@@ -1985,6 +2039,8 @@ static int closeFile()
        /* close file on Data Mover */
        if (fRemote != NULL) {
                if (0 != rfio_fendfile(fRemote)) {
+                       sprintf(msglog, "<E> %s, %d: rfio_fendfile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
                        syslog(LOG_ERR, "%s, %d: trying rfio_fendfile: %s", __FILE__, __LINE__, strerror(errno));
                        exit(EXIT_FAILURE);
                }
@@ -2001,9 +2057,13 @@ static int closeRESFile(TheArgs *theArgs)
                res_dirSize += res_file_size;
                closeFileR = fclose(outRESFile);
                if (0 != closeFileR) {
+                       sprintf(msglog, "<E> %s, %d: closeRESFile: failed to close file: %s", __FILE__, __LINE__, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
                        syslog(LOG_ERR, "%s, %d: trying fclose 'outRESFile': %s", __FILE__, __LINE__, strerror(errno));
                }
        } else {
+               sprintf(msglog, "<E> %s, %d: closeRESFile: outRESFile is NULL: %s", __FILE__, __LINE__, theArgs->respath, strerror(errno));
+               storeLogInfo(theArgs, msglog);
                syslog(LOG_ERR, "%s, %d: closeRESFile failed: outRESFile is NULL", __FILE__, __LINE__);
        }
 
@@ -2028,6 +2088,8 @@ static int rfio_openConnection(TheArgs *theArgs, TheStats *theStats)
                strncpy(pcc, "\0", 1);  /* terminates after node name */
 
                fprintf(stderr, "<I> evtbuild.c, rfio_fopen(): trying to open connection to Data Mover: %s\n", rfioBase);
+               sprintf(msglog, "<I> rfio_fopen: opening connection to Data Mover: %s", rfioBase);
+               storeLogInfo(theArgs, msglog);
                /* fRemote = rfio_fopen( rfioBase, "wb" ); */
 
                char pcDataMover[16];   /* name of the Data Mover */
@@ -2039,7 +2101,10 @@ static int rfio_openConnection(TheArgs *theArgs, TheStats *theStats)
                                                                           theArgs->rfio_iCopyFrac, theArgs->rfio_iMaxFile, theArgs->rfio_iPathConv);
 
                if (fRemote == NULL) {
-                       syslog(LOG_ERR, "%s, %d: trying to open connection to Data Mover %s: %s",
+                       sprintf(msglog, "<E> %s, %d: rfio_fopen_gsidaq_dm: failed to open connection to Data Mover %s: %s", __FILE__, __LINE__,
+                                       rfioBase, strerror(errno));
+                       storeLogInfo(theArgs, msglog);
+                       syslog(LOG_ERR, "%s, %d: rfio_fopen_gsidaq_dm: failed to open connection to Data Mover %s: %s",
                                   __FILE__, __LINE__, rfioBase, strerror(errno));
                        exit(EXIT_FAILURE);
                }
@@ -2056,7 +2121,11 @@ static int rfio_closeConnection(TheArgs *theArgs)
        if ((strcmp(theArgs->rfioRemotePath, "") != 0) && fRemote != NULL) {
 
                if (0 != rfio_fclose(fRemote)) {
-                       syslog(LOG_ERR, "%s, %d: trying to close connection to Data Mover: %s", __FILE__, __LINE__, strerror(errno));
+                       sprintf(msglog, "<E> %s, %d: rfio_fclose: failed to close connection to Data Mover: %s", __FILE__, __LINE__,
+                                       strerror(errno));
+                       storeLogInfo(theArgs, msglog);
+                       syslog(LOG_ERR, "%s, %d: rfio_fclose: failed to close connection to Data Mover: %s", __FILE__, __LINE__,
+                                  strerror(errno));
                        exit(EXIT_FAILURE);
                }
        }
@@ -2097,6 +2166,8 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
+       storeLogInfo(theArgs, "<I> started.");
+
        if (0 > makeQueues(theArgs)) {
                usage(argv[0]);
                exit(EXIT_FAILURE);
@@ -2130,14 +2201,19 @@ int main(int argc, char *argv[])
        sprintf(buf, "%s%s", argv[0], theArgs->shmname);
 
        if (NULL == (worker = Worker_initBegin(buf, sigHandler, theArgs->priority, theArgs->isStandalone))) {
+               sprintf(msglog, "<E> %s, %d: Worker_initBegin: failed to init: %s", __FILE__, __LINE__, strerror(errno));
+               storeLogInfo(theArgs, msglog);
                syslog(LOG_ERR, "%s, %d: %s", __FILE__, __LINE__, strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        if (theArgs->online == 0)
                syslog(LOG_WARNING, "DISABLE of online service");
-       else if (-1 == initOnline())
+       else if (-1 == initOnline()) {
                syslog(LOG_WARNING, "unable to initialize online service");
+               sprintf(msglog, "<E> %s, %d: initOnline: failed to init online service: %s", __FILE__, __LINE__, strerror(errno));
+               storeLogInfo(theArgs, msglog);
+       }
 
        if (theArgs->nrOfMsgs == 0) {
                /*
@@ -2167,7 +2243,10 @@ int main(int argc, char *argv[])
 
                        shmTrans[i] = ShmTrans_create(buf, 2 * theArgs->queueSize[i]);
                        if (shmTrans[i] == NULL) {
-                               fprintf(stderr, "<E> ShmTrans_create: could not create buffer /dev/shm/%s.shm\n", buf);
+                               sprintf(msglog, "<E> %s, %d: ShmTrans_create: failed to create buffer /dev/shm/%s.shm: %s", __FILE__, __LINE__, buf,
+                                               strerror(errno));
+                               storeLogInfo(theArgs, msglog);
+                               fprintf(stderr, "<E> ShmTrans_create: failed to create buffer /dev/shm/%s.shm\n", buf);
                        }
 
                        hadTuQueue[i] = NULL;
@@ -2302,7 +2381,7 @@ int main(int argc, char *argv[])
                        }
 
                        (*theStats->bytesWritten) += Evt_size(evt);
-                       writeFile(evt);
+                       writeFile(theArgs, evt);
                        deleteEvt(evt);
                }
 
@@ -2394,7 +2473,6 @@ int main(int argc, char *argv[])
 
                                popCnt++;
                                if (popCnt > theArgs->maxTrigMissmatch) {
-                                       fprintf(stderr, "<E> daq_evtbuild: trigger missmatch is above %d. Exit.\n", theArgs->maxTrigMissmatch);
                                        printPopTrigMissmatch(theArgs, theStats, theDebug, i);
                                        goto bailOut1;
                                }
@@ -2438,7 +2516,7 @@ int main(int argc, char *argv[])
 #endif
                        }
                        (*theStats->bytesWritten) += Evt_size(evt);
-                       writeFile(evt);
+                       writeFile(theArgs, evt);
 
                        if (theArgs->resdownscale) {
 
@@ -2493,7 +2571,7 @@ int main(int argc, char *argv[])
                                evt = appendFile(evt, theArgs->slowCtrlFiles[i]);
 
                        (*theStats->bytesWritten) += Evt_size(evt);
-                       writeFile(evt);
+                       writeFile(theArgs, evt);
                        deleteEvt(evt);
 
 /*       if( theArgs->epicsCtrl ) */
@@ -2501,7 +2579,7 @@ int main(int argc, char *argv[])
 /*       else */
                        ourTime = time(NULL);
 
-                       closeFile();
+                       closeFile(theArgs);
 
                        storeInfoStop(argv[0], ourTime, worker, theArgs);
 
@@ -2542,8 +2620,10 @@ int main(int argc, char *argv[])
 
   bailOut1:
 
+       storeLogInfo(theArgs, "<I> exited.");
+
        ourTime = time(NULL);
-       closeFile();
+       closeFile(theArgs);
 
 #ifdef RFIO
        rfio_closeConnection(theArgs);