1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-02-21 19:48:29 +02:00

Refactor logging functions to never allocate memory.

Allocating memory made these functions simpler but it meant that memory was leaking into the calling context when logging was enabled. It is not clear that this was an issue but it seems that trace level logging could result it a lot of memory usage depending on the use case.

This also makes it possible to audit allocations returned to the calling context, which will be done in a followup commit.

Also rename objToLog() to objNameToLog() since it seemed logical to name the new function objToLog().
This commit is contained in:
David Steele 2023-01-12 17:14:36 +07:00
parent 890b9d0093
commit de1dfb66ca
162 changed files with 1025 additions and 593 deletions

View File

@ -108,7 +108,7 @@ myObjFree(MyObj *const this)
#define FUNCTION_LOG_MY_OBJ_TYPE \
MyObj *
#define FUNCTION_LOG_MY_OBJ_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize)
/*
* C FILE - see db.c for a more complete and actual implementation example

View File

@ -214,7 +214,7 @@ myObjFree(MyObj *const this)
#define FUNCTION_LOG_MY_OBJ_TYPE \
MyObj *
#define FUNCTION_LOG_MY_OBJ_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize)
/*
* C FILE - see db.c for a more complete and actual implementation example

View File

@ -31,9 +31,10 @@ SRCS_COMMON = \
common/type/list.c \
common/type/object.c \
common/type/pack.c \
common/type/stringZ.c \
common/type/stringId.c \
common/type/stringList.c \
common/type/stringStatic.c \
common/type/stringZ.c \
common/type/variant.c \
common/type/variantList.c \
common/user.c \

View File

@ -139,11 +139,11 @@ Macros for function logging
#define FUNCTION_LOG_YAML_TYPE \
Yaml *
#define FUNCTION_LOG_YAML_FORMAT(value, buffer, bufferSize) \
objToLog(value, "Yaml", buffer, bufferSize)
objNameToLog(value, "Yaml", buffer, bufferSize)
#define FUNCTION_LOG_YAML_EVENT_TYPE \
YamlEvent
#define FUNCTION_LOG_YAML_EVENT_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "YamlEvent", buffer, bufferSize)
objNameToLog(&value, "YamlEvent", buffer, bufferSize)
#endif

View File

@ -140,7 +140,7 @@ Get the postgres database and storage objects
#define FUNCTION_LOG_BACKUP_DATA_TYPE \
BackupData *
#define FUNCTION_LOG_BACKUP_DATA_FORMAT(value, buffer, bufferSize) \
objToLog(value, "BackupData", buffer, bufferSize)
objNameToLog(value, "BackupData", buffer, bufferSize)
typedef struct BackupData
{

View File

@ -35,16 +35,16 @@ typedef struct PageChecksum
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *
pageChecksumToLog(const PageChecksum *this)
FN_EXTERN void
pageChecksumToLog(const PageChecksum *const this, StringStatic *const debugLog)
{
return strNewFmt("{valid: %s, align: %s}", cvtBoolToConstZ(this->valid), cvtBoolToConstZ(this->align));
strStcFmt(debugLog, "{valid: %s, align: %s}", cvtBoolToConstZ(this->valid), cvtBoolToConstZ(this->align));
}
#define FUNCTION_LOG_PAGE_CHECKSUM_TYPE \
PageChecksum *
#define FUNCTION_LOG_PAGE_CHECKSUM_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pageChecksumToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, pageChecksumToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Count bytes in the input

View File

@ -121,7 +121,7 @@ typedef struct InfoRepoData
#define FUNCTION_LOG_INFO_REPO_DATA_TYPE \
InfoRepoData *
#define FUNCTION_LOG_INFO_REPO_DATA_FORMAT(value, buffer, bufferSize) \
objToLog(value, "InfoRepoData", buffer, bufferSize)
objNameToLog(value, "InfoRepoData", buffer, bufferSize)
// Stanza with repository list of information for each repository
typedef struct InfoStanzaRepo
@ -138,7 +138,7 @@ typedef struct InfoStanzaRepo
#define FUNCTION_LOG_INFO_STANZA_REPO_TYPE \
InfoStanzaRepo *
#define FUNCTION_LOG_INFO_STANZA_REPO_FORMAT(value, buffer, bufferSize) \
objToLog(value, "InfoStanzaRepo", buffer, bufferSize)
objNameToLog(value, "InfoStanzaRepo", buffer, bufferSize)
// Group all databases with the same system-id and version together regardless of db-id or repo
typedef struct DbGroup
@ -154,7 +154,7 @@ typedef struct DbGroup
#define FUNCTION_LOG_DB_GROUP_TYPE \
DbGroup *
#define FUNCTION_LOG_DB_GROUP_FORMAT(value, buffer, bufferSize) \
objToLog(value, "DbGroup", buffer, bufferSize)
objNameToLog(value, "DbGroup", buffer, bufferSize)
/***********************************************************************************************************************************
Helper function for reporting errors

View File

@ -197,7 +197,7 @@ typedef struct RestoreBackupData
#define FUNCTION_LOG_RESTORE_BACKUP_DATA_TYPE \
RestoreBackupData
#define FUNCTION_LOG_RESTORE_BACKUP_DATA_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "RestoreBackupData", buffer, bufferSize)
objNameToLog(&value, "RestoreBackupData", buffer, bufferSize)
// Helper function for restoreBackupSet
static RestoreBackupData

View File

@ -42,12 +42,12 @@ Data Types and Structures
#define FUNCTION_LOG_VERIFY_ARCHIVE_RESULT_TYPE \
VerifyArchiveResult
#define FUNCTION_LOG_VERIFY_ARCHIVE_RESULT_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "VerifyArchiveResult", buffer, bufferSize)
objNameToLog(&value, "VerifyArchiveResult", buffer, bufferSize)
#define FUNCTION_LOG_VERIFY_BACKUP_RESULT_TYPE \
VerifyBackupResult
#define FUNCTION_LOG_VERIFY_BACKUP_RESULT_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "VerifyBackupResult", buffer, bufferSize)
objNameToLog(&value, "VerifyBackupResult", buffer, bufferSize)
// Structure for verifying repository info files
typedef struct VerifyInfoFile

View File

@ -30,18 +30,18 @@ typedef struct Bz2Compress
/***********************************************************************************************************************************
Render as string for logging
***********************************************************************************************************************************/
static String *
bz2CompressToLog(const Bz2Compress *this)
static void
bz2CompressToLog(const Bz2Compress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{inputSame: %s, done: %s, flushing: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
cvtBoolToConstZ(this->flushing), this->stream.avail_in);
strStcFmt(
debugLog, "{inputSame: %s, done: %s, flushing: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame),
cvtBoolToConstZ(this->done), cvtBoolToConstZ(this->flushing), this->stream.avail_in);
}
#define FUNCTION_LOG_BZ2_COMPRESS_TYPE \
Bz2Compress *
#define FUNCTION_LOG_BZ2_COMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, bz2CompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, bz2CompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free compression stream

View File

