suppress extra console message from logMsg
This commit is contained in:
@@ -56,9 +56,9 @@ epicsShareDef int errVerbose=0;
|
||||
|
||||
LOCAL void errlogThread(void);
|
||||
|
||||
LOCAL char *msgbufGetFree(void);
|
||||
LOCAL char *msgbufGetFree(int noConsoleMessage);
|
||||
LOCAL void msgbufSetSize(int size);
|
||||
LOCAL char * msgbufGetSend(void);
|
||||
LOCAL char * msgbufGetSend(int *noConsoleMessage);
|
||||
LOCAL void msgbufFreeSend(void);
|
||||
|
||||
LOCAL void *pvtCalloc(size_t count,size_t size);
|
||||
@@ -74,6 +74,7 @@ typedef struct msgNode {
|
||||
ELLNODE node;
|
||||
char *message;
|
||||
int length;
|
||||
int noConsoleMessage;
|
||||
} msgNode;
|
||||
|
||||
LOCAL struct {
|
||||
@@ -123,7 +124,7 @@ epicsShareFunc int errlogVprintf(
|
||||
return 0;
|
||||
}
|
||||
errlogInit(0);
|
||||
pbuffer = msgbufGetFree();
|
||||
pbuffer = msgbufGetFree(0);
|
||||
if(!pbuffer) return(0);
|
||||
nchar = vsprintf(pbuffer,pFormat,pvar);
|
||||
msgbufSetSize(nchar+1);/*include the \0*/
|
||||
@@ -140,12 +141,48 @@ epicsShareFunc int epicsShareAPI errlogMessage(const char *message)
|
||||
return 0;
|
||||
}
|
||||
errlogInit(0);
|
||||
pbuffer = msgbufGetFree();
|
||||
pbuffer = msgbufGetFree(0);
|
||||
if(!pbuffer) return(0);
|
||||
strcpy(pbuffer,message);
|
||||
msgbufSetSize(strlen(message) +1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
epicsShareFunc int errlogPrintfNoConsole( const char *pFormat, ...)
|
||||
{
|
||||
va_list pvar;
|
||||
int nchar;
|
||||
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage
|
||||
("errlogPrintf called from interrupt level\n");
|
||||
return 0;
|
||||
}
|
||||
errlogInit(0);
|
||||
va_start(pvar, pFormat);
|
||||
nchar = errlogVprintfNoConsole(pFormat,pvar);
|
||||
va_end (pvar);
|
||||
return(nchar);
|
||||
}
|
||||
|
||||
epicsShareFunc int errlogVprintfNoConsole(
|
||||
const char *pFormat,va_list pvar)
|
||||
{
|
||||
int nchar;
|
||||
char *pbuffer;
|
||||
|
||||
if(epicsInterruptIsInterruptContext()) {
|
||||
epicsInterruptContextMessage
|
||||
("errlogVprintf called from interrupt level\n");
|
||||
return 0;
|
||||
}
|
||||
errlogInit(0);
|
||||
pbuffer = msgbufGetFree(1);
|
||||
if(!pbuffer) return(0);
|
||||
nchar = vsprintf(pbuffer,pFormat,pvar);
|
||||
msgbufSetSize(nchar+1);/*include the \0*/
|
||||
return nchar;
|
||||
}
|
||||
|
||||
epicsShareFunc int errlogSevPrintf(
|
||||
const errlogSevEnum severity,const char *pFormat, ...)
|
||||
@@ -180,7 +217,7 @@ epicsShareFunc int errlogSevVprintf(
|
||||
return 0;
|
||||
}
|
||||
errlogInit(0);
|
||||
pnext = msgbufGetFree();
|
||||
pnext = msgbufGetFree(0);
|
||||
if(!pnext) return(0);
|
||||
nchar = sprintf(pnext,"sevr=%s ",errlogGetSevEnumString(severity));
|
||||
pnext += nchar; totalChar += nchar;
|
||||
@@ -269,7 +306,7 @@ epicsShareFunc void errPrintf(long status, const char *pFileName,
|
||||
return;
|
||||
}
|
||||
errlogInit(0);
|
||||
pnext = msgbufGetFree();
|
||||
pnext = msgbufGetFree(0);
|
||||
if(!pnext) return;
|
||||
if(pFileName){
|
||||
nchar = sprintf(pnext,"filename=\"%s\" line number=%d\n",
|
||||
@@ -359,14 +396,15 @@ epicsShareFunc void epicsShareAPI errlogFlush(void)
|
||||
LOCAL void errlogThread(void)
|
||||
{
|
||||
listenerNode *plistenerNode;
|
||||
int noConsoleMessage;
|
||||
|
||||
while(TRUE) {
|
||||
char *pmessage;
|
||||
|
||||
epicsEventMustWait(pvtData.waitForWork);
|
||||
while((pmessage = msgbufGetSend())) {
|
||||
while((pmessage = msgbufGetSend(&noConsoleMessage))) {
|
||||
epicsMutexMustLock(pvtData.listenerLock);
|
||||
if(pvtData.toConsole) printf("%s",pmessage);
|
||||
if(pvtData.toConsole && !noConsoleMessage) printf("%s",pmessage);
|
||||
plistenerNode = (listenerNode *)ellFirst(&pvtData.listenerList);
|
||||
while(plistenerNode) {
|
||||
(*plistenerNode->listener)(plistenerNode->pPrivate, pmessage);
|
||||
@@ -413,7 +451,7 @@ LOCAL msgNode *msgbufGetNode()
|
||||
return(pnextSend);
|
||||
}
|
||||
|
||||
LOCAL char *msgbufGetFree()
|
||||
LOCAL char *msgbufGetFree(int noConsoleMessage)
|
||||
{
|
||||
msgNode *pnextSend;
|
||||
|
||||
@@ -429,7 +467,11 @@ LOCAL char *msgbufGetFree()
|
||||
ellAdd(&pvtData.msgQueue,&pnextSend->node);
|
||||
}
|
||||
pvtData.pnextSend = pnextSend = msgbufGetNode();
|
||||
if(pnextSend) return(pnextSend->message);
|
||||
if(pnextSend) {
|
||||
pnextSend->noConsoleMessage = noConsoleMessage;
|
||||
pnextSend->length = 0;
|
||||
return(pnextSend->message);
|
||||
}
|
||||
++pvtData.missedMessages;
|
||||
epicsMutexUnlock(pvtData.msgQueueLock);
|
||||
return(0);
|
||||
@@ -471,7 +513,7 @@ LOCAL void msgbufSetSize(int size)
|
||||
/*Thus errlogThread is the ONLY task that removes messages from msgQueue */
|
||||
/*This is why each can lock and unlock msgQueue */
|
||||
/*This is necessary to prevent other tasks from waiting for errlogThread */
|
||||
LOCAL char * msgbufGetSend()
|
||||
LOCAL char * msgbufGetSend(int *noConsoleMessage)
|
||||
{
|
||||
msgNode *pnextSend;
|
||||
|
||||
@@ -479,6 +521,7 @@ LOCAL char * msgbufGetSend()
|
||||
pnextSend = (msgNode *)ellFirst(&pvtData.msgQueue);
|
||||
epicsMutexUnlock(pvtData.msgQueueLock);
|
||||
if(!pnextSend) return(0);
|
||||
*noConsoleMessage = pnextSend->noConsoleMessage;
|
||||
return(pnextSend->message);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,14 @@ epicsShareFunc void errPrintf(long status, const char *pFileName,
|
||||
|
||||
epicsShareExtern int errVerbose;
|
||||
|
||||
/* The following are added so that logMsg on vxWorks does not cause
|
||||
* the message to appear twice on the console
|
||||
*/
|
||||
epicsShareFunc int errlogPrintfNoConsole(
|
||||
const char *pformat, ...);
|
||||
epicsShareFunc int errlogVprintfNoConsole(
|
||||
const char *pformat,va_list pvar);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -46,7 +46,7 @@ static int errlogOpen ( DEV_HDR *, const char *, int )
|
||||
|
||||
static int errlogWrite ( DEV_HDR *, const char * pInBuf, int nbytes )
|
||||
{
|
||||
errlogPrintf ( "%.*s", nbytes, pInBuf );
|
||||
errlogPrintfNoConsole ( "%.*s", nbytes, pInBuf );
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user