1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +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 \ #define FUNCTION_LOG_MY_OBJ_TYPE \
MyObj * MyObj *
#define FUNCTION_LOG_MY_OBJ_FORMAT(value, buffer, bufferSize) \ #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 * 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 \ #define FUNCTION_LOG_MY_OBJ_TYPE \
MyObj * MyObj *
#define FUNCTION_LOG_MY_OBJ_FORMAT(value, buffer, bufferSize) \ #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 * 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/list.c \
common/type/object.c \ common/type/object.c \
common/type/pack.c \ common/type/pack.c \
common/type/stringZ.c \
common/type/stringId.c \ common/type/stringId.c \
common/type/stringList.c \ common/type/stringList.c \
common/type/stringStatic.c \
common/type/stringZ.c \
common/type/variant.c \ common/type/variant.c \
common/type/variantList.c \ common/type/variantList.c \
common/user.c \ common/user.c \

View File

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

View File

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

View File

@ -35,16 +35,16 @@ typedef struct PageChecksum
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
pageChecksumToLog(const PageChecksum *this) 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 \ #define FUNCTION_LOG_PAGE_CHECKSUM_TYPE \
PageChecksum * PageChecksum *
#define FUNCTION_LOG_PAGE_CHECKSUM_FORMAT(value, buffer, bufferSize) \ #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 Count bytes in the input

View File

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

View File

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

View File

