1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-06-16 23:47:38 +02:00

Simplify debug logging by allowing log functions to return String objects.

Previously, debug log functions had to handle NULLs and truncate output to the available buffer size.  This was verbose for both coding and testing.

Instead, create a function/macro combination that allows log functions to return a simple String object.  The wrapper function takes care of the memory context, handles NULLs, and truncates the log string based on the available buffer size.
This commit is contained in:
David Steele
2018-09-11 18:32:56 -04:00
parent 9b9396c7b7
commit 5aa458ffae
34 changed files with 139 additions and 327 deletions

View File

@ -79,6 +79,10 @@
<release-item> <release-item>
<p>Change locking around async process forking to be more test friendly.</p> <p>Change locking around async process forking to be more test friendly.</p>
</release-item> </release-item>
<release-item>
<p>Simplify debug logging by allowing log functions to return <code>String</code> objects.</p>
</release-item>
</release-development-list> </release-development-list>
</release-core-list> </release-core-list>

View File

@ -126,25 +126,10 @@ ioBufferFilter(const IoBuffer *this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
ioBufferToLog(const IoBuffer *this, char *buffer, size_t bufferSize) ioBufferToLog(const IoBuffer *this)
{ {
size_t result = 0; return strNewFmt("{inputSame: %s, inputPos: %zu}", cvtBoolToConstZ(this->inputSame), this->inputPos);
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{inputSame: %s, inputPos: %zu}", cvtBoolToConstZ(this->inputSame), this->inputPos);
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -39,11 +39,11 @@ void ioBufferFree(IoBuffer *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t ioBufferToLog(const IoBuffer *this, char *buffer, size_t bufferSize); String *ioBufferToLog(const IoBuffer *this);
#define FUNCTION_DEBUG_IO_BUFFER_TYPE \ #define FUNCTION_DEBUG_IO_BUFFER_TYPE \
IoBuffer * IoBuffer *
#define FUNCTION_DEBUG_IO_BUFFER_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_IO_BUFFER_FORMAT(value, buffer, bufferSize) \
ioBufferToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, ioBufferToLog, buffer, bufferSize)
#endif #endif

View File

@ -404,25 +404,10 @@ ioFilterGroupResult(const IoFilterGroup *this, const String *filterType)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
ioFilterGroupToLog(const IoFilterGroup *this, char *buffer, size_t bufferSize) ioFilterGroupToLog(const IoFilterGroup *this)
{ {
size_t result = 0; return strNewFmt("{inputSame: %s, done: %s}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done));
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{inputSame: %s, done: %s}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done));
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -46,11 +46,11 @@ void ioFilterGroupFree(IoFilterGroup *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t ioFilterGroupToLog(const IoFilterGroup *this, char *buffer, size_t bufferSize); String *ioFilterGroupToLog(const IoFilterGroup *this);
#define FUNCTION_DEBUG_IO_FILTER_GROUP_TYPE \ #define FUNCTION_DEBUG_IO_FILTER_GROUP_TYPE \
IoFilterGroup * IoFilterGroup *
#define FUNCTION_DEBUG_IO_FILTER_GROUP_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_IO_FILTER_GROUP_FORMAT(value, buffer, bufferSize) \
ioFilterGroupToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, ioFilterGroupToLog, buffer, bufferSize)
#endif #endif

View File

@ -84,25 +84,10 @@ ioSizeFilter(const IoSize *this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
ioSizeToLog(const IoSize *this, char *buffer, size_t bufferSize) ioSizeToLog(const IoSize *this)
{ {
size_t result = 0; return strNewFmt("{size: %" PRIu64 "}", this->size);
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{size: %" PRIu64 "}", this->size);
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -39,11 +39,11 @@ void ioSizeFree(IoSize *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t ioSizeToLog(const IoSize *this, char *buffer, size_t bufferSize); String *ioSizeToLog(const IoSize *this);
#define FUNCTION_DEBUG_IO_SIZE_TYPE \ #define FUNCTION_DEBUG_IO_SIZE_TYPE \
IoSize * IoSize *
#define FUNCTION_DEBUG_IO_SIZE_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_IO_SIZE_FORMAT(value, buffer, bufferSize) \
ioSizeToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, ioSizeToLog, buffer, bufferSize)
#endif #endif

View File

@ -401,25 +401,10 @@ bufUsedZero(Buffer *this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
bufToLog(const Buffer *this, char *buffer, size_t bufferSize) bufToLog(const Buffer *this)
{ {
size_t result = 0; return strNewFmt("{used: %zu, size: %zu}", this->used, this->size);
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{used: %zu, size: %zu}", this->used, this->size);
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -41,11 +41,11 @@ void bufFree(Buffer *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t bufToLog(const Buffer *this, char *buffer, size_t bufferSize); String *bufToLog(const Buffer *this);
#define FUNCTION_DEBUG_BUFFER_TYPE \ #define FUNCTION_DEBUG_BUFFER_TYPE \
Buffer * Buffer *
#define FUNCTION_DEBUG_BUFFER_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_BUFFER_FORMAT(value, buffer, bufferSize) \
bufToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, bufToLog, buffer, bufferSize)
#endif #endif

View File

@ -176,25 +176,10 @@ lstSort(List *this, int (*comparator)(const void *, const void*))
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
lstToLog(const List *this, char *buffer, size_t bufferSize) lstToLog(const List *this)
{ {
size_t result = 0; return strNewFmt("{size: %u}", this->listSize);
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{size: %u}", this->listSize);
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -32,11 +32,11 @@ void lstFree(List *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t lstToLog(const List *this, char *buffer, size_t bufferSize); String *lstToLog(const List *this);
#define FUNCTION_DEBUG_LIST_TYPE \ #define FUNCTION_DEBUG_LIST_TYPE \
List * List *
#define FUNCTION_DEBUG_LIST_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_LIST_FORMAT(value, buffer, bufferSize) \
lstToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, lstToLog, buffer, bufferSize)
#endif #endif

View File

@ -708,10 +708,9 @@ strTrunc(String *this, int idx)
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert an object to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t size_t strObjToLog(const void *object, StrObjToLogFormat formatFunc, char *buffer, size_t bufferSize)
strToLog(const String *this, char *buffer, size_t bufferSize)
{ {
size_t result = 0; size_t result = 0;
@ -719,10 +718,10 @@ strToLog(const String *this, char *buffer, size_t bufferSize)
{ {
String *string = NULL; String *string = NULL;
if (this == NULL) if (object == NULL)
string = strNew("null"); string = strNew("null");
else else
string = strNewFmt("{\"%s\"}", strPtr(this)); string = formatFunc(object);
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string)); result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
} }
@ -731,6 +730,15 @@ strToLog(const String *this, char *buffer, size_t bufferSize)
return result; return result;
} }
/***********************************************************************************************************************************
Convert to a zero-terminated string for logging
***********************************************************************************************************************************/
String *
strToLog(const String *this)
{
return strNewFmt("{\"%s\"}", strPtr(this));
}
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Free the string Free the string
***********************************************************************************************************************************/ ***********************************************************************************************************************************/

View File

@ -49,10 +49,20 @@ String *strTrunc(String *this, int idx);
void strFree(String *this); void strFree(String *this);
/***********************************************************************************************************************************
Helper function/macro for object logging
***********************************************************************************************************************************/
typedef String *(*StrObjToLogFormat)(const void *object);
size_t strObjToLog(const void *object, StrObjToLogFormat formatFunc, char *buffer, size_t bufferSize);
#define FUNCTION_DEBUG_STRING_OBJECT_FORMAT(object, formatFunc, buffer, bufferSize) \
strObjToLog(object, (StrObjToLogFormat)formatFunc, buffer, bufferSize)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t strToLog(const String *this, char *buffer, size_t bufferSize); String *strToLog(const String *this);
#define FUNCTION_DEBUG_CONST_STRING_TYPE \ #define FUNCTION_DEBUG_CONST_STRING_TYPE \
const String * const String *
@ -62,7 +72,7 @@ size_t strToLog(const String *this, char *buffer, size_t bufferSize);
#define FUNCTION_DEBUG_STRING_TYPE \ #define FUNCTION_DEBUG_STRING_TYPE \
String * String *
#define FUNCTION_DEBUG_STRING_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_STRING_FORMAT(value, buffer, bufferSize) \
strToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, strToLog, buffer, bufferSize)
#define FUNCTION_DEBUG_STRINGP_TYPE \ #define FUNCTION_DEBUG_STRINGP_TYPE \
const String ** const String **

View File

@ -520,25 +520,10 @@ strLstSort(StringList *this, SortOrder sortOrder)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
strLstToLog(const StringList *this, char *buffer, size_t bufferSize) strLstToLog(const StringList *this)
{ {
size_t result = 0; return strNewFmt("{[%s]}", strPtr(strLstJoinQuote(this, ", ", "\"")));
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{[%s]}", strPtr(strLstJoinQuote(this, ", ", "\"")));
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -50,11 +50,11 @@ void strLstFree(StringList *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t strLstToLog(const StringList *this, char *buffer, size_t bufferSize); String *strLstToLog(const StringList *this);
#define FUNCTION_DEBUG_STRING_LIST_TYPE \ #define FUNCTION_DEBUG_STRING_LIST_TYPE \
StringList * StringList *
#define FUNCTION_DEBUG_STRING_LIST_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_STRING_LIST_FORMAT(value, buffer, bufferSize) \
strLstToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, strLstToLog, buffer, bufferSize)
#endif #endif

View File

@ -926,29 +926,16 @@ varVarLst(const Variant *this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert variant to a zero-terminated string for logging Convert variant to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
varToLog(const Variant *this, char *buffer, size_t bufferSize) varToLog(const Variant *this)
{ {
size_t result = 0;
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL; String *string = NULL;
if (this == NULL)
{
string = strNew("null");
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
else
{
switch (varType(this)) switch (varType(this))
{ {
case varTypeString: case varTypeString:
{ {
String *temp = varStrForce(this); string = strNewFmt("\"%s\"", strPtr(varStrForce(this)));
string = strNewFmt("\"%s\"", strPtr(temp));
strFree(temp);
break; break;
} }
@ -975,12 +962,7 @@ varToLog(const Variant *this, char *buffer, size_t bufferSize)
} }
} }
result = (size_t)snprintf(buffer, bufferSize, "{%s}", strPtr(string)); return strNewFmt("{%s}", strPtr(string));
}
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -73,7 +73,7 @@ void varFree(Variant *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t varToLog(const Variant *this, char *buffer, size_t bufferSize); String *varToLog(const Variant *this);
#define FUNCTION_DEBUG_CONST_VARIANT_TYPE \ #define FUNCTION_DEBUG_CONST_VARIANT_TYPE \
const FUNCTION_DEBUG_VARIANT_TYPE const FUNCTION_DEBUG_VARIANT_TYPE
@ -83,6 +83,6 @@ size_t varToLog(const Variant *this, char *buffer, size_t bufferSize);
#define FUNCTION_DEBUG_VARIANT_TYPE \ #define FUNCTION_DEBUG_VARIANT_TYPE \
Variant * Variant *
#define FUNCTION_DEBUG_VARIANT_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_VARIANT_FORMAT(value, buffer, bufferSize) \
varToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, varToLog, buffer, bufferSize)
#endif #endif

View File

@ -177,29 +177,12 @@ gzipCompressInputSame(const GzipCompress *this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
gzipCompressToLog(const GzipCompress *this, char *buffer, size_t bufferSize) gzipCompressToLog(const GzipCompress *this)
{ {
size_t result = 0; return strNewFmt(
"{inputSame: %s, done: %s, flushing: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
MEM_CONTEXT_TEMP_BEGIN() cvtBoolToConstZ(this->done), this->stream != NULL ? this->stream->avail_in : 0);
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
{
string = strNewFmt(
"{inputSame: %s, done: %s, flushing: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame),
cvtBoolToConstZ(this->done), cvtBoolToConstZ(this->done), this->stream != NULL ? this->stream->avail_in : 0);
}
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -39,11 +39,11 @@ void gzipCompressFree(GzipCompress *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t gzipCompressToLog(const GzipCompress *this, char *buffer, size_t bufferSize); String *gzipCompressToLog(const GzipCompress *this);
#define FUNCTION_DEBUG_GZIP_COMPRESS_TYPE \ #define FUNCTION_DEBUG_GZIP_COMPRESS_TYPE \
GzipCompress * GzipCompress *
#define FUNCTION_DEBUG_GZIP_COMPRESS_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_GZIP_COMPRESS_FORMAT(value, buffer, bufferSize) \
gzipCompressToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, gzipCompressToLog, buffer, bufferSize)
#endif #endif

View File

@ -152,29 +152,12 @@ gzipDecompressInputSame(const GzipDecompress *this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
gzipDecompressToLog(const GzipDecompress *this, char *buffer, size_t bufferSize) gzipDecompressToLog(const GzipDecompress *this)
{ {
size_t result = 0; return strNewFmt(
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
{
string = strNewFmt(
"{inputSame: %s, done: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done), "{inputSame: %s, done: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
this->stream != NULL ? this->stream->avail_in : 0); this->stream != NULL ? this->stream->avail_in : 0);
}
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -39,11 +39,11 @@ void gzipDecompressFree(GzipDecompress *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t gzipDecompressToLog(const GzipDecompress *this, char *buffer, size_t bufferSize); String *gzipDecompressToLog(const GzipDecompress *this);
#define FUNCTION_DEBUG_GZIP_DECOMPRESS_TYPE \ #define FUNCTION_DEBUG_GZIP_DECOMPRESS_TYPE \
GzipDecompress * GzipDecompress *
#define FUNCTION_DEBUG_GZIP_DECOMPRESS_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_GZIP_DECOMPRESS_FORMAT(value, buffer, bufferSize) \
gzipDecompressToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, gzipDecompressToLog, buffer, bufferSize)
#endif #endif

View File

@ -216,26 +216,12 @@ infoPgDataTotal(const InfoPg *this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
infoPgDataToLog(const InfoPgData *this, char *buffer, size_t bufferSize) infoPgDataToLog(const InfoPgData *this)
{ {
size_t result = 0; return strNewFmt(
"{id: %u, version: %u, systemId: %" PRIu64 ", catalogVersion: %" PRIu32 ", controlVersion: %" PRIu32 "}",
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{\"id: %u, version: %u, systemId %" PRIu64 ", catalog %"PRIu32", control %"PRIu32"\"}",
this->id, this->version, this->systemId, this->catalogVersion, this->controlVersion); this->id, this->version, this->systemId, this->catalogVersion, this->controlVersion);
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -62,7 +62,7 @@ void infoPgFree(InfoPg *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t infoPgDataToLog(const InfoPgData *this, char *buffer, size_t bufferSize); String *infoPgDataToLog(const InfoPgData *this);
#define FUNCTION_DEBUG_INFO_PG_TYPE \ #define FUNCTION_DEBUG_INFO_PG_TYPE \
InfoPg * InfoPg *
@ -71,11 +71,11 @@ size_t infoPgDataToLog(const InfoPgData *this, char *buffer, size_t bufferSize);
#define FUNCTION_DEBUG_INFO_PG_DATA_TYPE \ #define FUNCTION_DEBUG_INFO_PG_DATA_TYPE \
InfoPgData InfoPgData
#define FUNCTION_DEBUG_INFO_PG_DATA_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_INFO_PG_DATA_FORMAT(value, buffer, bufferSize) \
infoPgDataToLog(&value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(&value, infoPgDataToLog, buffer, bufferSize)
#define FUNCTION_DEBUG_INFO_PG_DATAP_TYPE \ #define FUNCTION_DEBUG_INFO_PG_DATAP_TYPE \
InfoPgData * InfoPgData *
#define FUNCTION_DEBUG_INFO_PG_DATAP_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_INFO_PG_DATAP_FORMAT(value, buffer, bufferSize) \
infoPgDataToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, infoPgDataToLog, buffer, bufferSize)
#endif #endif

View File

@ -620,25 +620,10 @@ storageRemove(const Storage *this, const String *fileExp, StorageRemoveParam par
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Convert to a zero-terminated string for logging Convert to a zero-terminated string for logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t String *
storageToLog(const Storage *this, char *buffer, size_t bufferSize) storageToLog(const Storage *this)
{ {
size_t result = 0; return strNewFmt("{path: %s, write: %s}", strPtr(strQuoteZ(this->path, "\"")), cvtBoolToConstZ(this->write));
MEM_CONTEXT_TEMP_BEGIN()
{
String *string = NULL;
if (this == NULL)
string = strNew("null");
else
string = strNewFmt("{path: %s, write: %s}", strPtr(strQuoteZ(this->path, "\"")), cvtBoolToConstZ(this->write));
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
}
MEM_CONTEXT_TEMP_END();
return result;
} }
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -251,11 +251,11 @@ void storageFree(const Storage *this);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
size_t storageToLog(const Storage *this, char *buffer, size_t bufferSize); String *storageToLog(const Storage *this);
#define FUNCTION_DEBUG_STORAGE_TYPE \ #define FUNCTION_DEBUG_STORAGE_TYPE \
Storage * Storage *
#define FUNCTION_DEBUG_STORAGE_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_DEBUG_STORAGE_FORMAT(value, buffer, bufferSize) \
(size_t)storageToLog(value, buffer, bufferSize) FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, storageToLog, buffer, bufferSize)
#endif #endif

View File

@ -166,7 +166,7 @@ unit:
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: type-buffer - name: type-buffer
total: 4 total: 5
coverage: coverage:
common/type/buffer: full common/type/buffer: full

View File

@ -137,7 +137,7 @@ P00 DEBUG: info/info::infoNew: (fileName: {"<REPO:ARCHIVE>/archive.info"})
P00 DEBUG: info/info::infoNew: => {Info} P00 DEBUG: info/info::infoNew: => {Info}
P00 DEBUG: info/info::infoIni: (this: {Info}) P00 DEBUG: info/info::infoIni: (this: {Info})
P00 DEBUG: info/info::infoIni: => {Ini} P00 DEBUG: info/info::infoIni: => {Ini}
P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {"id: 1, version: 90400, systemId 1000000000000000094, catalog 0, control 0"}) P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {id: 1, version: 90400, systemId: 1000000000000000094, catalogVersion: 0, controlVersion: 0})
P00 DEBUG: info/infoPg::infoPgAdd: => 0 P00 DEBUG: info/infoPg::infoPgAdd: => 0
P00 DEBUG: info/infoPg::infoPgNew: => {InfoPg} P00 DEBUG: info/infoPg::infoPgNew: => {InfoPg}
P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive} P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive}
@ -181,7 +181,7 @@ P00 DEBUG: info/info::infoNew: (fileName: {"<REPO:ARCHIVE>/archive.info"})
P00 DEBUG: info/info::infoNew: => {Info} P00 DEBUG: info/info::infoNew: => {Info}
P00 DEBUG: info/info::infoIni: (this: {Info}) P00 DEBUG: info/info::infoIni: (this: {Info})
P00 DEBUG: info/info::infoIni: => {Ini} P00 DEBUG: info/info::infoIni: => {Ini}
P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {"id: 1, version: 90400, systemId 1000000000000000094, catalog 0, control 0"}) P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {id: 1, version: 90400, systemId: 1000000000000000094, catalogVersion: 0, controlVersion: 0})
P00 DEBUG: info/infoPg::infoPgAdd: => 0 P00 DEBUG: info/infoPg::infoPgAdd: => 0
P00 DEBUG: info/infoPg::infoPgNew: => {InfoPg} P00 DEBUG: info/infoPg::infoPgNew: => {InfoPg}
P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive} P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive}

View File

@ -554,9 +554,9 @@ P00 DEBUG: info/info::infoNew: (fileName: {"<REPO:ARCHIVE>/archive.info"})
P00 DEBUG: info/info::infoNew: => {Info} P00 DEBUG: info/info::infoNew: => {Info}
P00 DEBUG: info/info::infoIni: (this: {Info}) P00 DEBUG: info/info::infoIni: (this: {Info})
P00 DEBUG: info/info::infoIni: => {Ini} P00 DEBUG: info/info::infoIni: => {Ini}
P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {"id: 2, version: 90400, systemId 1000000000000000094, catalog 0, control 0"}) P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {id: 2, version: 90400, systemId: 1000000000000000094, catalogVersion: 0, controlVersion: 0})
P00 DEBUG: info/infoPg::infoPgAdd: => 0 P00 DEBUG: info/infoPg::infoPgAdd: => 0
P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {"id: 1, version: 90300, systemId 1000000000000000093, catalog 0, control 0"}) P00 DEBUG: info/infoPg::infoPgAdd: (this: {InfoPg}, infoPgData: {id: 1, version: 90300, systemId: 1000000000000000093, catalogVersion: 0, controlVersion: 0})
P00 DEBUG: info/infoPg::infoPgAdd: => 1 P00 DEBUG: info/infoPg::infoPgAdd: => 1
P00 DEBUG: info/infoPg::infoPgNew: => {InfoPg} P00 DEBUG: info/infoPg::infoPgNew: => {InfoPg}
P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive} P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive}

View File

@ -126,5 +126,11 @@ testRun(void)
TEST_RESULT_STR(strPtr(strNewBuf(bufCat(buffer, bufNewStr(strNew("AB"))))), "AB", "cat buffer with space"); TEST_RESULT_STR(strPtr(strNewBuf(bufCat(buffer, bufNewStr(strNew("AB"))))), "AB", "cat buffer with space");
} }
// *****************************************************************************************************************************
if (testBegin("bufToLog()"))
{
TEST_RESULT_STR(strPtr(bufToLog(bufNew(100))), "{used: 0, size: 100}", "buf to log");
}
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();
} }

View File

@ -177,27 +177,15 @@ testRun(void)
if (testBegin("strLstToLog()")) if (testBegin("strLstToLog()"))
{ {
StringList *list = strLstNew(); StringList *list = strLstNew();
char buffer[STACK_TRACE_PARAM_MAX];
TEST_RESULT_INT(strLstToLog(NULL, buffer, 4), 4, "format null list with too small buffer"); TEST_RESULT_STR(strPtr(strLstToLog(list)), "{[]}", "format empty list");
TEST_RESULT_STR(buffer, "nul", " check format");
TEST_RESULT_INT(strLstToLog(NULL, buffer, STACK_TRACE_PARAM_MAX), 4, "format null list");
TEST_RESULT_STR(buffer, "null", " check format");
TEST_RESULT_INT(strLstToLog(list, buffer, STACK_TRACE_PARAM_MAX), 4, "format empty list");
TEST_RESULT_STR(buffer, "{[]}", " check format");
strLstAddZ(list, "item1"); strLstAddZ(list, "item1");
TEST_RESULT_STR(strPtr(strLstToLog(list)), "{[\"item1\"]}", "format 1 item list");
TEST_RESULT_INT(strLstToLog(list, buffer, STACK_TRACE_PARAM_MAX), 11, "format 1 item list");
TEST_RESULT_STR(buffer, "{[\"item1\"]}", " check format");
strLstAddZ(list, "item2"); strLstAddZ(list, "item2");
strLstAddZ(list, "item3"); strLstAddZ(list, "item3");
TEST_RESULT_STR(strPtr(strLstToLog(list)), "{[\"item1\", \"item2\", \"item3\"]}", "format 3 item list");
TEST_RESULT_INT(strLstToLog(list, buffer, STACK_TRACE_PARAM_MAX), 29, "format 3 item list");
TEST_RESULT_STR(buffer, "{[\"item1\", \"item2\", \"item3\"]}", " check format");
} }
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();

View File

@ -201,16 +201,7 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("strToLog()")) if (testBegin("strToLog()"))
{ {
char buffer[STACK_TRACE_PARAM_MAX]; TEST_RESULT_STR(strPtr(strToLog(strNew("test"))), "{\"test\"}", "format string");
TEST_RESULT_INT(strToLog(NULL, buffer, 4), 4, "format null string with too small buffer");
TEST_RESULT_STR(buffer, "nul", " check format");
TEST_RESULT_INT(strToLog(NULL, buffer, STACK_TRACE_PARAM_MAX), 4, "format null string");
TEST_RESULT_STR(buffer, "null", " check format");
TEST_RESULT_INT(strToLog(strNew("test"), buffer, STACK_TRACE_PARAM_MAX), 8, "format string");
TEST_RESULT_STR(buffer, "{\"test\"}", " check format");
} }
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();

View File

@ -307,22 +307,10 @@ testRun(void)
// ----------------------------------------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------------------------------------
if (testBegin("varToLog")) if (testBegin("varToLog"))
{ {
char buffer[STACK_TRACE_PARAM_MAX]; TEST_RESULT_STR(strPtr(varToLog(varNewStrZ("testme"))), "{\"testme\"}", "format String");
TEST_RESULT_STR(strPtr(varToLog(varNewBool(false))), "{false}", "format bool");
TEST_RESULT_INT(varToLog(NULL, buffer, 4), 4, "format truncated null"); TEST_RESULT_STR(strPtr(varToLog(varNewKv())), "{KeyValue}", "format KeyValue");
TEST_RESULT_STR(buffer, "nul", " check buffer"); TEST_RESULT_STR(strPtr(varToLog(varNewVarLst(varLstNew()))), "{VariantList}", "format VariantList");
TEST_RESULT_INT(varToLog(varNewStrZ("testme"), buffer, STACK_TRACE_PARAM_MAX), 10, "format String");
TEST_RESULT_STR(buffer, "{\"testme\"}", " check buffer");
TEST_RESULT_INT(varToLog(varNewBool(false), buffer, STACK_TRACE_PARAM_MAX), 7, "format bool");
TEST_RESULT_STR(buffer, "{false}", " check buffer");
TEST_RESULT_INT(varToLog(varNewKv(), buffer, STACK_TRACE_PARAM_MAX), 10, "format KeyValue");
TEST_RESULT_STR(buffer, "{KeyValue}", " check buffer");
TEST_RESULT_INT(varToLog(varNewVarLst(varLstNew()), buffer, STACK_TRACE_PARAM_MAX), 13, "format VariantList");
TEST_RESULT_STR(buffer, "{VariantList}", " check buffer");
} }
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();

View File

@ -164,21 +164,15 @@ testRun(void)
// ***************************************************************************************************************************** // *****************************************************************************************************************************
if (testBegin("gzipDecompressToLog() and gzipCompressToLog()")) if (testBegin("gzipDecompressToLog() and gzipCompressToLog()"))
{ {
char buffer[STACK_TRACE_PARAM_MAX];
GzipDecompress *decompress = gzipDecompressNew(false); GzipDecompress *decompress = gzipDecompressNew(false);
TEST_RESULT_INT(gzipDecompressToLog(NULL, buffer, 4), 4, "format object with too small buffer"); TEST_RESULT_STR(strPtr(gzipDecompressToLog(decompress)), "{inputSame: false, done: false, availIn: 0}", "format object");
TEST_RESULT_STR(buffer, "nul", " check format");
TEST_RESULT_INT(gzipDecompressToLog(decompress, buffer, STACK_TRACE_PARAM_MAX), 43, "format object");
TEST_RESULT_STR(buffer, "{inputSame: false, done: false, availIn: 0}", " check format");
decompress->inputSame = true; decompress->inputSame = true;
decompress->done = true; decompress->done = true;
inflateEnd(decompress->stream); inflateEnd(decompress->stream);
decompress->stream = NULL; decompress->stream = NULL;
TEST_RESULT_INT(gzipDecompressToLog(decompress, buffer, STACK_TRACE_PARAM_MAX), 41, "format object"); TEST_RESULT_STR(strPtr(gzipDecompressToLog(decompress)), "{inputSame: true, done: true, availIn: 0}", "format object");
TEST_RESULT_STR(buffer, "{inputSame: true, done: true, availIn: 0}", " check format");
} }
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();

View File

@ -133,22 +133,16 @@ testRun(void)
// infoPgDataToLog // infoPgDataToLog
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
char buffer[STACK_TRACE_PARAM_MAX];
TEST_RESULT_INT(infoPgDataToLog(NULL, buffer, 4), 4, "infoPgDataToLog - format null string with too small buffer");
TEST_RESULT_INT(strToLog(NULL, buffer, STACK_TRACE_PARAM_MAX), 4, "infoPgDataToLog - format null string");
TEST_RESULT_STR(buffer, "null", " check format");
// test max values // test max values
infoPgDataTest.id = (unsigned int)4294967295; infoPgDataTest.id = (unsigned int)4294967295;
infoPgDataTest.version = (unsigned int)4294967295; infoPgDataTest.version = (unsigned int)4294967295;
infoPgDataTest.systemId = 18446744073709551615U; infoPgDataTest.systemId = 18446744073709551615U;
infoPgDataTest.catalogVersion = (uint32_t)4294967295; infoPgDataTest.catalogVersion = (uint32_t)4294967295;
infoPgDataTest.controlVersion = (uint32_t)4294967295; infoPgDataTest.controlVersion = (uint32_t)4294967295;
TEST_RESULT_INT(infoPgDataToLog(&infoPgDataTest, buffer, STACK_TRACE_PARAM_MAX), 110, "infoPgDataToLog - format string"); TEST_RESULT_STR(
TEST_RESULT_STR(buffer, strPtr(infoPgDataToLog(&infoPgDataTest)),
"{\"id: 4294967295, version: 4294967295, systemId 18446744073709551615, catalog 4294967295, control 4294967295\"}", "{id: 4294967295, version: 4294967295, systemId: 18446744073709551615, catalogVersion: 4294967295, controlVersion:"
" 4294967295}",
" check max format"); " check max format");
} }
} }