diff --git a/src/StreamEpics.cc b/src/StreamEpics.cc index b3ebbfe..845f922 100644 --- a/src/StreamEpics.cc +++ b/src/StreamEpics.cc @@ -18,6 +18,7 @@ * * ***************************************************************/ +#include #include "StreamCore.h" #include "StreamError.h" @@ -237,6 +238,24 @@ long streamReload(const char* recordname) return OK; } +long streamSetLogfile(const char* filename) +{ + FILE *oldfile, *newfile = NULL; + if (filename) + { + newfile = fopen(filename, "w"); + if (!newfile) + { + fprintf(stderr, "Opening file %s failed: %s\n", filename, strerror(errno)); + return ERROR; + } + } + oldfile = StreamDebugFile; + StreamDebugFile = newfile; + if (oldfile) fclose(oldfile); + return OK; +} + #ifndef EPICS_3_13 static const iocshArg streamReloadArg0 = { "recordname", iocshArgString }; @@ -262,10 +281,23 @@ void streamReportRecordFunc (const iocshArgBuf *args) streamReportRecord(args[0].sval); } +static const iocshArg streamSetLogfileArg0 = + { "filename", iocshArgString }; +static const iocshArg * const streamSetLogfileArgs[] = + { &streamSetLogfileArg0 }; +static const iocshFuncDef streamSetLogfileDef = + { "streamSetLogfile", 1, streamSetLogfileArgs }; + +void streamSetLogfileFunc (const iocshArgBuf *args) +{ + streamSetLogfile(args[0].sval); +} + static void streamRegistrar () { iocshRegister(&streamReloadDef, streamReloadFunc); iocshRegister(&streamReportRecordDef, streamReportRecordFunc); + iocshRegister(&streamSetLogfileDef, streamSetLogfileFunc); // make streamReload available for subroutine records registryFunctionAdd("streamReload", (REGISTRYFUNCTION)streamReloadSub); @@ -276,6 +308,8 @@ static void streamRegistrar () extern "C" { epicsExportRegistrar(streamRegistrar); } + + #endif // !EPICS_3_13 // driver support //////////////////////////////////////////////////////// diff --git a/streamApp/Makefile b/streamApp/Makefile index 4e790c5..bbf3620 100644 --- a/streamApp/Makefile +++ b/streamApp/Makefile @@ -60,10 +60,6 @@ endif PROD_LIBS += $(EPICS_BASE_IOC_LIBS) -# Write StreamDevice debug output to this file -# If unset output goes to stdout -CPPFLAGS += -DDEBUGFILE=StreamDebug.log - # switch off annoying rset warnings in 3.16+ CPPFLAGS += -DUSE_TYPED_RSET @@ -74,6 +70,6 @@ clean: else clean:: endif - $(RM) core* StreamDebug.log + $(RM) core* *.log endif diff --git a/streamApp/example.cmd b/streamApp/example.cmd index e22d9fc..0544d85 100755 --- a/streamApp/example.cmd +++ b/streamApp/example.cmd @@ -32,6 +32,9 @@ asynOctetSetOutputEos "terminal",0,"\r\n" #load the records dbLoadRecords "example.db","PREFIX=DZ" +#log debug output to file +#streamSetLogfile StreamDebug.log + #lots(!) of debug output before iocInit #var streamDebug 1 diff --git a/streamApp/regexp.cmd b/streamApp/regexp.cmd index 479eccd..99e850f 100755 --- a/streamApp/regexp.cmd +++ b/streamApp/regexp.cmd @@ -8,6 +8,9 @@ drvAsynIPPortConfigure web epics.web.psi.ch:80 0 1 dbLoadRecords regexp.db +#log debug output to file +#streamSetLogfile StreamDebug.log + iocInit #var streamDebug 1 diff --git a/streamApp/simple.cmd b/streamApp/simple.cmd index 7aa4b7a..d5dc6d8 100755 --- a/streamApp/simple.cmd +++ b/streamApp/simple.cmd @@ -14,7 +14,10 @@ drvAsynIPPortConfigure "L0", "localhost:40000" #load the records dbLoadRecords "simple.db","P=DZ,BUS=L0 28" +#log debug output to file +#streamSetLogfile StreamDebug.log + iocInit #enable debug output -var streamDebug 1 +#var streamDebug 1 diff --git a/streamApp/streamAppMain.cc b/streamApp/streamAppMain.cc index 31a74d5..a952e4a 100644 --- a/streamApp/streamAppMain.cc +++ b/streamApp/streamAppMain.cc @@ -19,15 +19,9 @@ #include "epicsThread.h" #include "iocsh.h" -#include "devStream.h" int main(int argc,char *argv[]) { -#ifdef DEBUGFILE -#define STR2(x) #x -#define STR(x) STR2(x) - StreamDebugFile = fopen(STR(DEBUGFILE), "w"); -#endif if(argc>=2) { iocsh(argv[1]); epicsThreadSleep(.2); diff --git a/streamApp/test.cmd b/streamApp/test.cmd index f98f59f..b55000c 100755 --- a/streamApp/test.cmd +++ b/streamApp/test.cmd @@ -8,5 +8,10 @@ epicsEnvSet "STREAM_PROTOCOL_PATH", "." drvAsynIPPortConfigure "terminal", "localhost:40000" dbLoadRecords "test.db","P=TEST" + +#log debug output to file +#streamSetLogfile StreamDebug.log + iocInit + #var streamDebug 1