]> jspc29.x-matter.uni-frankfurt.de Git - daqdata.git/commitdiff
Centralized logging via syslog. Sergey.
authorhadaq <hadaq>
Tue, 12 Apr 2011 16:34:40 +0000 (16:34 +0000)
committerhadaq <hadaq>
Tue, 12 Apr 2011 16:34:40 +0000 (16:34 +0000)
hadaq/args.c
hadaq/args.h
hadaq/evtbuild.c
hadaq/logger.c
hadaq/netmem.c

index f426a71d431c57f662d714dfcc3b2b7d090defbc..c2eedb7a952e909a133d775b5e88cb6bba1eb1f5 100644 (file)
@@ -52,6 +52,8 @@ void Args_default(TheArgs *my)
 {
        int i;
 
+       strcpy(my->progName, "daq");
+
        my->nrOfMsgs = 0;
        for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) {
                my->slowCtrlFiles[i] = my->slowCtrlFilesS[i];
@@ -118,8 +120,8 @@ void Args_default(TheArgs *my)
 
        my->maxTrigMismatch = -1;
 
-       /* Get host name */
-       gethostname(my->hostname, 30);
+       gethostname(my->hostname, 30);  /* Get host name */
+       strcpy(my->log, "syslog");
 }
 
 int Args_fromCL(TheArgs *my, int argc, char *argv[])
@@ -157,9 +159,10 @@ int Args_fromCL(TheArgs *my, int argc, char *argv[])
                        {"trigtype", 1, 0, 'T'},
                        {"multidisks", 1, 0, 'k'},
                        {"maxtrigmismatch", 1, 0, 'g'},
+                       {"log", 1, 0, 'Y'},
                        {0, 0, 0, 0}
                };
-               i = getopt_long(argc, argv, "am:f:r:o:d:q:Q:p:v:x:I:tz:e:n:h:w:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:D:T:k:g:", long_options,
+               i = getopt_long(argc, argv, "am:f:r:o:d:q:Q:p:v:x:I:tz:e:n:h:w:Hs:l:R:A:bEL:S:B:O:iW:M:F:X:C:D:T:k:g:Y:", long_options,
                                                &option_index);
                if (i == -1)
                        break;
@@ -278,6 +281,9 @@ int Args_fromCL(TheArgs *my, int argc, char *argv[])
                case 'g':
                        my->maxTrigMismatch = strtoul(optarg, NULL, 0);
                        break;
+               case 'Y':
+                       strcpy(my->log, optarg);
+                       break;
                case 'H':
                        return -1;
                        break;
@@ -296,6 +302,8 @@ int Args_fromCL(TheArgs *my, int argc, char *argv[])
 
        sprintf(my->logname, "%s%s_log.txt", getenv("DAQ_SETUP"), my->shmname);
 
+       strcpy(my->progName, (char *) basename(argv[0]));
+
        return 0;
 }
 
index d7f976b84eacf995fbe499b99c11f5bf71044ece..4017b9dde627722c6b0c4b9cf4e9866cfafdcbea 100644 (file)
@@ -8,6 +8,7 @@
 #include <allParam.h>
 
 typedef struct TheArgsS {
+        char progName[PARAM_MAX_VALUE_LEN];
        unsigned long nrOfMsgs;
        char outPath[PARAM_MAX_VALUE_LEN];
        char outDev[PARAM_MAX_VALUE_LEN];
@@ -74,6 +75,7 @@ typedef struct TheArgsS {
 
        unsigned long maxTrigMismatch;
        char hostname[PARAM_MAX_VALUE_LEN];
+        char log[PARAM_MAX_VALUE_LEN];
 } TheArgs;
 
 
index 623318c2e364d750e5db51ac8a3de253a97919f2..ae547898025adcc2a22bc18616f6730f57af18f1 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.145 2011-02-14 13:59:40 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.146 2011-04-12 16:34:40 hadaq Exp $";
 
 #define _POSIX_C_SOURCE 199309L
 #define SYSLOG_NAMES
@@ -148,6 +148,8 @@ static void usage(const char *progName)
        syslog(LOG_ERR, "       [--multidisk diskNr]         Write data to a disk number provided by daq_disks via shared memory.");
        syslog(LOG_ERR,
                   "                                    The very first file will be written to diskNr provided via --multidisk option.");
+       syslog(LOG_ERR, "       [-Y|--log <file>|<syslog>]   Logging method (default: syslog).");
+
        syslog(LOG_ERR, "");
        syslog(LOG_ERR, "Options for debugging:");
        syslog(LOG_ERR, "       [-v debug|info|notice|warning|err|alert|crit|emerg]");
index b7e01fefee6fc9d4ad6a4accc54e303fda21393b..80956b9be50e5a9b7c2f84980e43ded1a6946611 100644 (file)
@@ -4,6 +4,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
+#include <syslog.h>
+#include <unistd.h>
 
 #include "logger.h"
 
@@ -23,14 +25,30 @@ static char *unit(unsigned long v)
 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);