@ -29,18 +29,18 @@ typedef struct Bz2Decompress
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
bz2DecompressToLog(const Bz2Decompress *this)
static void
bz2DecompressToLog(const Bz2Decompress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{inputSame: %s, done: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
strStcFmt(
debugLog, "{inputSame: %s, done: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
this->stream.avail_in);
}
#define FUNCTION_LOG_BZ2_DECOMPRESS_TYPE \
Bz2Decompress *
#define FUNCTION_LOG_BZ2_DECOMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, bz2DecompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, bz2DecompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free inflate stream

View File

@ -30,18 +30,18 @@ typedef struct GzCompress
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
gzCompressToLog(const GzCompress *this)
static void
gzCompressToLog(const GzCompress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{inputSame: %s, done: %s, flushing: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
cvtBoolToConstZ(this->flushing), this->stream.avail_in);
strStcFmt(
debugLog, "{inputSame: %s, done: %s, flushing: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame),
cvtBoolToConstZ(this->done), cvtBoolToConstZ(this->flushing), this->stream.avail_in);
}
#define FUNCTION_LOG_GZ_COMPRESS_TYPE \
GzCompress *
#define FUNCTION_LOG_GZ_COMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, gzCompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, gzCompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Compression constants

View File

@ -29,18 +29,18 @@ typedef struct GzDecompress
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
gzDecompressToLog(const GzDecompress *this)
static void
gzDecompressToLog(const GzDecompress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{inputSame: %s, done: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
strStcFmt(
debugLog, "{inputSame: %s, done: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done),
this->stream.avail_in);
}
#define FUNCTION_LOG_GZ_DECOMPRESS_TYPE \
GzDecompress *
#define FUNCTION_LOG_GZ_DECOMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, gzDecompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, gzDecompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free inflate stream

View File

@ -44,18 +44,18 @@ typedef struct Lz4Compress
/***********************************************************************************************************************************
Render as string for logging
***********************************************************************************************************************************/
static String *
lz4CompressToLog(const Lz4Compress *this)
static void
lz4CompressToLog(const Lz4Compress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{level: %d, first: %s, inputSame: %s, flushing: %s}", this->prefs.compressionLevel,
strStcFmt(
debugLog, "{level: %d, first: %s, inputSame: %s, flushing: %s}", this->prefs.compressionLevel,
cvtBoolToConstZ(this->first), cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->flushing));
}
#define FUNCTION_LOG_LZ4_COMPRESS_TYPE \
Lz4Compress *
#define FUNCTION_LOG_LZ4_COMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, lz4CompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, lz4CompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free compression context

View File

@ -32,18 +32,18 @@ typedef struct Lz4Decompress
/***********************************************************************************************************************************
Render as string for logging
***********************************************************************************************************************************/
static String *
lz4DecompressToLog(const Lz4Decompress *this)
static void
lz4DecompressToLog(const Lz4Decompress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame), this->inputOffset,
cvtBoolToConstZ(this->frameDone), cvtBoolToConstZ(this->done));
strStcFmt(
debugLog, "{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame),
this->inputOffset, cvtBoolToConstZ(this->frameDone), cvtBoolToConstZ(this->done));
}
#define FUNCTION_LOG_LZ4_DECOMPRESS_TYPE \
Lz4Decompress *
#define FUNCTION_LOG_LZ4_DECOMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, lz4DecompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, lz4DecompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free decompression context

View File

@ -32,18 +32,18 @@ typedef struct ZstCompress
/***********************************************************************************************************************************
Render as string for logging
***********************************************************************************************************************************/
static String *
zstCompressToLog(const ZstCompress *this)
static void
zstCompressToLog(const ZstCompress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{level: %d, inputSame: %s, inputOffset: %zu, flushing: %s}", this->level, cvtBoolToConstZ(this->inputSame),
strStcFmt(
debugLog, "{level: %d, inputSame: %s, inputOffset: %zu, flushing: %s}", this->level, cvtBoolToConstZ(this->inputSame),
this->inputOffset, cvtBoolToConstZ(this->flushing));
}
#define FUNCTION_LOG_ZST_COMPRESS_TYPE \
ZstCompress *
#define FUNCTION_LOG_ZST_COMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, zstCompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, zstCompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free compression context

View File

@ -31,18 +31,18 @@ typedef struct ZstDecompress
/***********************************************************************************************************************************
Render as string for logging
***********************************************************************************************************************************/
static String *
zstDecompressToLog(const ZstDecompress *this)
static void
zstDecompressToLog(const ZstDecompress *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame), this->inputOffset,
strStcFmt(
debugLog, "{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame), this->inputOffset,
cvtBoolToConstZ(this->frameDone), cvtBoolToConstZ(this->done));
}
#define FUNCTION_LOG_ZST_DECOMPRESS_TYPE \
ZstDecompress *
#define FUNCTION_LOG_ZST_DECOMPRESS_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, zstDecompressToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, zstDecompressToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free decompression context

View File

@ -51,17 +51,16 @@ typedef struct CipherBlock
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *
cipherBlockToLog(const CipherBlock *this)
FN_EXTERN void
cipherBlockToLog(const CipherBlock *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{inputSame: %s, done: %s}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done));
strStcFmt(debugLog, "{inputSame: %s, done: %s}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done));
}
#define FUNCTION_LOG_CIPHER_BLOCK_TYPE \
CipherBlock *
#define FUNCTION_LOG_CIPHER_BLOCK_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, cipherBlockToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, cipherBlockToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free cipher context

View File

@ -49,7 +49,7 @@ Macros for function logging
#define FUNCTION_LOG_CRYPTO_HASH_TYPE \
CryptoHash *
#define FUNCTION_LOG_CRYPTO_HASH_FORMAT(value, buffer, bufferSize) \
objToLog(value, "CryptoHash", buffer, bufferSize)
objNameToLog(value, "CryptoHash", buffer, bufferSize)
/***********************************************************************************************************************************
Free hash context

View File

@ -8,36 +8,53 @@ Debug Routines
#include "common/debug.h"
/**********************************************************************************************************************************/
FN_EXTERN size_t
objToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize)
FN_EXTERN size_t objToLog(const void *const object, ObjToLogFormat formatFunc, char *const buffer, const size_t bufferSize)
{
size_t result = 0;
StringStatic debugLog = strStcInit(buffer, bufferSize);
if (object == NULL)
result = (size_t)snprintf(buffer, bufferSize, NULL_Z);
strStcCat(&debugLog, NULL_Z);
else
result = (size_t)snprintf(buffer, bufferSize, "{%s}", objectName);
formatFunc(object, &debugLog);
return result;
return strStcResultSize(&debugLog);
}
/**********************************************************************************************************************************/
FN_EXTERN size_t
objNameToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize)
{
StringStatic debugLog = strStcInit(buffer, bufferSize);
if (object == NULL)
strStcCat(&debugLog, NULL_Z);
else
strStcFmt(&debugLog, "{%s}", objectName);
return strStcResultSize(&debugLog);
}
/**********************************************************************************************************************************/
FN_EXTERN size_t
ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t bufferSize)
{
size_t result = 0;
StringStatic debugLog = strStcInit(buffer, bufferSize);
if (pointer == NULL)
result = (size_t)snprintf(buffer, bufferSize, NULL_Z);
strStcCat(&debugLog, NULL_Z);
else
result = (size_t)snprintf(buffer, bufferSize, "(%s)", pointerName);
strStcFmt(&debugLog, "(%s)", pointerName);
return result;
return strStcResultSize(&debugLog);
}
/**********************************************************************************************************************************/
FN_EXTERN size_t
typeToLog(const char *typeName, char *buffer, size_t bufferSize)
{
return (size_t)snprintf(buffer, bufferSize, "%s", typeName);
StringStatic debugLog = strStcInit(buffer, bufferSize);
strStcFmt(&debugLog, "%s", typeName);
return strStcResultSize(&debugLog);
}

View File

@ -7,6 +7,7 @@ Debug Routines
#include "common/assert.h"
#include "common/stackTrace.h"
#include "common/type/convert.h"
#include "common/type/stringStatic.h"
#include "common/type/stringZ.h"
/***********************************************************************************************************************************
@ -98,7 +99,15 @@ FUNCTION_LOG_VOID() is provided as a shortcut for functions that have no paramet
Functions and macros to render various data types
***********************************************************************************************************************************/
// Convert object to a zero-terminated string for logging
FN_EXTERN size_t objToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize);
typedef void (*ObjToLogFormat)(const void *object, StringStatic *debugLog);
FN_EXTERN size_t objToLog(const void *object, ObjToLogFormat formatFunc, char *buffer, size_t bufferSize);
#define FUNCTION_LOG_OBJECT_FORMAT(object, formatFunc, buffer, bufferSize) \
objToLog(object, (ObjToLogFormat)formatFunc, buffer, bufferSize)
// Convert object name to a zero-terminated string for logging
FN_EXTERN size_t objNameToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize);
// Convert pointer to a zero-terminated string for logging
FN_EXTERN size_t ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t bufferSize);

View File

@ -355,6 +355,6 @@ Macros for function logging
#define FUNCTION_LOG_ERROR_TYPE_TYPE \
ErrorType *
#define FUNCTION_LOG_ERROR_TYPE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "ErrorType", buffer, bufferSize)
objNameToLog(value, "ErrorType", buffer, bufferSize)
#endif

View File

@ -75,6 +75,6 @@ Macros for function logging
#define FUNCTION_LOG_EXEC_TYPE \
Exec *
#define FUNCTION_LOG_EXEC_FORMAT(value, buffer, bufferSize) \
objToLog(value, "Exec", buffer, bufferSize)
objNameToLog(value, "Exec", buffer, bufferSize)
#endif

View File

@ -76,6 +76,6 @@ Macros for function logging
#define FUNCTION_LOG_INI_TYPE \
Ini *
#define FUNCTION_LOG_INI_FORMAT(value, buffer, bufferSize) \
objToLog(value, "Ini", buffer, bufferSize)
objNameToLog(value, "Ini", buffer, bufferSize)
#endif