@ -42,12 +42,12 @@ Data Types and Structures
#define FUNCTION_LOG_VERIFY_ARCHIVE_RESULT_TYPE \ #define FUNCTION_LOG_VERIFY_ARCHIVE_RESULT_TYPE \
VerifyArchiveResult VerifyArchiveResult
#define FUNCTION_LOG_VERIFY_ARCHIVE_RESULT_FORMAT(value, buffer, bufferSize) \ #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 \ #define FUNCTION_LOG_VERIFY_BACKUP_RESULT_TYPE \
VerifyBackupResult VerifyBackupResult
#define FUNCTION_LOG_VERIFY_BACKUP_RESULT_FORMAT(value, buffer, bufferSize) \ #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 // Structure for verifying repository info files
typedef struct VerifyInfoFile typedef struct VerifyInfoFile

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,36 +8,53 @@ Debug Routines
#include "common/debug.h" #include "common/debug.h"
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN size_t FN_EXTERN size_t objToLog(const void *const object, ObjToLogFormat formatFunc, char *const buffer, const size_t bufferSize)
objToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize)
{ {
size_t result = 0; StringStatic debugLog = strStcInit(buffer, bufferSize);
if (object == NULL) if (object == NULL)
result = (size_t)snprintf(buffer, bufferSize, NULL_Z); strStcCat(&debugLog, NULL_Z);
else 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 FN_EXTERN size_t
ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t bufferSize) ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t bufferSize)
{ {
size_t result = 0; StringStatic debugLog = strStcInit(buffer, bufferSize);
if (pointer == NULL) if (pointer == NULL)
result = (size_t)snprintf(buffer, bufferSize, NULL_Z); strStcCat(&debugLog, NULL_Z);
else else
result = (size_t)snprintf(buffer, bufferSize, "(%s)", pointerName); strStcFmt(&debugLog, "(%s)", pointerName);
return result; return strStcResultSize(&debugLog);
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN size_t FN_EXTERN size_t
typeToLog(const char *typeName, char *buffer, size_t bufferSize) 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/assert.h"
#include "common/stackTrace.h" #include "common/stackTrace.h"
#include "common/type/convert.h" #include "common/type/convert.h"
#include "common/type/stringStatic.h"
#include "common/type/stringZ.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 Functions and macros to render various data types
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
// Convert object to a zero-terminated string for logging // 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 // 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); 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 \ #define FUNCTION_LOG_ERROR_TYPE_TYPE \
ErrorType * ErrorType *
#define FUNCTION_LOG_ERROR_TYPE_FORMAT(value, buffer, bufferSize) \ #define FUNCTION_LOG_ERROR_TYPE_FORMAT(value, buffer, bufferSize) \
objToLog(value, "ErrorType", buffer, bufferSize) objNameToLog(value, "ErrorType", buffer, bufferSize)
#endif #endif

View File

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

View File

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

View File

@ -26,7 +26,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_BUFFER_READ_TYPE \ #define FUNCTION_LOG_IO_BUFFER_READ_TYPE \
IoBufferRead * IoBufferRead *
#define FUNCTION_LOG_IO_BUFFER_READ_FORMAT(value, buffer, bufferSize) \ #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 Read data from the buffer

View File

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

View File

@ -47,9 +47,13 @@ ioClientNew(void *driver, const IoClientInterface *interface)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
ioClientToLog(const IoClient *this) ioClientToLog(const IoClient *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcCat(debugLog, "{type: ");
"{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver))); 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 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 \ #define FUNCTION_LOG_IO_CLIENT_TYPE \
IoClient * IoClient *
#define FUNCTION_LOG_IO_CLIENT_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

@ -29,7 +29,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_FD_READ_TYPE \ #define FUNCTION_LOG_IO_FD_READ_TYPE \
IoFdRead * IoFdRead *
#define FUNCTION_LOG_IO_FD_READ_FORMAT(value, buffer, bufferSize) \ #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? Are there bytes ready to read immediately?

View File

@ -28,7 +28,7 @@ Macros for function logging
#define FUNCTION_LOG_IO_FD_WRITE_TYPE \ #define FUNCTION_LOG_IO_FD_WRITE_TYPE \
IoFdWrite * IoFdWrite *
#define FUNCTION_LOG_IO_FD_WRITE_FORMAT(value, buffer, bufferSize) \ #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? // Can bytes be written immediately?

View File

@ -28,16 +28,16 @@ typedef struct IoBuffer
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static String * static void
ioBufferToLog(const IoBuffer *this) 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 \ #define FUNCTION_LOG_IO_BUFFER_TYPE \
IoBuffer * IoBuffer *
#define FUNCTION_LOG_IO_BUFFER_FORMAT(value, buffer, bufferSize) \ #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 Move data from the input buffer to the output buffer

View File

@ -154,8 +154,10 @@ ioFilterResult(const IoFilter *this)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
ioFilterToLog(const IoFilter *this) 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 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 \ #define FUNCTION_LOG_IO_FILTER_TYPE \
IoFilter * IoFilter *
#define FUNCTION_LOG_IO_FILTER_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

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

View File

@ -122,11 +122,11 @@ ioFilterGroupFree(IoFilterGroup *const this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging 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 \ #define FUNCTION_LOG_IO_FILTER_GROUP_TYPE \
IoFilterGroup * IoFilterGroup *
#define FUNCTION_LOG_IO_FILTER_GROUP_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

@ -23,16 +23,16 @@ typedef struct IoSize
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static String * static void
ioSizeToLog(const IoSize *this) 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 \ #define FUNCTION_LOG_IO_SIZE_TYPE \
IoSize * IoSize *
#define FUNCTION_LOG_IO_SIZE_FORMAT(value, buffer, bufferSize) \ #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 Count bytes in the input

View File

@ -115,10 +115,10 @@ httpClientReuse(HttpClient *this, HttpSession *session)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
httpClientToLog(const HttpClient *this) httpClientToLog(const HttpClient *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcCat(debugLog, "{ioClient: ");
"{ioClient: %s, reusable: %u, timeout: %" PRIu64"}", strZ(ioClientToLog(this->ioClient)), lstSize(this->sessionReuseList), ioClientToLog(this->ioClient, debugLog);
httpClientTimeout(this)); 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 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 \ #define FUNCTION_LOG_HTTP_CLIENT_TYPE \
HttpClient * HttpClient *
#define FUNCTION_LOG_HTTP_CLIENT_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

@ -202,26 +202,25 @@ httpHeaderRedact(const HttpHeader *this, const String *key)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
httpHeaderToLog(const HttpHeader *this) httpHeaderToLog(const HttpHeader *const this, StringStatic *const debugLog)
{ {
String *result = strCatZ(strNew(), "{"); const VariantList *const keyList = kvKeyList(this->kv);
const StringList *keyList = httpHeaderList(this);
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) if (keyIdx != 0)
strCatZ(result, ", "); strStcCat(debugLog, ", ");
if (httpHeaderRedact(this, key)) if (httpHeaderRedact(this, key))
strCatFmt(result, "%s: <redacted>", strZ(key)); strStcFmt(debugLog, "%s: <redacted>", strZ(key));
else else
strCatFmt(result, "%s: '%s'", strZ(key), strZ(httpHeaderGet(this, key))); strStcFmt(debugLog, "%s: '%s'", strZ(key), strZ(httpHeaderGet(this, key)));
} }
strCatZ(result, "}"); strStcCatChr(debugLog, '}');
return result;
} }

View File

@ -60,11 +60,11 @@ httpHeaderFree(HttpHeader *const this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging 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 \ #define FUNCTION_LOG_HTTP_HEADER_TYPE \
HttpHeader * HttpHeader *
#define FUNCTION_LOG_HTTP_HEADER_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

@ -288,28 +288,25 @@ httpQueryRender(const HttpQuery *this, HttpQueryRenderParam param)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
httpQueryToLog(const HttpQuery *this) httpQueryToLog(const HttpQuery *const this, StringStatic *const debugLog)
{ {
String *result = strCatZ(strNew(), "{"); const VariantList *const keyList = kvKeyList(this->kv);
const StringList *keyList = httpQueryList(this);
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) if (keyIdx != 0)
strCatZ(result, ", "); strStcCat(debugLog, ", ");
strCatFmt(result, "%s: ", strZ(key));
if (httpQueryRedact(this, key)) if (httpQueryRedact(this, key))
strCatZ(result, "<redacted>"); strStcFmt(debugLog, "%s: <redacted>", strZ(key));
else else
strCatFmt(result, "'%s'", strZ(httpQueryGet(this, key))); strStcFmt(debugLog, "%s: '%s'", strZ(key), strZ(httpQueryGet(this, key)));
} }
strCatZ(result, "}"); strStcCatChr(debugLog, '}');
return result;
} }

