Skip to content

Commit

Permalink
Updated xlog version function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Kalatozishvili committed Aug 26, 2023
1 parent 9ddec45 commit 5d9a8da
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
6 changes: 1 addition & 5 deletions examples/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ int logCallback(const char *pLog, size_t nLength, xlog_flag_t eFlag, void *pCtx)

void greet()
{
/* Get and print XLog version */
char sVersion[128];
XLog_Version(sVersion, sizeof(sVersion), 0);

printf("=========================================\n");
printf("XLog Version: %s\n", sVersion);
printf("XLog Version: %s\n", XLog_Version(XFALSE));
printf("=========================================\n");
}

Expand Down
37 changes: 27 additions & 10 deletions src/sys/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ typedef struct XLogCtx {
} xlog_ctx_t;

static xlog_t g_xlog;
static xbool_t g_bInit = XFALSE;

static XATOMIC g_nHaveXLogVerShort = XFALSE;
static XATOMIC g_nHaveXLogVerLong = XFALSE;
static XATOMIC g_bInit = XFALSE;

static char g_xlogVerShort[128];
static char g_xlogVerLong[256];

static const char *XLog_GetIndent(xlog_flag_t eFlag)
{
Expand Down Expand Up @@ -353,19 +359,30 @@ void* XLog_ThrowPtr(void* pRetVal, const char *pFmt, ...)
return pRetVal;
}

size_t XLog_Version(char *pDest, size_t nSize, int nMin)
const char* XLog_Version(xbool_t bShort)
{
size_t nLength = 0;
if (bShort)
{
if (!g_nHaveXLogVerShort)
{
xstrncpyf(g_xlogVerShort, sizeof(g_xlogVerShort), "%d.%d.%d",
XLOG_VERSION_MAJOR, XLOG_VERSION_MINOR, SLOG_BUILD_NUMBER);

g_nHaveXLogVerShort = XTRUE;
}

return g_xlogVerShort;
}

/* Version short */
if (nMin) nLength = xstrncpyf(pDest, nSize, "%d.%d.%d",
XLOG_VERSION_MAJOR, XLOG_VERSION_MINOR, XLOG_BUILD_NUM);
if (!g_nHaveXLogVerLong)
{
xstrncpyf(g_xlogVerLong, sizeof(g_xlogVerLong), "%d.%d build %d (%s)",
XLOG_VERSION_MAJOR, XLOG_VERSION_MINOR, SLOG_BUILD_NUMBER, __DATE__);

/* Version long */
else nLength = xstrncpyf(pDest, nSize, "%d.%d build %d (%s)",
XLOG_VERSION_MAJOR, XLOG_VERSION_MINOR, XLOG_BUILD_NUM, __DATE__);
g_nHaveXLogVerLong = XTRUE;
}

return nLength;
return g_xlogVerLong;
}

void XLog_ConfigGet(struct XLogConfig *pCfg)
Expand Down
5 changes: 2 additions & 3 deletions src/sys/xlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {
/* Definations for version info */
#define XLOG_VERSION_MAJOR 1
#define XLOG_VERSION_MINOR 8
#define XLOG_BUILD_NUM 27
#define SLOG_BUILD_NUMBER 28

#define XLOG_NAME_DEFAULT "xlog"

Expand All @@ -46,7 +46,6 @@ extern "C" {

/* SLog limits (To be safe while avoiding dynamic allocations) */
#define XLOG_MESSAGE_MAX 8196
#define XLOG_VERSION_MAX 128
#define XLOG_PATH_MAX 2048
#define XLOG_INFO_MAX 512
#define XLOG_NAME_MAX 256
Expand Down Expand Up @@ -200,7 +199,7 @@ typedef struct XLogConfig {
char sSeparator[XLOG_NAME_MAX];
} xlog_cfg_t;

size_t XLog_Version(char *pDest, size_t nSize, int nMin);
const char* XLog_Version(xbool_t bShort);
void XLog_ConfigGet(struct XLogConfig *pCfg);
void XLog_ConfigSet(struct XLogConfig *pCfg);

Expand Down
2 changes: 1 addition & 1 deletion src/xver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define XUTILS_VERSION_MAX 2
#define XUTILS_VERSION_MIN 5
#define XUTILS_BUILD_NUMBER 45
#define XUTILS_BUILD_NUMBER 46

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit 5d9a8da

Please sign in to comment.