{
int i;
+ strcpy(my->progName, "daq");
+
my->nrOfMsgs = 0;
for (i = 0; i < PARAM_MAX_ARRAY_LEN; i++) {
my->slowCtrlFiles[i] = my->slowCtrlFilesS[i];
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[])
{"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;
case 'g':
my->maxTrigMismatch = strtoul(optarg, NULL, 0);
break;
+ case 'Y':
+ strcpy(my->log, optarg);
+ break;
case 'H':
return -1;
break;
sprintf(my->logname, "%s%s_log.txt", getenv("DAQ_SETUP"), my->shmname);
+ strcpy(my->progName, (char *) basename(argv[0]));
+
return 0;
}
#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];
unsigned long maxTrigMismatch;
char hostname[PARAM_MAX_VALUE_LEN];
+ char log[PARAM_MAX_VALUE_LEN];
} TheArgs;
-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
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]");
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <syslog.h>
+#include <unistd.h>
#include "logger.h"
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)
-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
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;
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)
/* Get host name */
gethostname(my->hostname, 30);
+
+ strcpy(my->progName, "daq");
+ strcpy(my->log, "syslog");
}
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);
case 'd':
my->dataDelay = atoi(optarg);
break;
+ case 'Y':
+ strcpy(my->log, optarg);
+ break;
default:
return -1;
break;
}
}
+ strcpy(my->progName, (char *) basename(argv[0]));
+
return 0;
}
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)