inserted logger

This commit is contained in:
zolliker
2005-09-02 12:50:33 +00:00
parent 87b4c5bf68
commit 170b24bb44
4 changed files with 54 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ tasp@tasp:tecs/ dmc@dmc:tecs/ hrpt@hrpt:tecs/ \
morpheus@morpheus:tecs/ sans@sans:tecs/ sans2@sans2:tecs/ \
type@darwin \
macosx=/afs/psi.ch/project/sinq/mac_os/stow/tecs/bin/ \
admin@ldmprep1:bin/ admin@ldmprep2:bin/ \
)
set dests=""

View File

@@ -10,7 +10,7 @@
LIBR_OBJ =coc_util.o myc_err.o myc_str.o myc_buf.o myc_time.o
SERV_OBJ =tecs.o coc_server.o tecs_lsc.o tecs_serial.o coc_logfile.o \
tecs_data.o $(LIBR_OBJ)
tecs_data.o tecs_logger.o $(LIBR_OBJ)
CLI_OBJ =tecs_cli.o coc_client.o $(LIBR_OBJ)
TCLI_OBJ =sys_getenv.o sys_env.o myc_tmp.o sys_cmdpar.o \
sys_date.o sys_wait.o sys_lun.o sys_rdline.o \

View File

@@ -5,6 +5,9 @@
#include <signal.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "myc_mem.h"
#include "myc_err.h"
#include "coc_util.h"
@@ -14,6 +17,7 @@
#include "myc_time.h"
#include "tecs_lsc.h"
#include "tecs_data.h"
#include "logger.h"
/* --- non ANSI signal --- */
#ifndef SIGPIPE
@@ -28,6 +32,7 @@
static SerChannel *ser=NULL;
static char binDir[256]="";
static char logDir[256]="";
static char loggerDir[256]="";
static int logIt=0, use_stdout=0;
static char serverId[32]="tecs";
static int msecTmo=5000;
@@ -170,7 +175,7 @@ static int
lockAlarm,
cntError;
int tim, rdTim; /* actual time, read Time */
static int tim, rdTim; /* actual time, read Time */
static int decod[8]={21,20,17,16,5,4,1,0}; /* for code conversion */
@@ -2777,7 +2782,6 @@ int LogfileHdl(int mode, void *base, int fd) {
return 0;
}
int ExecuteRequest(void) {
if (readTemp) ERR_I(ReadTemp());
ERR_I(CocCallHandlers());
@@ -3003,6 +3007,7 @@ int main(int argc, char *argv[]) {
CocDefStr(serverId, RW); CocHdl(LogfileHdl);
CocDefInt(logIt, RW); CocHdl(LogfileHdl);
CocDefStr(logDir, RW); CocHdl(LogfileHdl);
CocDefStr(loggerDir, RW);
CocDefStr(binDir, RW);
logfileOut(LOG_MAIN ,"%s ", argv[0]);
@@ -3029,6 +3034,9 @@ int main(int argc, char *argv[]) {
} else if ('d'==opt) {
i++;
str_copy(logDir, argv[i]);
} else if ('m'==opt) {
i++;
str_copy(loggerDir, argv[i]);
} else if ('t'==opt) {
i++;
msecTmo=atoi(argv[i]);
@@ -3064,9 +3072,36 @@ int main(int argc, char *argv[]) {
str_copy(statusBuf, "starting up");
logfileStatusBuf(statusBuf);
str_copy(buf, logDir);
str_append(buf, serverId);
if (logDir[0] == '/') {
str_copy(buf, logDir);
} else {
getcwd(buf, sizeof buf);
str_append(buf, "/");
ERR_I(str_append(buf, logDir));
}
ERR_I(str_append(buf, serverId));
if (strcmp(serverId, "tecs") != 0) {
ERR_I(str_append(buf, "/tecs"));
}
logfile=logfileInit(buf, logIt, use_stdout, logIt && use_stdout);
if (loggerDir[0] != '\0') {
if (loggerDir[0] == '/') {
str_copy(buf, loggerDir);
} else {
getcwd(buf, sizeof buf);
str_append(buf, "/");
ERR_I(str_append(buf, loggerDir));
}
if (strcmp(serverId, "tecs") != 0) {
ERR_I(str_append(buf, serverId));
mkdir(buf, S_IRWXU+S_IRGRP+S_IXGRP+S_IROTH+S_IXOTH);
/* do not check return value */
}
str_copy(loggerDir, buf);
LoggerSetDir(loggerDir);
}
CocDefStr(logfile, RD);
logfileOut(LOG_MAIN ,"\n");
logfileWrite(logMask);

View File

@@ -8,6 +8,7 @@
#include "myc_time.h"
#include "coc_logfile.h"
#include "tecs_data.h"
#include "logger.h"
#define RUN_SIZE 1024
#define SET_LEN 1024
@@ -34,6 +35,7 @@ typedef struct _Set {
float *var;
Run *runs;
Summary sum;
Logger *log;
} Set;
typedef struct {
@@ -125,6 +127,7 @@ Set *CreateSet(Base *base, char *name, float *var, int step, int lifetime, int s
s->start = start;
s->step = step;
s->var = var;
s->log = LoggerMake(name, step, 0);
ResetSum(&s->sum);
return s;
OnError:
@@ -267,6 +270,7 @@ int DataPut(DataSet *set, int time, float value) {
int DataPutAll(DataBase *base, int time) {
Set *s;
char value[32];
if (base == NULL) {
s=database.head;
@@ -276,6 +280,14 @@ int DataPutAll(DataBase *base, int time) {
while (s!=NULL) {
if (s->var!=NULL) {
ERR_I(Put(s, time, *s->var));
if (s->log != NULL) {
if (*s->var == DATA_UNDEF) {
value[0]='\0';
} else {
snprintf(value, sizeof value, "%.5g", *s->var);
}
LoggerWrite(s->log, mycUnixTime(time), s->step, value);
}
}
s=s->next;
}