added a variable 'streamMsgTimeStamped' to enable/disable timestamps on debug & error messages

This commit is contained in:
Yong Hu
2021-04-22 22:10:27 -04:00
committed by Dirk Zimoch
parent fe7f4a5e1b
commit a5eb4618b7
4 changed files with 15 additions and 2 deletions

View File

@ -200,6 +200,7 @@ epicsExportAddress(int, streamDebug);
epicsExportAddress(int, streamError); epicsExportAddress(int, streamError);
epicsExportAddress(int, streamDebugColored); epicsExportAddress(int, streamDebugColored);
epicsExportAddress(int, streamErrorDeadTime); epicsExportAddress(int, streamErrorDeadTime);
epicsExportAddress(int, streamMsgTimeStamped);
} }
// for subroutine record // for subroutine record

View File

@ -35,6 +35,9 @@ int streamDebug = 0;
int streamError = 1; int streamError = 1;
FILE *StreamDebugFile = NULL; FILE *StreamDebugFile = NULL;
/*0: disable timestamps on stream messages (both debug and error)*/
int streamMsgTimeStamped = 1;
#ifndef va_copy #ifndef va_copy
#ifdef __va_copy #ifdef __va_copy
#define va_copy __va_copy #define va_copy __va_copy
@ -115,7 +118,11 @@ void StreamVError(int line, const char* file, const char* fmt, va_list args)
{ {
char timestamp[40]; char timestamp[40];
if (!(streamError || streamDebug)) return; // Error logging disabled if (!(streamError || streamDebug)) return; // Error logging disabled
StreamPrintTimestampFunction(timestamp, 40); strcpy(timestamp, "");
if (streamMsgTimeStamped != 0)
{
StreamPrintTimestampFunction(timestamp, 40);
}
#ifdef va_copy #ifdef va_copy
if (StreamDebugFile) if (StreamDebugFile)
{ {
@ -146,7 +153,10 @@ print(const char* fmt, ...)
const char* f = strrchr(file, '/'); const char* f = strrchr(file, '/');
if (f) f++; else f = file; if (f) f++; else f = file;
FILE* fp = StreamDebugFile ? StreamDebugFile : stderr; FILE* fp = StreamDebugFile ? StreamDebugFile : stderr;
fprintf(fp, "%s ", timestamp); if (streamMsgTimeStamped != 0)
{
fprintf(fp, "%s ", timestamp);
}
fprintf(fp, "%s:%d: ", f, line); fprintf(fp, "%s:%d: ", f, line);
vfprintf(fp, fmt, args); vfprintf(fp, fmt, args);
fflush(fp); fflush(fp);

View File

@ -33,6 +33,7 @@
extern int streamDebug; extern int streamDebug;
extern int streamError; extern int streamError;
extern int streamDebugColored; extern int streamDebugColored;
extern int streamMsgTimeStamped;
extern void (*StreamPrintTimestampFunction)(char* buffer, size_t size); extern void (*StreamPrintTimestampFunction)(char* buffer, size_t size);
void StreamError(int line, const char* file, const char* fmt, ...) void StreamError(int line, const char* file, const char* fmt, ...)

View File

@ -34,6 +34,7 @@ if (@ARGV[0] eq "-3.13") {
print "variable(streamError, int)\n"; print "variable(streamError, int)\n";
print "variable(streamDebugColored, int)\n"; print "variable(streamDebugColored, int)\n";
print "variable(streamErrorDeadTime, int)\n"; print "variable(streamErrorDeadTime, int)\n";
print "variable(streamMsgTimeStamped, int)\n";
print "registrar(streamRegistrar)\n"; print "registrar(streamRegistrar)\n";
if ($asyn) { print "registrar(AsynDriverInterfaceRegistrar)\n"; } if ($asyn) { print "registrar(AsynDriverInterfaceRegistrar)\n"; }
} }