From bb5f12b2fa4ae4887fb51bfeb60107d751a5636d Mon Sep 17 00:00:00 2001 From: Simon Rose Date: Tue, 24 Feb 2026 14:53:33 +0000 Subject: [PATCH] Add command to show errlog buffer contents --- modules/libcom/src/error/errlog.c | 28 +++++++++++++++++++++++ modules/libcom/src/error/errlog.h | 9 -------- modules/libcom/src/error/errlogPvt.h | 26 +++++++++++++++++++++ modules/libcom/src/iocsh/libComRegister.c | 17 ++++++++++++++ 4 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 modules/libcom/src/error/errlogPvt.h diff --git a/modules/libcom/src/error/errlog.c b/modules/libcom/src/error/errlog.c index b5678fcba..c4362f763 100644 --- a/modules/libcom/src/error/errlog.c +++ b/modules/libcom/src/error/errlog.c @@ -641,6 +641,34 @@ void errlogBufResize(int bufsize, int maxMsgSize) epicsMutexUnlock(pvt.bufSizeLock); } +void errlogShow(int level) +{ + epicsMutexMustLock(pvt.bufSizeLock); + printf("Error log:\n"); + printf(" buffer size: %zu\n", pvt.bufSize); + printf(" max message size: %zu\n", pvt.maxMsgSize); + epicsMutexUnlock(pvt.bufSizeLock); + + if (level > 0) + { + epicsMutexMustLock(pvt.listenerLock); + printf(" number of listeners: %u\n", pvt.listenerList.count); + epicsMutexUnlock(pvt.listenerLock); + } + + if (level > 1) + { + epicsMutexMustLock(pvt.msgQueueLock); + printf(" buffer(log) contents:\n"); + printf("%s\n", pvt.log->base); + printf("%*s^\n", (int)pvt.log->pos, ""); + printf(" buffer(print) contents:\n"); + printf("%s\n", pvt.print->base); + printf("%*s^\n", (int)pvt.print->pos, ""); + epicsMutexUnlock(pvt.msgQueueLock); + } +} + void errlogFlush(void) { /* wait for both buffers to be handled to know that all currently diff --git a/modules/libcom/src/error/errlog.h b/modules/libcom/src/error/errlog.h index aea8437da..a204bec87 100644 --- a/modules/libcom/src/error/errlog.h +++ b/modules/libcom/src/error/errlog.h @@ -224,15 +224,6 @@ LIBCOM_API int errlogInit(int bufsize); */ LIBCOM_API int errlogInit2(int bufsize, int maxMsgSize); -/** - * errlogBufResize can be used to reinitialize the error logging system with a larger buffer and maximum message size. - * The default buffer size is 1280 bytes, and the default maximum message size is 256. - * - * \param bufsize The desired buffer size - * \param maxMsgSize The desired max message size - */ -LIBCOM_API void errlogBufResize(int bufsize, int maxMsgSize); - /** Wakes up the errlog task and then waits until all messages are flushed from the queue. */ LIBCOM_API void errlogFlush(void); diff --git a/modules/libcom/src/error/errlogPvt.h b/modules/libcom/src/error/errlogPvt.h new file mode 100644 index 000000000..c65220769 --- /dev/null +++ b/modules/libcom/src/error/errlogPvt.h @@ -0,0 +1,26 @@ +/*************************************************************************\ +* Copyright (c) 2026 European Spallation Source ERIC +* SPDX-License-Identifier: EPICS +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ + +#ifndef INC_errlogPvt_H +#define INC_errlogPvt_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * errlogShow is used to display the contents of the error log buffers + * + * \param level How much detail to print out + */ +void errlogShow(int level); + +#ifdef __cplusplus +} +#endif + +#endif /*INC_errlogPvt_H*/ diff --git a/modules/libcom/src/iocsh/libComRegister.c b/modules/libcom/src/iocsh/libComRegister.c index 844ee14e2..cbf262608 100644 --- a/modules/libcom/src/iocsh/libComRegister.c +++ b/modules/libcom/src/iocsh/libComRegister.c @@ -22,6 +22,7 @@ #include "osiUnistd.h" #include "logClient.h" #include "errlog.h" +#include "errlogPvt.h" #include "taskwd.h" #include "registry.h" #include "epicsGeneralTime.h" @@ -306,6 +307,21 @@ static void errlogBufResizeCallFunc(const iocshArgBuf *args) errlogBufResize(args[0].ival, args[1].ival); } +/* errlogShow */ +static const iocshArg errlogShowArg0 = { "level",iocshArgInt}; +static const iocshArg * const errlogShowArgs[1] = {&errlogShowArg0}; +static const iocshFuncDef errlogShowFuncDef = { + "errlogShow",1,errlogShowArgs, + "Show the contents of the error log private data\n" + "level 0 - Show the size of the buffers and max message size\n" + " 1 - Show the number of listeners\n" + " 2 - Show the contents of the buffer\n" +}; +static void errlogShowCallFunc(const iocshArgBuf *args) +{ + errlogShow(args[0].ival); +} + /* errlog */ IOCSH_STATIC_FUNC void errlog(const char *message) { @@ -517,6 +533,7 @@ void epicsStdCall libComRegister(void) iocshRegister(&errlogInitFuncDef,errlogInitCallFunc); iocshRegister(&errlogInit2FuncDef,errlogInit2CallFunc); iocshRegister(&errlogBufResizeFuncDef,errlogBufResizeCallFunc); + iocshRegister(&errlogShowFuncDef,errlogShowCallFunc); iocshRegister(&errlogFuncDef, errlogCallFunc); iocshRegister(&iocLogPrefixFuncDef, iocLogPrefixCallFunc);