Skip to content

Commit

Permalink
Add API for turning on/off logging at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
antevir committed Jan 17, 2024
1 parent ade7971 commit 7ddc0fc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
24 changes: 21 additions & 3 deletions inc/u_cx_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>

#include "u_cx_at_config.h"

Expand Down Expand Up @@ -48,12 +49,12 @@

/* Internal defines - do not use! */
#define _U_CX_LOG_BEGIN_FMT(enabled, chText, format, ...) \
if (enabled) { \
if (enabled && uCxLogIsEnabled()) { \
uCxLogPrintTime(); \
U_CX_PORT_PRINTF(chText " " format, ##__VA_ARGS__); \
}
#define _U_CX_LOG(enabled, chText, format, ...) \
if (enabled) { \
if (enabled && uCxLogIsEnabled()) { \
U_CX_PORT_PRINTF(format, ##__VA_ARGS__); \
}

Expand All @@ -71,4 +72,21 @@

void uCxLogPrintTime(void);

#endif // U_CX_LOG_H
/**
* @brief Turn off all logging
*/
void uCxLogDisable(void);

/**
* @brief Turn on logging (default)
*/
void uCxLogEnable(void);

/**
* @brief Check if logging is enabled at runtime
*
* @retval true if logging is enabled
*/
bool uCxLogIsEnabled(void);

#endif // U_CX_LOG_H
1 change: 0 additions & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
- -fno-sanitize-recover
- -fstack-protector-all
- -fno-omit-frame-pointer
- -DU_CX_LOG_AT=0
- -O1 # Set O1 so that GCC correctly detects uninitialized variables: https://stackoverflow.com/questions/17705880/gcc-failing-to-warn-of-uninitialized-variable
- -Wno-clobbered # Needed when enabling -O1 for disabling warning in the CMock runners
:link:
Expand Down
16 changes: 16 additions & 0 deletions src/u_cx_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/* ----------------------------------------------------------------
* STATIC VARIABLES
* -------------------------------------------------------------- */
static bool gUCxLogEnabled = true;

/* ----------------------------------------------------------------
* STATIC FUNCTIONS
Expand All @@ -44,3 +45,18 @@ void uCxLogPrintTime(void)
U_CX_PORT_PRINTF("[%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32"]",
hours, minutes, seconds, ms);
}

void uCxLogDisable(void)
{
gUCxLogEnabled = false;
}

void uCxLogEnable(void)
{
gUCxLogEnabled = true;
}

bool uCxLogIsEnabled(void)
{
return gUCxLogEnabled;
}
1 change: 1 addition & 0 deletions test/test_u_cx_at_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static void uAtClientSendCmdVaList_wrapper(uCxAtClient_t *pClient, const char *p
void setUp(void)
{
uCxLogPrintTime_Ignore();
uCxLogIsEnabled_IgnoreAndReturn(false);
uCxAtClientInit(&gClientConfig, &gClient);
memset(&gTxBuffer[0], 0xc0, sizeof(gTxBuffer));
gTxBufferPos = 0;
Expand Down

0 comments on commit 7ddc0fc

Please sign in to comment.