+       if (strcmp(theArgs->log, "file") == 0) {
+               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, theArgs->progName, msg);
+               fclose(fp);
+       } else if (strcmp(theArgs->log, "syslog") == 0) {
+               openlog("DAQ", LOG_ODELAY, LOG_LOCAL1); /* Centralized logging */
+               printf("progName: %s\n", theArgs->progName);
+               /* Identify the application name */
+               if (strcmp(theArgs->progName, "daq_evtbuild") == 0) {
+                       syslog(LOG_INFO, "%s-%s %s", "EVTBLD", theArgs->shmname, msg);
+               } else if (strcmp(theArgs->progName, "daq_netmem") == 0) {
+                       syslog(LOG_INFO, "%s-%s %s", "NETMEM", theArgs->shmname, msg);
+               } else {
+                       syslog(LOG_INFO, "%s-%s %s", "UNKNOWN", theArgs->shmname, msg);
+               }
+               openlog(theArgs->progName, LOG_PID | LOG_PERROR, LOG_LOCAL0);   /* Restore syslog settings */
+       } else {
+               /* Unknown logging method */
+       }
 }
 
 void storeRunInfoStart(time_t t, TheArgs *myArgs)
index 174803f8e519fac372681b5c1ac6cea776de8112..7b86ae8fe3a6ad26689a24f305a945257390bb6c 100644 (file)
@@ -1,4 +1,4 @@
-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/netmem.c,v 6.51 2011-02-24 13:32:49 hadaq Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/netmem.c,v 6.52 2011-04-12 16:34:40 hadaq Exp $";
 
 #define _POSIX_C_SOURCE 199309L
 #define SYSLOG_NAMES
@@ -24,6 +24,8 @@ static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hada
 static char msglog[300];
 
 typedef struct TheArgsS {
+       char log[PARAM_MAX_VALUE_LEN];
+       char progName[PARAM_MAX_VALUE_LEN];
        char inPathS[MAXINPATH][PARAM_MAX_NAME_LEN];
        char *inPath[MAXINPATH];
        int inPathCnt;
@@ -78,6 +80,7 @@ static void usage(const char *progName)
        syslog(LOG_ERR, "       [-Q queueNr:queueSize]       Set different queue sizes in MB for different queue numbers,");
        syslog(LOG_ERR, "                                    example: -Q 2:4 -Q 4:8 -Q 5:12");
        syslog(LOG_ERR, "       [-d seconds]                 Maximum delay of incoming data in seconds.");
+       syslog(LOG_ERR, "       [-Y|--log <file>|<syslog>]   Logging method (default: syslog).");
 }
 
 static int makeQueues(TheArgs *my)
@@ -161,6 +164,9 @@ static void argsDefault(TheArgs *my)
 
        /* Get host name */
        gethostname(my->hostname, 30);
+
+       strcpy(my->progName, "daq");
+       strcpy(my->log, "syslog");
 }
 
 static int argsFromCL(TheArgs *my, int argc, char *argv[])
@@ -173,7 +179,7 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
        inPathCntFromParam = my->inPathCnt;
        my->inPathCnt = 0;
 
-       while ((i = getopt(argc, argv, "ai:m:q:Q:p:v:bS:d:")) != -1) {
+       while ((i = getopt(argc, argv, "ai:m:q:Q:p:v:bS:d:Y:")) != -1) {
                switch (i) {
                case 'm':
                        my->nrOfMsgs = atoi(optarg);
@@ -202,6 +208,9 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                case 'd':
                        my->dataDelay = atoi(optarg);
                        break;
+               case 'Y':
+                       strcpy(my->log, optarg);
+                       break;
                default:
                        return -1;
                        break;
@@ -242,6 +251,8 @@ static int argsFromCL(TheArgs *my, int argc, char *argv[])
                }
        }
 
+       strcpy(my->progName, (char *) basename(argv[0]));
+
        return 0;
 }
 
@@ -279,17 +290,33 @@ static char *unit(unsigned long v)
        return retVal;
 }
 
-static void storeLogInfo(TheArgs *theArgs, const char *msg)
+void storeLogInfo(TheArgs *theArgs, const char *msg)
 {
 
-       FILE *fp;
-       char ltime[20];                         /* local time */
-       time_t t = time(NULL);
-       strftime(ltime, 20, "%b %2d %2H:%2M:%2S", localtime(&t));
-
-       fp = fopen(theArgs->logname, "a+");
-       fprintf(fp, "%s %10s %s %2s %13s %s\n", ltime, theArgs->hostname, "EB", theArgs->shmname, "daq_netmem:", msg);
-       fclose(fp);
+       if (strcmp(theArgs->log, "file") == 0) {
+               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, theArgs->progName, msg);
+               fclose(fp);
+       } else if (strcmp(theArgs->log, "syslog") == 0) {
+               openlog("DAQ", LOG_ODELAY, LOG_LOCAL1); /* Centralized logging */
+               printf("progName: %s\n", theArgs->progName);
+               /* Identify the application name */
+               if (strcmp(theArgs->progName, "daq_evtbuild") == 0) {
+                       syslog(LOG_INFO, "%s-%s %s", "EVTBLD", theArgs->shmname, msg);
+               } else if (strcmp(theArgs->progName, "daq_netmem") == 0) {
+                       syslog(LOG_INFO, "%s-%s %s", "NETMEM", theArgs->shmname, msg);
+               } else {
+                       syslog(LOG_INFO, "%s-%s %s", "UNKNOWN", theArgs->shmname, msg);
+               }
+               openlog(theArgs->progName, LOG_PID | LOG_PERROR, LOG_LOCAL0);   /* Restore syslog settings */
+       } else {
+               /* Unknown logging method */
+       }
 }
 
 static int checkDataSources(TheArgs *theArgs, TheStats *theStats)