From: hadaq Date: Tue, 12 Apr 2011 16:34:40 +0000 (+0000) Subject: Centralized logging via syslog. Sergey. X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=ab4d1169c7a2259ab70edd861cce67665995584c;p=daqdata.git Centralized logging via syslog. Sergey. --- diff --git a/hadaq/args.c b/hadaq/args.c index f426a71..c2eedb7 100644 --- a/hadaq/args.c +++ b/hadaq/args.c @@ -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; } diff --git a/hadaq/args.h b/hadaq/args.h index d7f976b..4017b9d 100644 --- a/hadaq/args.h +++ b/hadaq/args.h @@ -8,6 +8,7 @@ #include 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; diff --git a/hadaq/evtbuild.c b/hadaq/evtbuild.c index 623318c..ae54789 100644 --- a/hadaq/evtbuild.c +++ b/hadaq/evtbuild.c @@ -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 |] 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]"); diff --git a/hadaq/logger.c b/hadaq/logger.c index b7e01fe..80956b9 100644 --- a/hadaq/logger.c +++ b/hadaq/logger.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #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) diff --git a/hadaq/netmem.c b/hadaq/netmem.c index 174803f..7b86ae8 100644 --- a/hadaq/netmem.c +++ b/hadaq/netmem.c @@ -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 |] 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)