View File

@ -95,11 +95,11 @@ httpQueryFree(HttpQuery *const this)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging 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 \ #define FUNCTION_LOG_HTTP_QUERY_TYPE \
HttpQuery * HttpQuery *
#define FUNCTION_LOG_HTTP_QUERY_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

@ -302,11 +302,19 @@ httpRequestError(const HttpRequest *this, HttpResponse *response)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
httpRequestToLog(const HttpRequest *this) httpRequestToLog(const HttpRequest *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcFmt(
"{verb: %s, path: %s, query: %s, header: %s, contentSize: %zu}", strZ(httpRequestVerb(this)), strZ(httpRequestPath(this)), debugLog, "{verb: %s, path: %s, contentSize: %zu, query: ", strZ(httpRequestVerb(this)),
httpRequestQuery(this) == NULL ? "null" : strZ(httpQueryToLog(httpRequestQuery(this))), strZ(httpRequestPath(this)), this->content == NULL ? 0 : bufUsed(this->content));
strZ(httpHeaderToLog(httpRequestHeader(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 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 \ #define FUNCTION_LOG_HTTP_REQUEST_TYPE \
HttpRequest * HttpRequest *
#define FUNCTION_LOG_HTTP_REQUEST_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

@ -399,13 +399,18 @@ httpResponseContent(HttpResponse *this)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
httpResponseToLog(const HttpResponse *this) httpResponseToLog(const HttpResponse *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcFmt(
"{code: %u, reason: %s, header: %s, contentChunked: %s, contentSize: %" PRIu64 ", contentRemaining: %" PRIu64 debugLog,
", closeOnContentEof: %s, contentExists: %s, contentEof: %s, contentCached: %s}", "{code: %u, reason: %s, contentChunked: %s, contentSize: %" PRIu64 ", contentRemaining: %" PRIu64 ", closeOnContentEof: %s"
httpResponseCode(this), strZ(httpResponseReason(this)), strZ(httpHeaderToLog(httpResponseHeader(this))), ", contentExists: %s, contentEof: %s, contentCached: %s}",
cvtBoolToConstZ(this->contentChunked), this->contentSize, this->contentRemaining, cvtBoolToConstZ(this->closeOnContentEof), httpResponseCode(this), strZ(httpResponseReason(this)), cvtBoolToConstZ(this->contentChunked), this->contentSize,
cvtBoolToConstZ(this->contentExists), cvtBoolToConstZ(this->contentEof), cvtBoolToConstZ(this->content != NULL)); 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 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 \ #define FUNCTION_LOG_HTTP_RESPONSE_TYPE \
HttpResponse * HttpResponse *
#define FUNCTION_LOG_HTTP_RESPONSE_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

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

View File

@ -100,12 +100,12 @@ Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#ifdef DEBUG #ifdef DEBUG
FN_EXTERN String *httpUrlToLog(const HttpUrl *this); FN_EXTERN void httpUrlToLog(const HttpUrl *this, StringStatic *debugLog);
#define FUNCTION_LOG_HTTP_URL_TYPE \ #define FUNCTION_LOG_HTTP_URL_TYPE \
HttpUrl * HttpUrl *
#define FUNCTION_LOG_HTTP_URL_FORMAT(value, buffer, bufferSize) \ #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 #endif // DEBUG

View File

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

View File

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

View File

@ -48,9 +48,13 @@ ioServerNew(void *const driver, const IoServerInterface *const interface)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
ioServerToLog(const IoServer *const this) ioServerToLog(const IoServer *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcCat(debugLog, "{type: ");
"{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver))); 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 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 \ #define FUNCTION_LOG_IO_SERVER_TYPE \
IoServer * IoServer *
#define FUNCTION_LOG_IO_SERVER_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

@ -94,10 +94,16 @@ ioSessionPeerNameSet(IoSession *const this, const String *const peerName)
} // {vm_covered} } // {vm_covered}
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
ioSessionToLog(const IoSession *this) ioSessionToLog(const IoSession *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcCat(debugLog, "{type: ");
"{type: %s, role: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(strIdToStr(ioSessionRole(this))), strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
strZ(this->pub.interface->toLog(this->pub.driver)));
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 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 \ #define FUNCTION_LOG_IO_SESSION_TYPE \
IoSession * IoSession *
#define FUNCTION_LOG_IO_SESSION_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

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

View File

@ -40,18 +40,18 @@ typedef struct SocketServer
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static String * static void
sckServerToLog(const THIS_VOID) sckServerToLog(const THIS_VOID, StringStatic *const debugLog)
{ {
THIS(const SocketServer); 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 \ #define FUNCTION_LOG_SOCKET_SERVER_TYPE \
SocketServer * SocketServer *
#define FUNCTION_LOG_SOCKET_SERVER_FORMAT(value, buffer, bufferSize) \ #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 Free connection

View File

@ -31,18 +31,19 @@ typedef struct SocketSession
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static String * static void
sckSessionToLog(const THIS_VOID) sckSessionToLog(const THIS_VOID, StringStatic *const debugLog)
{ {
THIS(const SocketSession); 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 \ #define FUNCTION_LOG_SOCKET_SESSION_TYPE \
SocketSession * SocketSession *
#define FUNCTION_LOG_SOCKET_SESSION_FORMAT(value, buffer, bufferSize) \ #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 Free connection

View File

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

View File

@ -39,18 +39,18 @@ typedef struct TlsServer
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
static String * static void
tlsServerToLog(const THIS_VOID) tlsServerToLog(const THIS_VOID, StringStatic *const debugLog)
{ {
THIS(const TlsServer); 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 \ #define FUNCTION_LOG_TLS_SERVER_TYPE \
TlsServer * TlsServer *
#define FUNCTION_LOG_TLS_SERVER_FORMAT(value, buffer, bufferSize) \ #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 Free context

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -210,11 +210,11 @@ BUFFER_DECLARE(QUOTED_BUF);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging 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 \ #define FUNCTION_LOG_BUFFER_TYPE \
Buffer * Buffer *
#define FUNCTION_LOG_BUFFER_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

@ -184,19 +184,19 @@ Macros for function logging
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#ifdef DEBUG #ifdef DEBUG
FN_EXTERN String *jsonReadToLog(const JsonRead *this); FN_EXTERN void jsonReadToLog(const JsonRead *this, StringStatic *debugLog);
#define FUNCTION_LOG_JSON_READ_TYPE \ #define FUNCTION_LOG_JSON_READ_TYPE \
JsonRead * JsonRead *
#define FUNCTION_LOG_JSON_READ_FORMAT(value, buffer, bufferSize) \ #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 \ #define FUNCTION_LOG_JSON_WRITE_TYPE \
JsonWrite * JsonWrite *
#define FUNCTION_LOG_JSON_WRITE_FORMAT(value, buffer, bufferSize) \ #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 #endif // DEBUG

View File

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

View File

@ -430,8 +430,8 @@ lstComparatorSet(List *this, ListComparator *comparator)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
lstToLog(const List *this) 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 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 \ #define FUNCTION_LOG_LIST_TYPE \
List * List *
#define FUNCTION_LOG_LIST_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

@ -1242,11 +1242,11 @@ pckReadEnd(PackRead *this)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
pckReadToLog(const PackRead *this) pckReadToLog(const PackRead *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcFmt(
"{depth: %u, idLast: %u, tagNextId: %u, tagNextType: %u, tagNextValue %" PRIu64 "}", this->tagStack.depth, debugLog, "{depth: %u, idLast: %u, tagNextId: %u, tagNextType: %u, tagNextValue %" PRIu64 "}", this->tagStack.depth,
this->tagStack.top->idLast, this->tagNextId, this->tagNextTypeMap, this->tagNextValue); this->tagStack.top->idLast, this->tagNextId, this->tagNextTypeMap, this->tagNextValue);
} }
@ -1946,8 +1946,9 @@ pckWriteResult(PackWrite *const this)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
pckWriteToLog(const PackWrite *this) 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 \ #define FUNCTION_LOG_PACK_TYPE \
Pack * Pack *
#define FUNCTION_LOG_PACK_FORMAT(value, buffer, bufferSize) \ #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 \ #define FUNCTION_LOG_PACK_READ_TYPE \
PackRead * PackRead *
#define FUNCTION_LOG_PACK_READ_FORMAT(value, buffer, bufferSize) \ #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 \ #define FUNCTION_LOG_PACK_WRITE_TYPE \
PackWrite * PackWrite *
#define FUNCTION_LOG_PACK_WRITE_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

@ -998,27 +998,11 @@ strTruncIdx(String *this, int idx)
FUNCTION_TEST_RETURN(STRING, this); 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 * FN_EXTERN void
strToLog(const String *this) 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 <stdint.h>
#include "common/debug.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Minimum number of extra bytes to allocate for strings that are growing or are likely to grow 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(Y_STR);
STRING_DECLARE(ZERO_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 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 \ #define FUNCTION_LOG_STRING_TYPE \
String * String *
#define FUNCTION_LOG_STRING_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

@ -93,7 +93,7 @@ FN_EXTERN size_t strIdToZ(const StringId strId, char *const buffer);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging 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 \ #define FUNCTION_LOG_STRING_ID_TYPE \
StringId StringId

View File

@ -435,8 +435,23 @@ strLstPtr(const StringList *this)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
strLstToLog(const StringList *this) 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 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 \ #define FUNCTION_LOG_STRING_LIST_TYPE \
StringList * StringList *
#define FUNCTION_LOG_STRING_LIST_FORMAT(value, buffer, bufferSize) \ #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 #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 * FN_EXTERN void
varToLog(const Variant *this) 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: case varTypeString:
result = strToLog(varStr(this)); strStcResultSizeInc(
debugLog,
FUNCTION_LOG_OBJECT_FORMAT(varStr(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog)));
break; break;
case varTypeKeyValue: case varTypeKeyValue:
result = strNewZ("{KeyValue}"); strStcCat(debugLog, "{KeyValue}");
break; break;
case varTypeVariantList: case varTypeVariantList:
result = strNewZ("{VariantList}"); strStcCat(debugLog, "{VariantList}");
break; break;
case varTypeBool: case varTypeBool:
strStcFmt(debugLog, "{%s}", cvtBoolToConstZ(varBool(this)));
break;
case varTypeInt: case varTypeInt:
strStcFmt(debugLog, "{%d}", varInt(this));
break;
case varTypeInt64: case varTypeInt64:
strStcFmt(debugLog, "{%" PRId64 "}", varInt64(this));
break;
case varTypeUInt: case varTypeUInt:
strStcFmt(debugLog, "{%u}", varUInt(this));
break;
case varTypeUInt64: case varTypeUInt64:
{ strStcFmt(debugLog, "{%" PRIu64 "}", varUInt64(this));
result = strNewFmt("{%s}", strZ(varStrForce(this)));
break; break;
} }
}
}
return result;
} }

View File

@ -220,11 +220,11 @@ VARIANT_DECLARE(BOOL_TRUE_VAR);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Macros for function logging 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 \ #define FUNCTION_LOG_VARIANT_TYPE \
Variant * Variant *
#define FUNCTION_LOG_VARIANT_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

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

View File

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

View File

@ -851,10 +851,17 @@ dbWalSwitch(Db *this)
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
dbToLog(const Db *this) dbToLog(const Db *const this, StringStatic *const debugLog)
{ {
return strNewFmt( strStcCat(debugLog, "{client: ");
"{client: %s, remoteClient: %s}", this->client == NULL ? NULL_Z : strZ(pgClientToLog(this->client)), strStcResultSizeInc(
this->remoteClient == NULL ? NULL_Z : strZ(protocolClientToLog(this->remoteClient))); 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 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 \ #define FUNCTION_LOG_DB_TYPE \
Db * Db *
#define FUNCTION_LOG_DB_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

View File

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

View File

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

View File

@ -850,8 +850,8 @@ infoBackupSaveFile(
} }
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
FN_EXTERN String * FN_EXTERN void
infoBackupDataToLog(const InfoBackupData *this) 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 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 \ #define FUNCTION_LOG_INFO_BACKUP_TYPE \
InfoBackup * InfoBackup *
#define FUNCTION_LOG_INFO_BACKUP_FORMAT(value, buffer, bufferSize) \ #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 \ #define FUNCTION_LOG_INFO_BACKUP_DATA_TYPE \
InfoBackupData InfoBackupData
#define FUNCTION_LOG_INFO_BACKUP_DATA_FORMAT(value, buffer, bufferSize) \ #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 #endif

View File

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

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