View File

@ -26,7 +26,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_BUFFER_READ_TYPE \
IoBufferRead *
#define FUNCTION_LOG_IO_BUFFER_READ_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoBufferRead", buffer, bufferSize)
objNameToLog(value, "IoBufferRead", buffer, bufferSize)
/***********************************************************************************************************************************
Read data from the buffer

View File

@ -23,7 +23,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_BUFFER_WRITE_TYPE \
IoBufferWrite *
#define FUNCTION_LOG_IO_BUFFER_WRITE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoBufferWrite", buffer, bufferSize)
objNameToLog(value, "IoBufferWrite", buffer, bufferSize)
/***********************************************************************************************************************************
Write to the buffer

View File

@ -47,9 +47,13 @@ ioClientNew(void *driver, const IoClientInterface *interface)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
ioClientToLog(const IoClient *this)
FN_EXTERN void
ioClientToLog(const IoClient *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver)));
strStcCat(debugLog, "{type: ");
strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCat(debugLog, ", driver: ");
this->pub.interface->toLog(this->pub.driver, debugLog);
strStcCatChr(debugLog, '}');
}

View File

@ -62,11 +62,11 @@ ioClientFree(IoClient *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *ioClientToLog(const IoClient *this);
FN_EXTERN void ioClientToLog(const IoClient *this, StringStatic *debugLog);
#define FUNCTION_LOG_IO_CLIENT_TYPE \
IoClient *
#define FUNCTION_LOG_IO_CLIENT_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioClientToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, ioClientToLog, buffer, bufferSize)
#endif

View File

@ -23,7 +23,7 @@ typedef struct IoClientInterface
IoSession *(*open)(void *driver);
// Driver log function
String *(*toLog)(const void *driver);
void (*toLog)(const void *driver, StringStatic *debugLog);
} IoClientInterface;
/***********************************************************************************************************************************
@ -37,6 +37,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_CLIENT_INTERFACE_TYPE \
IoClientInterface *
#define FUNCTION_LOG_IO_CLIENT_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoClientInterface", buffer, bufferSize)
objNameToLog(&value, "IoClientInterface", buffer, bufferSize)
#endif

View File

@ -29,7 +29,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_FD_READ_TYPE \
IoFdRead *
#define FUNCTION_LOG_IO_FD_READ_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoFdRead", buffer, bufferSize)
objNameToLog(value, "IoFdRead", buffer, bufferSize)
/***********************************************************************************************************************************
Are there bytes ready to read immediately?

View File

@ -28,7 +28,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_FD_WRITE_TYPE \
IoFdWrite *
#define FUNCTION_LOG_IO_FD_WRITE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoFdWrite", buffer, bufferSize)
objNameToLog(value, "IoFdWrite", buffer, bufferSize)
/***********************************************************************************************************************************
// Can bytes be written immediately?

View File

@ -28,16 +28,16 @@ typedef struct IoBuffer
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
ioBufferToLog(const IoBuffer *this)
static void
ioBufferToLog(const IoBuffer *const this, StringStatic *const debugLog)
{
return strNewFmt("{inputSame: %s, inputPos: %zu}", cvtBoolToConstZ(this->inputSame), this->inputPos);
strStcFmt(debugLog, "{inputSame: %s, inputPos: %zu}", cvtBoolToConstZ(this->inputSame), this->inputPos);
}
#define FUNCTION_LOG_IO_BUFFER_TYPE \
IoBuffer *
#define FUNCTION_LOG_IO_BUFFER_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioBufferToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, ioBufferToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Move data from the input buffer to the output buffer

View File

@ -154,8 +154,10 @@ ioFilterResult(const IoFilter *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
ioFilterToLog(const IoFilter *this)
FN_EXTERN void
ioFilterToLog(const IoFilter *const this, StringStatic *const debugLog)
{
return strNewFmt("{type: %s}", strZ(strIdToStr(ioFilterType(this))));
strStcCat(debugLog, "{type: ");
strStcResultSizeInc(debugLog, strIdToLog(ioFilterType(this), strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCatChr(debugLog, '}');
}

View File

@ -45,11 +45,11 @@ ioFilterFree(IoFilter *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *ioFilterToLog(const IoFilter *this);
FN_EXTERN void ioFilterToLog(const IoFilter *this, StringStatic *debugLog);
#define FUNCTION_LOG_IO_FILTER_TYPE \
IoFilter *
#define FUNCTION_LOG_IO_FILTER_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioFilterToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, ioFilterToLog, buffer, bufferSize)
#endif

View File

@ -125,6 +125,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_FILTER_INTERFACE_TYPE \
IoFilterInterface *
#define FUNCTION_LOG_IO_FILTER_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoFilterInterface", buffer, bufferSize)
objNameToLog(&value, "IoFilterInterface", buffer, bufferSize)
#endif

View File

@ -30,7 +30,7 @@ typedef struct IoFilterData
#define FUNCTION_LOG_IO_FILTER_DATA_TYPE \
IoFilterData *
#define FUNCTION_LOG_IO_FILTER_DATA_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoFilterData", buffer, bufferSize)
objNameToLog(value, "IoFilterData", buffer, bufferSize)
/***********************************************************************************************************************************
Filter results
@ -544,10 +544,11 @@ ioFilterGroupResultAllSet(IoFilterGroup *const this, const Pack *const filterRes
}
/**********************************************************************************************************************************/
FN_EXTERN String *
ioFilterGroupToLog(const IoFilterGroup *this)
FN_EXTERN void
ioFilterGroupToLog(const IoFilterGroup *const this, StringStatic *const debugLog)
{
return strNewFmt(
strStcFmt(
debugLog,
"{inputSame: %s, done: %s"
#ifdef DEBUG
", opened %s, flushing %s, closed %s"

View File

@ -122,11 +122,11 @@ ioFilterGroupFree(IoFilterGroup *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *ioFilterGroupToLog(const IoFilterGroup *this);
FN_EXTERN void ioFilterGroupToLog(const IoFilterGroup *this, StringStatic *debugLog);
#define FUNCTION_LOG_IO_FILTER_GROUP_TYPE \
IoFilterGroup *
#define FUNCTION_LOG_IO_FILTER_GROUP_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioFilterGroupToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, ioFilterGroupToLog, buffer, bufferSize)
#endif

View File

@ -23,7 +23,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_SINK_TYPE \
IoSink *
#define FUNCTION_LOG_IO_SINK_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoSink", buffer, bufferSize)
objNameToLog(value, "IoSink", buffer, bufferSize)
/***********************************************************************************************************************************
Discard all input

View File

@ -23,16 +23,16 @@ typedef struct IoSize
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
ioSizeToLog(const IoSize *this)
static void
ioSizeToLog(const IoSize *const this, StringStatic *const debugLog)
{
return strNewFmt("{size: %" PRIu64 "}", this->size);
strStcFmt(debugLog, "{size: %" PRIu64 "}", this->size);
}
#define FUNCTION_LOG_IO_SIZE_TYPE \
IoSize *
#define FUNCTION_LOG_IO_SIZE_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioSizeToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, ioSizeToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Count bytes in the input

View File

@ -115,10 +115,10 @@ httpClientReuse(HttpClient *this, HttpSession *session)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
httpClientToLog(const HttpClient *this)
FN_EXTERN void
httpClientToLog(const HttpClient *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{ioClient: %s, reusable: %u, timeout: %" PRIu64"}", strZ(ioClientToLog(this->ioClient)), lstSize(this->sessionReuseList),
httpClientTimeout(this));
strStcCat(debugLog, "{ioClient: ");
ioClientToLog(this->ioClient, debugLog);
strStcFmt(debugLog, ", reusable: %u, timeout: %" PRIu64 "}", lstSize(this->sessionReuseList), httpClientTimeout(this));
}

View File

@ -70,11 +70,11 @@ FN_EXTERN void httpClientReuse(HttpClient *this, HttpSession *session);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *httpClientToLog(const HttpClient *this);
FN_EXTERN void httpClientToLog(const HttpClient *this, StringStatic *debugLog);
#define FUNCTION_LOG_HTTP_CLIENT_TYPE \
HttpClient *
#define FUNCTION_LOG_HTTP_CLIENT_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpClientToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, httpClientToLog, buffer, bufferSize)
#endif

View File

@ -202,26 +202,25 @@ httpHeaderRedact(const HttpHeader *this, const String *key)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
httpHeaderToLog(const HttpHeader *this)
FN_EXTERN void
httpHeaderToLog(const HttpHeader *const this, StringStatic *const debugLog)
{
String *result = strCatZ(strNew(), "{");
const StringList *keyList = httpHeaderList(this);
const VariantList *const keyList = kvKeyList(this->kv);
for (unsigned int keyIdx = 0; keyIdx < strLstSize(keyList); keyIdx++)
strStcCatChr(debugLog, '{');
for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++)
{
const String *key = strLstGet(keyList, keyIdx);
const String *const key = varStr(varLstGet(keyList, keyIdx));
if (strSize(result) != 1)
strCatZ(result, ", ");
if (keyIdx != 0)
strStcCat(debugLog, ", ");
if (httpHeaderRedact(this, key))
strCatFmt(result, "%s: <redacted>", strZ(key));
strStcFmt(debugLog, "%s: <redacted>", strZ(key));
else
strCatFmt(result, "%s: '%s'", strZ(key), strZ(httpHeaderGet(this, key)));
strStcFmt(debugLog, "%s: '%s'", strZ(key), strZ(httpHeaderGet(this, key)));
}
strCatZ(result, "}");
return result;
strStcCatChr(debugLog, '}');
}

View File

@ -60,11 +60,11 @@ httpHeaderFree(HttpHeader *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *httpHeaderToLog(const HttpHeader *this);
FN_EXTERN void httpHeaderToLog(const HttpHeader *this, StringStatic *debugLog);
#define FUNCTION_LOG_HTTP_HEADER_TYPE \
HttpHeader *
#define FUNCTION_LOG_HTTP_HEADER_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpHeaderToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, httpHeaderToLog, buffer, bufferSize)
#endif

View File

@ -288,28 +288,25 @@ httpQueryRender(const HttpQuery *this, HttpQueryRenderParam param)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
httpQueryToLog(const HttpQuery *this)
FN_EXTERN void
httpQueryToLog(const HttpQuery *const this, StringStatic *const debugLog)
{
String *result = strCatZ(strNew(), "{");
const StringList *keyList = httpQueryList(this);
const VariantList *const keyList = kvKeyList(this->kv);
for (unsigned int keyIdx = 0; keyIdx < strLstSize(keyList); keyIdx++)
strStcCatChr(debugLog, '{');
for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++)
{
const String *key = strLstGet(keyList, keyIdx);
const String *const key = varStr(varLstGet(keyList, keyIdx));
if (strSize(result) != 1)
strCatZ(result, ", ");
strCatFmt(result, "%s: ", strZ(key));
if (keyIdx != 0)
strStcCat(debugLog, ", ");
if (httpQueryRedact(this, key))
strCatZ(result, "<redacted>");
strStcFmt(debugLog, "%s: <redacted>", strZ(key));
else
strCatFmt(result, "'%s'", strZ(httpQueryGet(this, key)));
strStcFmt(debugLog, "%s: '%s'", strZ(key), strZ(httpQueryGet(this, key)));
}
strCatZ(result, "}");
return result;
strStcCatChr(debugLog, '}');
}

View File

@ -95,11 +95,11 @@ httpQueryFree(HttpQuery *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *httpQueryToLog(const HttpQuery *this);
FN_EXTERN void httpQueryToLog(const HttpQuery *this, StringStatic *debugLog);
#define FUNCTION_LOG_HTTP_QUERY_TYPE \
HttpQuery *
#define FUNCTION_LOG_HTTP_QUERY_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpQueryToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, httpQueryToLog, buffer, bufferSize)
#endif

View File

@ -302,11 +302,19 @@ httpRequestError(const HttpRequest *this, HttpResponse *response)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
httpRequestToLog(const HttpRequest *this)
FN_EXTERN void
httpRequestToLog(const HttpRequest *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{verb: %s, path: %s, query: %s, header: %s, contentSize: %zu}", strZ(httpRequestVerb(this)), strZ(httpRequestPath(this)),
httpRequestQuery(this) == NULL ? "null" : strZ(httpQueryToLog(httpRequestQuery(this))),
strZ(httpHeaderToLog(httpRequestHeader(this))), this->content == NULL ? 0 : bufUsed(this->content));
strStcFmt(
debugLog, "{verb: %s, path: %s, contentSize: %zu, query: ", strZ(httpRequestVerb(this)),
strZ(httpRequestPath(this)), this->content == NULL ? 0 : bufUsed(this->content));
strStcResultSizeInc(
debugLog,
FUNCTION_LOG_OBJECT_FORMAT(
httpRequestQuery(this), httpQueryToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCat(debugLog, ", header: "),
httpHeaderToLog(httpRequestHeader(this), debugLog);
strStcCatChr(debugLog, '}');
}

View File

@ -149,11 +149,11 @@ httpRequestFree(HttpRequest *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *httpRequestToLog(const HttpRequest *this);
FN_EXTERN void httpRequestToLog(const HttpRequest *this, StringStatic *debugLog);
#define FUNCTION_LOG_HTTP_REQUEST_TYPE \
HttpRequest *
#define FUNCTION_LOG_HTTP_REQUEST_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpRequestToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, httpRequestToLog, buffer, bufferSize)
#endif

View File

@ -399,13 +399,18 @@ httpResponseContent(HttpResponse *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
httpResponseToLog(const HttpResponse *this)
FN_EXTERN void
httpResponseToLog(const HttpResponse *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{code: %u, reason: %s, header: %s, contentChunked: %s, contentSize: %" PRIu64 ", contentRemaining: %" PRIu64
", closeOnContentEof: %s, contentExists: %s, contentEof: %s, contentCached: %s}",
httpResponseCode(this), strZ(httpResponseReason(this)), strZ(httpHeaderToLog(httpResponseHeader(this))),
cvtBoolToConstZ(this->contentChunked), this->contentSize, this->contentRemaining, cvtBoolToConstZ(this->closeOnContentEof),
cvtBoolToConstZ(this->contentExists), cvtBoolToConstZ(this->contentEof), cvtBoolToConstZ(this->content != NULL));
strStcFmt(
debugLog,
"{code: %u, reason: %s, contentChunked: %s, contentSize: %" PRIu64 ", contentRemaining: %" PRIu64 ", closeOnContentEof: %s"
", contentExists: %s, contentEof: %s, contentCached: %s}",
httpResponseCode(this), strZ(httpResponseReason(this)), cvtBoolToConstZ(this->contentChunked), this->contentSize,
this->contentRemaining, cvtBoolToConstZ(this->closeOnContentEof), cvtBoolToConstZ(this->contentExists),
cvtBoolToConstZ(this->contentEof), cvtBoolToConstZ(this->content != NULL));
strStcCat(debugLog, ", header: "),
httpHeaderToLog(httpResponseHeader(this), debugLog);
strStcCatChr(debugLog, '}');
}

View File

@ -101,11 +101,11 @@ httpResponseFree(HttpResponse *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *httpResponseToLog(const HttpResponse *this);
FN_EXTERN void httpResponseToLog(const HttpResponse *this, StringStatic *debugLog);
#define FUNCTION_LOG_HTTP_RESPONSE_TYPE \
HttpResponse *
#define FUNCTION_LOG_HTTP_RESPONSE_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpResponseToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, httpResponseToLog, buffer, bufferSize)
#endif

View File

@ -68,6 +68,6 @@ Macros for function logging
#define FUNCTION_LOG_HTTP_SESSION_TYPE \
HttpSession *
#define FUNCTION_LOG_HTTP_SESSION_FORMAT(value, buffer, bufferSize) \
objToLog(value, "HttpSession", buffer, bufferSize)
objNameToLog(value, "HttpSession", buffer, bufferSize)
#endif

View File

@ -197,15 +197,15 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param)
/**********************************************************************************************************************************/
#ifdef DEBUG
FN_EXTERN String *
httpUrlToLog(const HttpUrl *this)
FN_EXTERN void
httpUrlToLog(const HttpUrl *const this, StringStatic *const debugLog)
{
// Is IPv6 address?
bool ipv6 = strChr(this->pub.host, ':') != -1;
return strNewFmt(
"{%s://%s%s%s:%u%s}", strZ(httpProtocolTypeStr(this->pub.type)), ipv6 ? "[" : "", strZ(this->pub.host), ipv6 ? "]" : "",
this->pub.port, strZ(this->pub.path));
strStcFmt(
debugLog, "{%s://%s%s%s:%u%s}", strZ(httpProtocolTypeStr(this->pub.type)), ipv6 ? "[" : "", strZ(this->pub.host),
ipv6 ? "]" : "", this->pub.port, strZ(this->pub.path));
}
#endif // DEBUG

View File

@ -100,12 +100,12 @@ Macros for function logging
***********************************************************************************************************************************/
#ifdef DEBUG
FN_EXTERN String *httpUrlToLog(const HttpUrl *this);
FN_EXTERN void httpUrlToLog(const HttpUrl *this, StringStatic *debugLog);
#define FUNCTION_LOG_HTTP_URL_TYPE \
HttpUrl *
#define FUNCTION_LOG_HTTP_URL_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpUrlToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, httpUrlToLog, buffer, bufferSize)
#endif // DEBUG

View File

@ -103,6 +103,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_READ_TYPE \
IoRead *
#define FUNCTION_LOG_IO_READ_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoRead", buffer, bufferSize)
objNameToLog(value, "IoRead", buffer, bufferSize)
#endif

View File

@ -69,6 +69,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_READ_INTERFACE_TYPE \
IoReadInterface
#define FUNCTION_LOG_IO_READ_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoReadInterface", buffer, bufferSize)
objNameToLog(&value, "IoReadInterface", buffer, bufferSize)
#endif

View File

@ -48,9 +48,13 @@ ioServerNew(void *const driver, const IoServerInterface *const interface)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
ioServerToLog(const IoServer *const this)
FN_EXTERN void
ioServerToLog(const IoServer *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver)));
strStcCat(debugLog, "{type: ");
strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCat(debugLog, ", driver: ");
this->pub.interface->toLog(this->pub.driver, debugLog);
strStcCatChr(debugLog, '}');
}

View File

@ -62,11 +62,11 @@ ioServerFree(IoServer *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *ioServerToLog(const IoServer *this);
FN_EXTERN void ioServerToLog(const IoServer *this, StringStatic *debugLog);
#define FUNCTION_LOG_IO_SERVER_TYPE \
IoServer *
#define FUNCTION_LOG_IO_SERVER_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioServerToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, ioServerToLog, buffer, bufferSize)
#endif

View File

@ -23,7 +23,7 @@ typedef struct IoServerInterface
IoSession *(*accept)(void *driver, IoSession *session);
// Driver log function
String *(*toLog)(const void *driver);
void (*toLog)(const void *driver, StringStatic *debugLog);
} IoServerInterface;
/***********************************************************************************************************************************
@ -37,6 +37,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_SERVER_INTERFACE_TYPE \
IoServerInterface *
#define FUNCTION_LOG_IO_SERVER_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoServerInterface", buffer, bufferSize)
objNameToLog(&value, "IoServerInterface", buffer, bufferSize)
#endif

View File

@ -94,10 +94,16 @@ ioSessionPeerNameSet(IoSession *const this, const String *const peerName)
} // {vm_covered}
/**********************************************************************************************************************************/
FN_EXTERN String *
ioSessionToLog(const IoSession *this)
FN_EXTERN void
ioSessionToLog(const IoSession *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{type: %s, role: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(strIdToStr(ioSessionRole(this))),
strZ(this->pub.interface->toLog(this->pub.driver)));
strStcCat(debugLog, "{type: ");
strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCat(debugLog, ", role: ");
strStcResultSizeInc(debugLog, strIdToLog(ioSessionRole(this), strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCat(debugLog, ", driver: ");
this->pub.interface->toLog(this->pub.driver, debugLog);
strStcCatChr(debugLog, '}');
}

View File

@ -117,11 +117,11 @@ ioSessionFree(IoSession *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *ioSessionToLog(const IoSession *this);
FN_EXTERN void ioSessionToLog(const IoSession *this, StringStatic *debugLog);
#define FUNCTION_LOG_IO_SESSION_TYPE \
IoSession *
#define FUNCTION_LOG_IO_SESSION_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioSessionToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, ioSessionToLog, buffer, bufferSize)
#endif

View File

@ -31,7 +31,7 @@ typedef struct IoSessionInterface
IoSessionRole (*role)(const void *driver);
// Driver log function
String *(*toLog)(const void *driver);
void (*toLog)(const void *driver, StringStatic *debugLog);
} IoSessionInterface;
/***********************************************************************************************************************************
@ -54,6 +54,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_SESSION_INTERFACE_TYPE \
IoSessionInterface *
#define FUNCTION_LOG_IO_SESSION_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoSessionInterface", buffer, bufferSize)
objNameToLog(&value, "IoSessionInterface", buffer, bufferSize)
#endif

View File

@ -40,20 +40,20 @@ typedef struct SocketClient
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
sckClientToLog(const THIS_VOID)
static void
sckClientToLog(const THIS_VOID, StringStatic *const debugLog)
{
THIS(const SocketClient);
return strNewFmt(
"{host: %s, port: %u, timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 "}", strZ(this->host), this->port,
strStcFmt(
debugLog, "{host: %s, port: %u, timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 "}", strZ(this->host), this->port,
this->timeoutConnect, this->timeoutSession);
}
#define FUNCTION_LOG_SOCKET_CLIENT_TYPE \
SocketClient *
#define FUNCTION_LOG_SOCKET_CLIENT_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, sckClientToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, sckClientToLog, buffer, bufferSize)
/**********************************************************************************************************************************/
static IoSession *

View File

@ -40,18 +40,18 @@ typedef struct SocketServer
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
sckServerToLog(const THIS_VOID)
static void
sckServerToLog(const THIS_VOID, StringStatic *const debugLog)
{
THIS(const SocketServer);
return strNewFmt("{address: %s, port: %u, timeout: %" PRIu64 "}", strZ(this->address), this->port, this->timeout);
strStcFmt(debugLog, "{address: %s, port: %u, timeout: %" PRIu64 "}", strZ(this->address), this->port, this->timeout);
}
#define FUNCTION_LOG_SOCKET_SERVER_TYPE \
SocketServer *
#define FUNCTION_LOG_SOCKET_SERVER_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, sckServerToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, sckServerToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free connection

View File

@ -31,18 +31,19 @@ typedef struct SocketSession
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
sckSessionToLog(const THIS_VOID)
static void
sckSessionToLog(const THIS_VOID, StringStatic *const debugLog)
{
THIS(const SocketSession);
return strNewFmt("{fd %d, host: %s, port: %u, timeout: %" PRIu64 "}", this->fd, strZ(this->host), this->port, this->timeout);
strStcFmt(
debugLog, "{host: %s, port: %u, fd: %d, timeout: %" PRIu64 "}", strZ(this->host), this->port, this->fd, this->timeout);
}
#define FUNCTION_LOG_SOCKET_SESSION_TYPE \
SocketSession *
#define FUNCTION_LOG_SOCKET_SESSION_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, sckSessionToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, sckSessionToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free connection

View File

@ -41,20 +41,23 @@ typedef struct TlsClient
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
tlsClientToLog(const THIS_VOID)
static void
tlsClientToLog(const THIS_VOID, StringStatic *const debugLog)
{
THIS(const TlsClient);
return strNewFmt(
"{ioClient: %s, timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 ", verifyPeer: %s}",
strZ(ioClientToLog(this->ioClient)), this->timeoutConnect, this->timeoutSession, cvtBoolToConstZ(this->verifyPeer));
strStcCat(debugLog, "{ioClient: ");
ioClientToLog(this->ioClient, debugLog);
strStcFmt(
debugLog, ", timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 ", verifyPeer: %s}", this->timeoutConnect,
this->timeoutSession, cvtBoolToConstZ(this->verifyPeer));
}
#define FUNCTION_LOG_TLS_CLIENT_TYPE \
TlsClient *
#define FUNCTION_LOG_TLS_CLIENT_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, tlsClientToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, tlsClientToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free connection

View File

@ -39,18 +39,18 @@ typedef struct TlsServer
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
tlsServerToLog(const THIS_VOID)
static void
tlsServerToLog(const THIS_VOID, StringStatic *const debugLog)
{
THIS(const TlsServer);
return strNewFmt("{host: %s, timeout: %" PRIu64 "}", strZ(this->host), this->timeout);
strStcFmt(debugLog, "{host: %s, timeout: %" PRIu64 "}", strZ(this->host), this->timeout);
}
#define FUNCTION_LOG_TLS_SERVER_TYPE \
TlsServer *
#define FUNCTION_LOG_TLS_SERVER_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, tlsServerToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, tlsServerToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free context

View File

@ -34,20 +34,20 @@ typedef struct TlsSession
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
static String *
tlsSessionToLog(const THIS_VOID)
static void
tlsSessionToLog(const THIS_VOID, StringStatic *const debugLog)
{
THIS(const TlsSession);
return strNewFmt(
"{ioSession: %s, timeout: %" PRIu64", shutdownOnClose: %s}", strZ(ioSessionToLog(this->ioSession)), this->timeout,
cvtBoolToConstZ(this->shutdownOnClose));
strStcCat(debugLog, "{ioSession: ");
ioSessionToLog(this->ioSession, debugLog);
strStcFmt(debugLog, ", timeout: %" PRIu64", shutdownOnClose: %s}", this->timeout, cvtBoolToConstZ(this->shutdownOnClose));
}
#define FUNCTION_LOG_TLS_SESSION_TYPE \
TlsSession *
#define FUNCTION_LOG_TLS_SESSION_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, tlsSessionToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, tlsSessionToLog, buffer, bufferSize)
/***********************************************************************************************************************************
Free connection

View File

@ -91,6 +91,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_WRITE_TYPE \
IoWrite *
#define FUNCTION_LOG_IO_WRITE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "IoWrite", buffer, bufferSize)
objNameToLog(value, "IoWrite", buffer, bufferSize)
#endif

View File

@ -34,6 +34,6 @@ Macros for function logging
#define FUNCTION_LOG_IO_WRITE_INTERFACE_TYPE \
IoWriteInterface
#define FUNCTION_LOG_IO_WRITE_INTERFACE_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "IoWriteInterface", buffer, bufferSize)
objNameToLog(&value, "IoWriteInterface", buffer, bufferSize)
#endif

View File

@ -294,7 +294,7 @@ Macros for function logging
#define FUNCTION_LOG_MEM_CONTEXT_TYPE \
MemContext *
#define FUNCTION_LOG_MEM_CONTEXT_FORMAT(value, buffer, bufferSize) \
objToLog(value, "MemContext", buffer, bufferSize)
objNameToLog(value, "MemContext", buffer, bufferSize)
/***********************************************************************************************************************************
Internal functions

View File

@ -49,6 +49,6 @@ Macros for function logging
#define FUNCTION_LOG_REGEXP_TYPE \
RegExp *
#define FUNCTION_LOG_REGEXP_FORMAT(value, buffer, bufferSize) \
objToLog(value, "RegExp", buffer, bufferSize)
objNameToLog(value, "RegExp", buffer, bufferSize)
#endif

View File

@ -53,6 +53,6 @@ Macros for function logging
#define FUNCTION_LOG_BLOB_TYPE \
Blob *
#define FUNCTION_LOG_BLOB_FORMAT(value, buffer, bufferSize) \
objToLog(value, "Blob", buffer, bufferSize)
objNameToLog(value, "Blob", buffer, bufferSize)
#endif

View File

@ -345,12 +345,10 @@ bufUsedZero(Buffer *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
bufToLog(const Buffer *this)
FN_EXTERN void
bufToLog(const Buffer *const this, StringStatic *const debugLog)
{
String *result = strNewFmt(
"{used: %zu, size: %zu%s", bufUsed(this), bufSize(this),
bufSizeLimit(this) ? zNewFmt(", sizeAlloc: %zu}", bufSizeAlloc(this)) : "}");
return result;
strStcFmt(
debugLog, "{used: %zu, size: %zu%s", bufUsed(this), bufSize(this), bufSizeLimit(this) ? zNewFmt(", sizeAlloc: %zu}",
bufSizeAlloc(this)) : "}");
}

View File

@ -210,11 +210,11 @@ BUFFER_DECLARE(QUOTED_BUF);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *bufToLog(const Buffer *this);
FN_EXTERN void bufToLog(const Buffer *this, StringStatic *debugLog);
#define FUNCTION_LOG_BUFFER_TYPE \
Buffer *
#define FUNCTION_LOG_BUFFER_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, bufToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, bufToLog, buffer, bufferSize)
#endif

View File

@ -1301,10 +1301,10 @@ jsonValidate(const String *const json)
/**********************************************************************************************************************************/
#ifdef DEBUG
FN_EXTERN String *
jsonReadToLog(const JsonRead *const this)
FN_EXTERN void
jsonReadToLog(const JsonRead *const this, StringStatic *const debugLog)
{
return strNewFmt("{json: %s}", this->json);
strStcFmt(debugLog, "{json: %s}", this->json);
}
#endif // DEBUG
@ -2053,10 +2053,10 @@ jsonFromVar(const Variant *const value)
/**********************************************************************************************************************************/
#ifdef DEBUG
FN_EXTERN String *
jsonWriteToLog(const JsonWrite *const this)
FN_EXTERN void
jsonWriteToLog(const JsonWrite *const this, StringStatic *const debugLog)
{
return strNewFmt("{size: %zu}", strSize(this->json));
strStcFmt(debugLog, "{size: %zu}", strSize(this->json));
}
#endif // DEBUG

View File

@ -184,19 +184,19 @@ Macros for function logging
***********************************************************************************************************************************/
#ifdef DEBUG
FN_EXTERN String *jsonReadToLog(const JsonRead *this);
FN_EXTERN void jsonReadToLog(const JsonRead *this, StringStatic *debugLog);
#define FUNCTION_LOG_JSON_READ_TYPE \
JsonRead *
#define FUNCTION_LOG_JSON_READ_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, jsonReadToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, jsonReadToLog, buffer, bufferSize)
FN_EXTERN String *jsonWriteToLog(const JsonWrite *this);
FN_EXTERN void jsonWriteToLog(const JsonWrite *this, StringStatic *debugLog);
#define FUNCTION_LOG_JSON_WRITE_TYPE \
JsonWrite *
#define FUNCTION_LOG_JSON_WRITE_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, jsonWriteToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, jsonWriteToLog, buffer, bufferSize)
#endif // DEBUG

View File

@ -98,6 +98,6 @@ Macros for function logging
#define FUNCTION_LOG_KEY_VALUE_TYPE \
KeyValue *
#define FUNCTION_LOG_KEY_VALUE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "KeyValue", buffer, bufferSize)
objNameToLog(value, "KeyValue", buffer, bufferSize)
#endif

View File

@ -430,8 +430,8 @@ lstComparatorSet(List *this, ListComparator *comparator)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
lstToLog(const List *this)
FN_EXTERN void
lstToLog(const List *const this, StringStatic *const debugLog)
{
return strNewFmt("{size: %u}", lstSize(this));
strStcFmt(debugLog, "{size: %u}", lstSize(this));
}

View File

@ -158,11 +158,11 @@ lstFree(List *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *lstToLog(const List *this);
FN_EXTERN void lstToLog(const List *this, StringStatic *debugLog);
#define FUNCTION_LOG_LIST_TYPE \
List *
#define FUNCTION_LOG_LIST_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, lstToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, lstToLog, buffer, bufferSize)
#endif

View File

@ -1242,11 +1242,11 @@ pckReadEnd(PackRead *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
pckReadToLog(const PackRead *this)
FN_EXTERN void
pckReadToLog(const PackRead *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{depth: %u, idLast: %u, tagNextId: %u, tagNextType: %u, tagNextValue %" PRIu64 "}", this->tagStack.depth,
strStcFmt(
debugLog, "{depth: %u, idLast: %u, tagNextId: %u, tagNextType: %u, tagNextValue %" PRIu64 "}", this->tagStack.depth,
this->tagStack.top->idLast, this->tagNextId, this->tagNextTypeMap, this->tagNextValue);
}
@ -1946,8 +1946,9 @@ pckWriteResult(PackWrite *const this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
pckWriteToLog(const PackWrite *this)
FN_EXTERN void
pckWriteToLog(const PackWrite *const this, StringStatic *const debugLog)
{
return strNewFmt("{depth: %u, idLast: %u}", this->tagStack.depth, this->tagStack.top == NULL ? 0 : this->tagStack.top->idLast);
strStcFmt(
debugLog, "{depth: %u, idLast: %u}", this->tagStack.depth, this->tagStack.top == NULL ? 0 : this->tagStack.top->idLast);
}

View File

@ -661,20 +661,20 @@ Macros for function logging
#define FUNCTION_LOG_PACK_TYPE \
Pack *
#define FUNCTION_LOG_PACK_FORMAT(value, buffer, bufferSize) \
objToLog(value, "Pack", buffer, bufferSize)
objNameToLog(value, "Pack", buffer, bufferSize)
FN_EXTERN String *pckReadToLog(const PackRead *this);
FN_EXTERN void pckReadToLog(const PackRead *this, StringStatic *debugLog);
#define FUNCTION_LOG_PACK_READ_TYPE \
PackRead *
#define FUNCTION_LOG_PACK_READ_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pckReadToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, pckReadToLog, buffer, bufferSize)
FN_EXTERN String *pckWriteToLog(const PackWrite *this);
FN_EXTERN void pckWriteToLog(const PackWrite *this, StringStatic *debugLog);
#define FUNCTION_LOG_PACK_WRITE_TYPE \
PackWrite *
#define FUNCTION_LOG_PACK_WRITE_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pckWriteToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, pckWriteToLog, buffer, bufferSize)
#endif

View File

@ -998,27 +998,11 @@ strTruncIdx(String *this, int idx)
FUNCTION_TEST_RETURN(STRING, this);
}
/***********************************************************************************************************************************
Convert an object to a zero-terminated string for logging
***********************************************************************************************************************************/
FN_EXTERN size_t strObjToLog(const void *object, StrObjToLogFormat formatFunc, char *buffer, size_t bufferSize)
{
size_t result = 0;
MEM_CONTEXT_TEMP_BEGIN()
{
result = (size_t)snprintf(buffer, bufferSize, "%s", object == NULL ? NULL_Z : strZ(formatFunc(object)));
}
MEM_CONTEXT_TEMP_END();
return result;
}
/**********************************************************************************************************************************/
FN_EXTERN String *
strToLog(const String *this)
FN_EXTERN void
strToLog(const String *const this, StringStatic *const debugLog)
{
return this == NULL ? strDup(NULL_STR) : strNewFmt("{\"%s\"}", strZ(this));
strStcFmt(debugLog, "{\"%s\"}", strZ(this));
}
/**********************************************************************************************************************************/

View File

@ -23,6 +23,8 @@ old context and then back. Below is a simplified example:
#include <stdint.h>
#include "common/debug.h"
/***********************************************************************************************************************************
Minimum number of extra bytes to allocate for strings that are growing or are likely to grow
***********************************************************************************************************************************/
@ -258,24 +260,14 @@ STRING_DECLARE(TRUE_STR);
STRING_DECLARE(Y_STR);
STRING_DECLARE(ZERO_STR);
/***********************************************************************************************************************************
Helper function/macro for object logging
***********************************************************************************************************************************/
typedef String *(*StrObjToLogFormat)(const void *object);
FN_EXTERN size_t strObjToLog(const void *object, StrObjToLogFormat formatFunc, char *buffer, size_t bufferSize);
#define FUNCTION_LOG_STRING_OBJECT_FORMAT(object, formatFunc, buffer, bufferSize) \
strObjToLog(object, (StrObjToLogFormat)formatFunc, buffer, bufferSize)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *strToLog(const String *this);
FN_EXTERN void strToLog(const String *this, StringStatic *debugLog);
#define FUNCTION_LOG_STRING_TYPE \
String *
#define FUNCTION_LOG_STRING_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, strToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, strToLog, buffer, bufferSize)
#endif

View File

@ -93,7 +93,7 @@ FN_EXTERN size_t strIdToZ(const StringId strId, char *const buffer);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN size_t strIdToLog(const StringId strId, char *const buffer, const size_t bufferSize);
FN_EXTERN size_t strIdToLog(StringId strId, char *buffer, size_t bufferSize);
#define FUNCTION_LOG_STRING_ID_TYPE \
StringId

View File

@ -435,8 +435,23 @@ strLstPtr(const StringList *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
strLstToLog(const StringList *this)
FN_EXTERN void
strLstToLog(const StringList *const this, StringStatic *const debugLog)
{
return strNewFmt("{[%s]}", strZ(strLstJoinQuote(this, ", ", "\"")));
strStcCat(debugLog, "{[");
for (unsigned int strLstIdx = 0; strLstIdx < strLstSize(this); strLstIdx++)
{
const String *const value = strLstGet(this, strLstIdx);
if (strLstIdx != 0)
strStcCat(debugLog, ", ");
if (value == NULL)
strStcCat(debugLog, NULL_Z);
else
strStcFmt(debugLog, "\"%s\"", strZ(value));
}
strStcCat(debugLog, "]}");
}

View File

@ -174,11 +174,11 @@ strLstFree(StringList *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *strLstToLog(const StringList *this);
FN_EXTERN void strLstToLog(const StringList *this, StringStatic *debugLog);
#define FUNCTION_LOG_STRING_LIST_TYPE \
StringList *
#define FUNCTION_LOG_STRING_LIST_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, strLstToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, strLstToLog, buffer, bufferSize)
#endif

View File

@ -0,0 +1,61 @@
/***********************************************************************************************************************************
Static String Handler
***********************************************************************************************************************************/
#include "build.auto.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "common/type/stringStatic.h"
/**********************************************************************************************************************************/
FN_EXTERN StringStatic *
strStcFmt(StringStatic *const debugLog, const char *const format, ...)
{
// Proceed if there is space for at least one character
if (strStcRemainsSize(debugLog) > 1)
{
va_list argument;
va_start(argument, format);
size_t result = (size_t)vsnprintf(strStcRemains(debugLog), strStcRemainsSize(debugLog), format, argument);
va_end(argument);
if (result >= strStcRemainsSize(debugLog))
debugLog->resultSize = debugLog->bufferSize - 1;
else
debugLog->resultSize += result;
}
return debugLog;
}
/**********************************************************************************************************************************/
FN_EXTERN void
strStcCat(StringStatic *const debugLog, const char *const cat)
{
// Proceed if there is space for at least one character
const size_t remainsSize = strStcRemainsSize(debugLog);
if (remainsSize > 1)
{
const size_t catSize = strlen(cat);
const size_t resultSize = catSize > remainsSize - 1 ? remainsSize - 1 : catSize;
memcpy(strStcRemains(debugLog), cat, resultSize);
debugLog->resultSize += resultSize;
debugLog->buffer[debugLog->resultSize] = '\0';
}
}
/**********************************************************************************************************************************/
FN_EXTERN void
strStcCatChr(StringStatic *const debugLog, const char cat)
{
if (strStcRemainsSize(debugLog) > 1)
{
debugLog->buffer[debugLog->resultSize] = cat;
debugLog->buffer[++debugLog->resultSize] = '\0';
}
}

View File

@ -0,0 +1,75 @@
/***********************************************************************************************************************************
Static String Handler
Format a statically-size char buffer with automatic truncation and size tracking. These are convenience methods on top of the
built-in format and memcpy functions to make the interface simpler.
***********************************************************************************************************************************/
#ifndef COMMON_TYPE_STRINGSTATIC_H
#define COMMON_TYPE_STRINGSTATIC_H
#include <stddef.h>
/***********************************************************************************************************************************
Type
***********************************************************************************************************************************/
typedef struct StringStatic
{
char *buffer;
size_t bufferSize;
size_t resultSize;
} StringStatic;
/***********************************************************************************************************************************
Constructor
***********************************************************************************************************************************/
// Init static string
FN_INLINE_ALWAYS StringStatic
strStcInit(char *const buffer, const size_t bufferSize)
{
return (StringStatic){.buffer = buffer, .bufferSize = bufferSize};
}
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Cat formatted string to static string
FN_EXTERN StringStatic *strStcFmt(StringStatic *debugLog, const char *format, ...) __attribute__((format(printf, 2, 3)));
// Cat zero-terminated string to static string
FN_EXTERN void strStcCat(StringStatic *debugLog, const char *cat);
// Cat character to static string
FN_EXTERN void strStcCatChr(StringStatic *debugLog, char cat);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
// Pointer to remaining buffer
FN_INLINE_ALWAYS char *
strStcRemains(const StringStatic *const debugLog)
{
return debugLog->buffer + debugLog->resultSize;
}
// Remaining buffer size
FN_INLINE_ALWAYS size_t
strStcRemainsSize(const StringStatic *const debugLog)
{
return debugLog->bufferSize - debugLog->resultSize;
}
// Result size
FN_INLINE_ALWAYS size_t
strStcResultSize(const StringStatic *const debugLog)
{
return debugLog->resultSize;
}
// Increment result size
FN_INLINE_ALWAYS void
strStcResultSizeInc(StringStatic *const debugLog, const size_t inc)
{
debugLog->resultSize += inc;
}
#endif

View File

@ -1017,40 +1017,43 @@ varVarLst(const Variant *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
varToLog(const Variant *this)
FN_EXTERN void
varToLog(const Variant *const this, StringStatic *const debugLog)
{
String *result = NULL;
if (this == NULL)
result = strDup(NULL_STR);
else
switch (varType(this))
{
switch (varType(this))
{
case varTypeString:
result = strToLog(varStr(this));
break;
case varTypeString:
strStcResultSizeInc(
debugLog,
FUNCTION_LOG_OBJECT_FORMAT(varStr(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
break;
case varTypeKeyValue:
result = strNewZ("{KeyValue}");
break;
case varTypeKeyValue:
strStcCat(debugLog, "{KeyValue}");
break;
case varTypeVariantList:
result = strNewZ("{VariantList}");
break;
case varTypeVariantList:
strStcCat(debugLog, "{VariantList}");
break;
case varTypeBool:
case varTypeInt:
case varTypeInt64:
case varTypeUInt:
case varTypeUInt64:
{
result = strNewFmt("{%s}", strZ(varStrForce(this)));
break;
}
}
case varTypeBool:
strStcFmt(debugLog, "{%s}", cvtBoolToConstZ(varBool(this)));
break;
case varTypeInt:
strStcFmt(debugLog, "{%d}", varInt(this));
break;
case varTypeInt64:
strStcFmt(debugLog, "{%" PRId64 "}", varInt64(this));
break;
case varTypeUInt:
strStcFmt(debugLog, "{%u}", varUInt(this));
break;
case varTypeUInt64:
strStcFmt(debugLog, "{%" PRIu64 "}", varUInt64(this));
break;
}
return result;
}

View File

@ -220,11 +220,11 @@ VARIANT_DECLARE(BOOL_TRUE_VAR);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *varToLog(const Variant *this);
FN_EXTERN void varToLog(const Variant *this, StringStatic *debugLog);
#define FUNCTION_LOG_VARIANT_TYPE \
Variant *
#define FUNCTION_LOG_VARIANT_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, varToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, varToLog, buffer, bufferSize)
#endif

View File

@ -85,6 +85,6 @@ Macros for function logging
#define FUNCTION_LOG_VARIANT_LIST_TYPE \
VariantList *
#define FUNCTION_LOG_VARIANT_LIST_FORMAT(value, buffer, bufferSize) \
objToLog(value, "VariantList", buffer, bufferSize)
objNameToLog(value, "VariantList", buffer, bufferSize)
#endif

View File

@ -113,16 +113,16 @@ Macros for function logging
#define FUNCTION_LOG_XML_DOCUMENT_TYPE \
XmlDocument *
#define FUNCTION_LOG_XML_DOCUMENT_FORMAT(value, buffer, bufferSize) \
objToLog(value, "XmlDocument", buffer, bufferSize)
objNameToLog(value, "XmlDocument", buffer, bufferSize)
#define FUNCTION_LOG_XML_NODE_TYPE \
XmlNode *
#define FUNCTION_LOG_XML_NODE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "XmlNode", buffer, bufferSize)
objNameToLog(value, "XmlNode", buffer, bufferSize)
#define FUNCTION_LOG_XML_NODE_LIST_TYPE \
XmlNodeList *
#define FUNCTION_LOG_XML_NODE_LIST_FORMAT(value, buffer, bufferSize) \
objToLog(value, "XmlNodeList", buffer, bufferSize)
objNameToLog(value, "XmlNodeList", buffer, bufferSize)
#endif

View File

@ -53,6 +53,6 @@ Macros for function logging
#define FUNCTION_LOG_WAIT_TYPE \
Wait *
#define FUNCTION_LOG_WAIT_FORMAT(value, buffer, bufferSize) \
objToLog(value, "Wait", buffer, bufferSize)
objNameToLog(value, "Wait", buffer, bufferSize)
#endif

View File

@ -851,10 +851,17 @@ dbWalSwitch(Db *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
dbToLog(const Db *this)
FN_EXTERN void
dbToLog(const Db *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{client: %s, remoteClient: %s}", this->client == NULL ? NULL_Z : strZ(pgClientToLog(this->client)),
this->remoteClient == NULL ? NULL_Z : strZ(protocolClientToLog(this->remoteClient)));
strStcCat(debugLog, "{client: ");
strStcResultSizeInc(
debugLog, FUNCTION_LOG_OBJECT_FORMAT(this->client, pgClientToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCat(debugLog, ", remoteClient: ");
strStcResultSizeInc(
debugLog,
FUNCTION_LOG_OBJECT_FORMAT(
this->remoteClient, protocolClientToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strStcCatChr(debugLog, '}');
}

View File

@ -159,11 +159,11 @@ dbFree(Db *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *dbToLog(const Db *this);
FN_EXTERN void dbToLog(const Db *this, StringStatic *debugLog);
#define FUNCTION_LOG_DB_TYPE \
Db *
#define FUNCTION_LOG_DB_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, dbToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(value, dbToLog, buffer, bufferSize)
#endif

View File

@ -30,6 +30,6 @@ Macros for function logging
#define FUNCTION_LOG_DB_GET_RESULT_TYPE \
DbGetResult
#define FUNCTION_LOG_DB_GET_RESULT_FORMAT(value, buffer, bufferSize) \
objToLog(&value, "DbGetResult", buffer, bufferSize)
objNameToLog(&value, "DbGetResult", buffer, bufferSize)
#endif

View File

@ -89,11 +89,11 @@ Macros for function logging
#define FUNCTION_LOG_INFO_TYPE \
Info *
#define FUNCTION_LOG_INFO_FORMAT(value, buffer, bufferSize) \
objToLog(value, "Info", buffer, bufferSize)
objNameToLog(value, "Info", buffer, bufferSize)
#define FUNCTION_LOG_INFO_SAVE_TYPE \
InfoSave *
#define FUNCTION_LOG_INFO_SAVE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "InfoSave", buffer, bufferSize)
objNameToLog(value, "InfoSave", buffer, bufferSize)
#endif

View File

@ -106,6 +106,6 @@ Macros for function logging
#define FUNCTION_LOG_INFO_ARCHIVE_TYPE \
InfoArchive *
#define FUNCTION_LOG_INFO_ARCHIVE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "InfoArchive", buffer, bufferSize)
objNameToLog(value, "InfoArchive", buffer, bufferSize)
#endif

View File

@ -850,8 +850,8 @@ infoBackupSaveFile(
}
/**********************************************************************************************************************************/
FN_EXTERN String *
infoBackupDataToLog(const InfoBackupData *this)
FN_EXTERN void
infoBackupDataToLog(const InfoBackupData *const this, StringStatic *const debugLog)
{
return strNewFmt("{label: %s, pgId: %u}", strZ(this->backupLabel), this->backupPgId);
strStcFmt(debugLog, "{label: %s, pgId: %u}", strZ(this->backupLabel), this->backupPgId);
}

View File

@ -184,15 +184,15 @@ FN_EXTERN void infoBackupSaveFile(
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
FN_EXTERN String *infoBackupDataToLog(const InfoBackupData *this);
FN_EXTERN void infoBackupDataToLog(const InfoBackupData *this, StringStatic *debugLog);
#define FUNCTION_LOG_INFO_BACKUP_TYPE \
InfoBackup *
#define FUNCTION_LOG_INFO_BACKUP_FORMAT(value, buffer, bufferSize) \
objToLog(value, "InfoBackup", buffer, bufferSize)
objNameToLog(value, "InfoBackup", buffer, bufferSize)
#define FUNCTION_LOG_INFO_BACKUP_DATA_TYPE \
InfoBackupData
#define FUNCTION_LOG_INFO_BACKUP_DATA_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, infoBackupDataToLog, buffer, bufferSize)
FUNCTION_LOG_OBJECT_FORMAT(&value, infoBackupDataToLog, buffer, bufferSize)
#endif

View File

@ -456,10 +456,10 @@ infoPgCurrentDataId(const InfoPg *this)
}
/**********************************************************************************************************************************/
FN_EXTERN String *
infoPgDataToLog(const InfoPgData *this)
FN_EXTERN void
infoPgDataToLog(const InfoPgData *const this, StringStatic *const debugLog)
{
return strNewFmt(
"{id: %u, version: %u, systemId: %" PRIu64 ", catalogVersion: %u}", this->id, this->version, this->systemId,
strStcFmt(
debugLog, "{id: %u, version: %u, systemId: %" PRIu64 ", catalogVersion: %u}", this->id, this->version, this->systemId,
this->catalogVersion);
}

Some files were not shown because too many files have changed in this diff Show More