mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +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:
parent
9b9396c7b7
commit
5aa458ffae
@ -79,6 +79,10 @@
|
||||
<release-item>
|
||||
<p>Change locking around async process forking to be more test friendly.</p>
|
||||
</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-core-list>
|
||||
|
||||
|
@ -126,25 +126,10 @@ ioBufferFilter(const IoBuffer *this)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
ioBufferToLog(const IoBuffer *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
ioBufferToLog(const IoBuffer *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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;
|
||||
return strNewFmt("{inputSame: %s, inputPos: %zu}", cvtBoolToConstZ(this->inputSame), this->inputPos);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -39,11 +39,11 @@ void ioBufferFree(IoBuffer *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
IoBuffer *
|
||||
#define FUNCTION_DEBUG_IO_BUFFER_FORMAT(value, buffer, bufferSize) \
|
||||
ioBufferToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, ioBufferToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -404,25 +404,10 @@ ioFilterGroupResult(const IoFilterGroup *this, const String *filterType)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
ioFilterGroupToLog(const IoFilterGroup *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
ioFilterGroupToLog(const IoFilterGroup *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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;
|
||||
return strNewFmt("{inputSame: %s, done: %s}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done));
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -46,11 +46,11 @@ void ioFilterGroupFree(IoFilterGroup *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
IoFilterGroup *
|
||||
#define FUNCTION_DEBUG_IO_FILTER_GROUP_FORMAT(value, buffer, bufferSize) \
|
||||
ioFilterGroupToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, ioFilterGroupToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -84,25 +84,10 @@ ioSizeFilter(const IoSize *this)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
ioSizeToLog(const IoSize *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
ioSizeToLog(const IoSize *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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;
|
||||
return strNewFmt("{size: %" PRIu64 "}", this->size);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -39,11 +39,11 @@ void ioSizeFree(IoSize *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
IoSize *
|
||||
#define FUNCTION_DEBUG_IO_SIZE_FORMAT(value, buffer, bufferSize) \
|
||||
ioSizeToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, ioSizeToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -401,25 +401,10 @@ bufUsedZero(Buffer *this)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
bufToLog(const Buffer *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
bufToLog(const Buffer *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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;
|
||||
return strNewFmt("{used: %zu, size: %zu}", this->used, this->size);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -41,11 +41,11 @@ void bufFree(Buffer *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
Buffer *
|
||||
#define FUNCTION_DEBUG_BUFFER_FORMAT(value, buffer, bufferSize) \
|
||||
bufToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, bufToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -176,25 +176,10 @@ lstSort(List *this, int (*comparator)(const void *, const void*))
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
lstToLog(const List *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
lstToLog(const List *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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;
|
||||
return strNewFmt("{size: %u}", this->listSize);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -32,11 +32,11 @@ void lstFree(List *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
List *
|
||||
#define FUNCTION_DEBUG_LIST_FORMAT(value, buffer, bufferSize) \
|
||||
lstToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, lstToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -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
|
||||
strToLog(const String *this, char *buffer, size_t bufferSize)
|
||||
size_t strObjToLog(const void *object, StrObjToLogFormat formatFunc, char *buffer, size_t bufferSize)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
@ -719,10 +718,10 @@ strToLog(const String *this, char *buffer, size_t bufferSize)
|
||||
{
|
||||
String *string = NULL;
|
||||
|
||||
if (this == NULL)
|
||||
if (object == NULL)
|
||||
string = strNew("null");
|
||||
else
|
||||
string = strNewFmt("{\"%s\"}", strPtr(this));
|
||||
string = formatFunc(object);
|
||||
|
||||
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
|
||||
}
|
||||
@ -731,6 +730,15 @@ strToLog(const String *this, char *buffer, size_t bufferSize)
|
||||
return result;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
String *
|
||||
strToLog(const String *this)
|
||||
{
|
||||
return strNewFmt("{\"%s\"}", strPtr(this));
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Free the string
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -49,10 +49,20 @@ String *strTrunc(String *this, int idx);
|
||||
|
||||
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
|
||||
***********************************************************************************************************************************/
|
||||
size_t strToLog(const String *this, char *buffer, size_t bufferSize);
|
||||
String *strToLog(const String *this);
|
||||
|
||||
#define FUNCTION_DEBUG_CONST_STRING_TYPE \
|
||||
const String *
|
||||
@ -62,7 +72,7 @@ size_t strToLog(const String *this, char *buffer, size_t bufferSize);
|
||||
#define FUNCTION_DEBUG_STRING_TYPE \
|
||||
String *
|
||||
#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 \
|
||||
const String **
|
||||
|
@ -520,25 +520,10 @@ strLstSort(StringList *this, SortOrder sortOrder)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
strLstToLog(const StringList *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
strLstToLog(const StringList *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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;
|
||||
return strNewFmt("{[%s]}", strPtr(strLstJoinQuote(this, ", ", "\"")));
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -50,11 +50,11 @@ void strLstFree(StringList *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
StringList *
|
||||
#define FUNCTION_DEBUG_STRING_LIST_FORMAT(value, buffer, bufferSize) \
|
||||
strLstToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, strLstToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -926,61 +926,43 @@ varVarLst(const Variant *this)
|
||||
/***********************************************************************************************************************************
|
||||
Convert variant to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
varToLog(const Variant *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
varToLog(const Variant *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
String *string = NULL;
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
switch (varType(this))
|
||||
{
|
||||
String *string = NULL;
|
||||
|
||||
if (this == NULL)
|
||||
case varTypeString:
|
||||
{
|
||||
string = strNew("null");
|
||||
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
|
||||
string = strNewFmt("\"%s\"", strPtr(varStrForce(this)));
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
||||
case varTypeKeyValue:
|
||||
{
|
||||
switch (varType(this))
|
||||
{
|
||||
case varTypeString:
|
||||
{
|
||||
String *temp = varStrForce(this);
|
||||
string = strNewFmt("\"%s\"", strPtr(temp));
|
||||
strFree(temp);
|
||||
break;
|
||||
}
|
||||
string = strNew("KeyValue");
|
||||
break;
|
||||
}
|
||||
|
||||
case varTypeKeyValue:
|
||||
{
|
||||
string = strNew("KeyValue");
|
||||
break;
|
||||
}
|
||||
case varTypeVariantList:
|
||||
{
|
||||
string = strNew("VariantList");
|
||||
break;
|
||||
}
|
||||
|
||||
case varTypeVariantList:
|
||||
{
|
||||
string = strNew("VariantList");
|
||||
break;
|
||||
}
|
||||
|
||||
case varTypeBool:
|
||||
case varTypeDouble:
|
||||
case varTypeInt:
|
||||
case varTypeInt64:
|
||||
case varTypeUInt64:
|
||||
{
|
||||
string = varStrForce(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result = (size_t)snprintf(buffer, bufferSize, "{%s}", strPtr(string));
|
||||
case varTypeBool:
|
||||
case varTypeDouble:
|
||||
case varTypeInt:
|
||||
case varTypeInt64:
|
||||
case varTypeUInt64:
|
||||
{
|
||||
string = varStrForce(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
return result;
|
||||
return strNewFmt("{%s}", strPtr(string));
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -73,7 +73,7 @@ void varFree(Variant *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
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 \
|
||||
Variant *
|
||||
#define FUNCTION_DEBUG_VARIANT_FORMAT(value, buffer, bufferSize) \
|
||||
varToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, varToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -177,29 +177,12 @@ gzipCompressInputSame(const GzipCompress *this)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
gzipCompressToLog(const GzipCompress *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
gzipCompressToLog(const GzipCompress *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
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;
|
||||
return 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);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -39,11 +39,11 @@ void gzipCompressFree(GzipCompress *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
GzipCompress *
|
||||
#define FUNCTION_DEBUG_GZIP_COMPRESS_FORMAT(value, buffer, bufferSize) \
|
||||
gzipCompressToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, gzipCompressToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -152,29 +152,12 @@ gzipDecompressInputSame(const GzipDecompress *this)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
gzipDecompressToLog(const GzipDecompress *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
gzipDecompressToLog(const GzipDecompress *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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),
|
||||
this->stream != NULL ? this->stream->avail_in : 0);
|
||||
}
|
||||
|
||||
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
return result;
|
||||
return strNewFmt(
|
||||
"{inputSame: %s, done: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
|
||||
this->stream != NULL ? this->stream->avail_in : 0);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -39,11 +39,11 @@ void gzipDecompressFree(GzipDecompress *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
GzipDecompress *
|
||||
#define FUNCTION_DEBUG_GZIP_DECOMPRESS_FORMAT(value, buffer, bufferSize) \
|
||||
gzipDecompressToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, gzipDecompressToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -216,26 +216,12 @@ infoPgDataTotal(const InfoPg *this)
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
infoPgDataToLog(const InfoPgData *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
infoPgDataToLog(const InfoPgData *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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);
|
||||
|
||||
result = (size_t)snprintf(buffer, bufferSize, "%s", strPtr(string));
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
return result;
|
||||
return strNewFmt(
|
||||
"{id: %u, version: %u, systemId: %" PRIu64 ", catalogVersion: %" PRIu32 ", controlVersion: %" PRIu32 "}",
|
||||
this->id, this->version, this->systemId, this->catalogVersion, this->controlVersion);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -62,7 +62,7 @@ void infoPgFree(InfoPg *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
InfoPg *
|
||||
@ -71,11 +71,11 @@ size_t infoPgDataToLog(const InfoPgData *this, char *buffer, size_t bufferSize);
|
||||
#define FUNCTION_DEBUG_INFO_PG_DATA_TYPE \
|
||||
InfoPgData
|
||||
#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 \
|
||||
InfoPgData *
|
||||
#define FUNCTION_DEBUG_INFO_PG_DATAP_FORMAT(value, buffer, bufferSize) \
|
||||
infoPgDataToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, infoPgDataToLog, buffer, bufferSize)
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -620,25 +620,10 @@ storageRemove(const Storage *this, const String *fileExp, StorageRemoveParam par
|
||||
/***********************************************************************************************************************************
|
||||
Convert to a zero-terminated string for logging
|
||||
***********************************************************************************************************************************/
|
||||
size_t
|
||||
storageToLog(const Storage *this, char *buffer, size_t bufferSize)
|
||||
String *
|
||||
storageToLog(const Storage *this)
|
||||
{
|
||||
size_t result = 0;
|
||||
|
||||
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;
|
||||
return strNewFmt("{path: %s, write: %s}", strPtr(strQuoteZ(this->path, "\"")), cvtBoolToConstZ(this->write));
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -251,11 +251,11 @@ void storageFree(const Storage *this);
|
||||
/***********************************************************************************************************************************
|
||||
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 \
|
||||
Storage *
|
||||
#define FUNCTION_DEBUG_STORAGE_FORMAT(value, buffer, bufferSize) \
|
||||
(size_t)storageToLog(value, buffer, bufferSize)
|
||||
FUNCTION_DEBUG_STRING_OBJECT_FORMAT(value, storageToLog, buffer, bufferSize)
|
||||
|
||||
#endif
|
||||
|
@ -166,7 +166,7 @@ unit:
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: type-buffer
|
||||
total: 4
|
||||
total: 5
|
||||
|
||||
coverage:
|
||||
common/type/buffer: full
|
||||
|
@ -137,7 +137,7 @@ P00 DEBUG: info/info::infoNew: (fileName: {"<REPO:ARCHIVE>/archive.info"})
|
||||
P00 DEBUG: info/info::infoNew: => {Info}
|
||||
P00 DEBUG: info/info::infoIni: (this: {Info})
|
||||
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::infoPgNew: => {InfoPg}
|
||||
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::infoIni: (this: {Info})
|
||||
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::infoPgNew: => {InfoPg}
|
||||
P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive}
|
||||
|
@ -554,9 +554,9 @@ P00 DEBUG: info/info::infoNew: (fileName: {"<REPO:ARCHIVE>/archive.info"})
|
||||
P00 DEBUG: info/info::infoNew: => {Info}
|
||||
P00 DEBUG: info/info::infoIni: (this: {Info})
|
||||
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: (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::infoPgNew: => {InfoPg}
|
||||
P00 DEBUG: info/infoArchive::infoArchiveNew: => {InfoArchive}
|
||||
|
@ -126,5 +126,11 @@ testRun(void)
|
||||
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();
|
||||
}
|
||||
|
@ -177,27 +177,15 @@ testRun(void)
|
||||
if (testBegin("strLstToLog()"))
|
||||
{
|
||||
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(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");
|
||||
TEST_RESULT_STR(strPtr(strLstToLog(list)), "{[]}", "format empty list");
|
||||
|
||||
strLstAddZ(list, "item1");
|
||||
|
||||
TEST_RESULT_INT(strLstToLog(list, buffer, STACK_TRACE_PARAM_MAX), 11, "format 1 item list");
|
||||
TEST_RESULT_STR(buffer, "{[\"item1\"]}", " check format");
|
||||
TEST_RESULT_STR(strPtr(strLstToLog(list)), "{[\"item1\"]}", "format 1 item list");
|
||||
|
||||
strLstAddZ(list, "item2");
|
||||
strLstAddZ(list, "item3");
|
||||
|
||||
TEST_RESULT_INT(strLstToLog(list, buffer, STACK_TRACE_PARAM_MAX), 29, "format 3 item list");
|
||||
TEST_RESULT_STR(buffer, "{[\"item1\", \"item2\", \"item3\"]}", " check format");
|
||||
TEST_RESULT_STR(strPtr(strLstToLog(list)), "{[\"item1\", \"item2\", \"item3\"]}", "format 3 item list");
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
|
@ -201,16 +201,7 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("strToLog()"))
|
||||
{
|
||||
char buffer[STACK_TRACE_PARAM_MAX];
|
||||
|
||||
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");
|
||||
TEST_RESULT_STR(strPtr(strToLog(strNew("test"))), "{\"test\"}", "format string");
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
|
@ -307,22 +307,10 @@ testRun(void)
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("varToLog"))
|
||||
{
|
||||
char buffer[STACK_TRACE_PARAM_MAX];
|
||||
|
||||
TEST_RESULT_INT(varToLog(NULL, buffer, 4), 4, "format truncated null");
|
||||
TEST_RESULT_STR(buffer, "nul", " check buffer");
|
||||
|
||||
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");
|
||||
TEST_RESULT_STR(strPtr(varToLog(varNewStrZ("testme"))), "{\"testme\"}", "format String");
|
||||
TEST_RESULT_STR(strPtr(varToLog(varNewBool(false))), "{false}", "format bool");
|
||||
TEST_RESULT_STR(strPtr(varToLog(varNewKv())), "{KeyValue}", "format KeyValue");
|
||||
TEST_RESULT_STR(strPtr(varToLog(varNewVarLst(varLstNew()))), "{VariantList}", "format VariantList");
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
|
@ -164,21 +164,15 @@ testRun(void)
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("gzipDecompressToLog() and gzipCompressToLog()"))
|
||||
{
|
||||
char buffer[STACK_TRACE_PARAM_MAX];
|
||||
GzipDecompress *decompress = gzipDecompressNew(false);
|
||||
|
||||
TEST_RESULT_INT(gzipDecompressToLog(NULL, buffer, 4), 4, "format object with too small buffer");
|
||||
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");
|
||||
TEST_RESULT_STR(strPtr(gzipDecompressToLog(decompress)), "{inputSame: false, done: false, availIn: 0}", "format object");
|
||||
|
||||
decompress->inputSame = true;
|
||||
decompress->done = true;
|
||||
inflateEnd(decompress->stream);
|
||||
decompress->stream = NULL;
|
||||
TEST_RESULT_INT(gzipDecompressToLog(decompress, buffer, STACK_TRACE_PARAM_MAX), 41, "format object");
|
||||
TEST_RESULT_STR(buffer, "{inputSame: true, done: true, availIn: 0}", " check format");
|
||||
TEST_RESULT_STR(strPtr(gzipDecompressToLog(decompress)), "{inputSame: true, done: true, availIn: 0}", "format object");
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
|
@ -133,22 +133,16 @@ testRun(void)
|
||||
|
||||
// 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
|
||||
infoPgDataTest.id = (unsigned int)4294967295;
|
||||
infoPgDataTest.version = (unsigned int)4294967295;
|
||||
infoPgDataTest.systemId = 18446744073709551615U;
|
||||
infoPgDataTest.catalogVersion = (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(buffer,
|
||||
"{\"id: 4294967295, version: 4294967295, systemId 18446744073709551615, catalog 4294967295, control 4294967295\"}",
|
||||
TEST_RESULT_STR(
|
||||
strPtr(infoPgDataToLog(&infoPgDataTest)),
|
||||
"{id: 4294967295, version: 4294967295, systemId: 18446744073709551615, catalogVersion: 4294967295, controlVersion:"
|
||||
" 4294967295}",
|
||||
" check max format");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user