diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 43c5afd31..b9a54eb60 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -108,7 +108,7 @@ myObjFree(MyObj *const this) #define FUNCTION_LOG_MY_OBJ_TYPE \ MyObj * #define FUNCTION_LOG_MY_OBJ_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize) /* * C FILE - see db.c for a more complete and actual implementation example diff --git a/doc/xml/contributing.xml b/doc/xml/contributing.xml index a2cefada9..5eccc8a16 100644 --- a/doc/xml/contributing.xml +++ b/doc/xml/contributing.xml @@ -214,7 +214,7 @@ myObjFree(MyObj *const this) #define FUNCTION_LOG_MY_OBJ_TYPE \ MyObj * #define FUNCTION_LOG_MY_OBJ_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, myObjToLog, buffer, bufferSize) /* * C FILE - see db.c for a more complete and actual implementation example diff --git a/src/Makefile.in b/src/Makefile.in index 03e2aae96..b9d1a36e9 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -31,9 +31,10 @@ SRCS_COMMON = \ common/type/list.c \ common/type/object.c \ common/type/pack.c \ - common/type/stringZ.c \ common/type/stringId.c \ common/type/stringList.c \ + common/type/stringStatic.c \ + common/type/stringZ.c \ common/type/variant.c \ common/type/variantList.c \ common/user.c \ diff --git a/src/build/common/yaml.h b/src/build/common/yaml.h index 410e98a9d..99d30610b 100644 --- a/src/build/common/yaml.h +++ b/src/build/common/yaml.h @@ -139,11 +139,11 @@ Macros for function logging #define FUNCTION_LOG_YAML_TYPE \ Yaml * #define FUNCTION_LOG_YAML_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Yaml", buffer, bufferSize) + objNameToLog(value, "Yaml", buffer, bufferSize) #define FUNCTION_LOG_YAML_EVENT_TYPE \ YamlEvent #define FUNCTION_LOG_YAML_EVENT_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "YamlEvent", buffer, bufferSize) + objNameToLog(&value, "YamlEvent", buffer, bufferSize) #endif diff --git a/src/command/backup/backup.c b/src/command/backup/backup.c index 9b398b11f..f21b2e39c 100644 --- a/src/command/backup/backup.c +++ b/src/command/backup/backup.c @@ -140,7 +140,7 @@ Get the postgres database and storage objects #define FUNCTION_LOG_BACKUP_DATA_TYPE \ BackupData * #define FUNCTION_LOG_BACKUP_DATA_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "BackupData", buffer, bufferSize) + objNameToLog(value, "BackupData", buffer, bufferSize) typedef struct BackupData { diff --git a/src/command/backup/pageChecksum.c b/src/command/backup/pageChecksum.c index 428a6fd6f..2d1f3e1e6 100644 --- a/src/command/backup/pageChecksum.c +++ b/src/command/backup/pageChecksum.c @@ -35,16 +35,16 @@ typedef struct PageChecksum /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String * -pageChecksumToLog(const PageChecksum *this) +FN_EXTERN void +pageChecksumToLog(const PageChecksum *const this, StringStatic *const debugLog) { - return strNewFmt("{valid: %s, align: %s}", cvtBoolToConstZ(this->valid), cvtBoolToConstZ(this->align)); + strStcFmt(debugLog, "{valid: %s, align: %s}", cvtBoolToConstZ(this->valid), cvtBoolToConstZ(this->align)); } #define FUNCTION_LOG_PAGE_CHECKSUM_TYPE \ PageChecksum * #define FUNCTION_LOG_PAGE_CHECKSUM_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pageChecksumToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, pageChecksumToLog, buffer, bufferSize) /*********************************************************************************************************************************** Count bytes in the input diff --git a/src/command/info/info.c b/src/command/info/info.c index da1dc9f5a..83446fe20 100644 --- a/src/command/info/info.c +++ b/src/command/info/info.c @@ -121,7 +121,7 @@ typedef struct InfoRepoData #define FUNCTION_LOG_INFO_REPO_DATA_TYPE \ InfoRepoData * #define FUNCTION_LOG_INFO_REPO_DATA_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "InfoRepoData", buffer, bufferSize) + objNameToLog(value, "InfoRepoData", buffer, bufferSize) // Stanza with repository list of information for each repository typedef struct InfoStanzaRepo @@ -138,7 +138,7 @@ typedef struct InfoStanzaRepo #define FUNCTION_LOG_INFO_STANZA_REPO_TYPE \ InfoStanzaRepo * #define FUNCTION_LOG_INFO_STANZA_REPO_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "InfoStanzaRepo", buffer, bufferSize) + objNameToLog(value, "InfoStanzaRepo", buffer, bufferSize) // Group all databases with the same system-id and version together regardless of db-id or repo typedef struct DbGroup @@ -154,7 +154,7 @@ typedef struct DbGroup #define FUNCTION_LOG_DB_GROUP_TYPE \ DbGroup * #define FUNCTION_LOG_DB_GROUP_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "DbGroup", buffer, bufferSize) + objNameToLog(value, "DbGroup", buffer, bufferSize) /*********************************************************************************************************************************** Helper function for reporting errors diff --git a/src/command/restore/restore.c b/src/command/restore/restore.c index 397d7e178..2a90a70b0 100644 --- a/src/command/restore/restore.c +++ b/src/command/restore/restore.c @@ -197,7 +197,7 @@ typedef struct RestoreBackupData #define FUNCTION_LOG_RESTORE_BACKUP_DATA_TYPE \ RestoreBackupData #define FUNCTION_LOG_RESTORE_BACKUP_DATA_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "RestoreBackupData", buffer, bufferSize) + objNameToLog(&value, "RestoreBackupData", buffer, bufferSize) // Helper function for restoreBackupSet static RestoreBackupData diff --git a/src/command/verify/verify.c b/src/command/verify/verify.c index 0bee7e423..e15690d83 100644 --- a/src/command/verify/verify.c +++ b/src/command/verify/verify.c @@ -42,12 +42,12 @@ Data Types and Structures #define FUNCTION_LOG_VERIFY_ARCHIVE_RESULT_TYPE \ VerifyArchiveResult #define FUNCTION_LOG_VERIFY_ARCHIVE_RESULT_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "VerifyArchiveResult", buffer, bufferSize) + objNameToLog(&value, "VerifyArchiveResult", buffer, bufferSize) #define FUNCTION_LOG_VERIFY_BACKUP_RESULT_TYPE \ VerifyBackupResult #define FUNCTION_LOG_VERIFY_BACKUP_RESULT_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "VerifyBackupResult", buffer, bufferSize) + objNameToLog(&value, "VerifyBackupResult", buffer, bufferSize) // Structure for verifying repository info files typedef struct VerifyInfoFile diff --git a/src/common/compress/bz2/compress.c b/src/common/compress/bz2/compress.c index 86075c3bf..30887c378 100644 --- a/src/common/compress/bz2/compress.c +++ b/src/common/compress/bz2/compress.c @@ -30,18 +30,18 @@ typedef struct Bz2Compress /*********************************************************************************************************************************** Render as string for logging ***********************************************************************************************************************************/ -static String * -bz2CompressToLog(const Bz2Compress *this) +static void +bz2CompressToLog(const Bz2Compress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{inputSame: %s, done: %s, flushing: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done), - cvtBoolToConstZ(this->flushing), this->stream.avail_in); + strStcFmt( + debugLog, "{inputSame: %s, done: %s, flushing: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame), + cvtBoolToConstZ(this->done), cvtBoolToConstZ(this->flushing), this->stream.avail_in); } #define FUNCTION_LOG_BZ2_COMPRESS_TYPE \ Bz2Compress * #define FUNCTION_LOG_BZ2_COMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, bz2CompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, bz2CompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free compression stream diff --git a/src/common/compress/bz2/decompress.c b/src/common/compress/bz2/decompress.c index 6fd4d9658..165698d58 100644 --- a/src/common/compress/bz2/decompress.c +++ b/src/common/compress/bz2/decompress.c @@ -29,18 +29,18 @@ typedef struct Bz2Decompress /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -bz2DecompressToLog(const Bz2Decompress *this) +static void +bz2DecompressToLog(const Bz2Decompress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{inputSame: %s, done: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done), + strStcFmt( + debugLog, "{inputSame: %s, done: %s, avail_in: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done), this->stream.avail_in); } #define FUNCTION_LOG_BZ2_DECOMPRESS_TYPE \ Bz2Decompress * #define FUNCTION_LOG_BZ2_DECOMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, bz2DecompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, bz2DecompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free inflate stream diff --git a/src/common/compress/gz/compress.c b/src/common/compress/gz/compress.c index eba5ab82f..bed20c164 100644 --- a/src/common/compress/gz/compress.c +++ b/src/common/compress/gz/compress.c @@ -30,18 +30,18 @@ typedef struct GzCompress /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -gzCompressToLog(const GzCompress *this) +static void +gzCompressToLog(const GzCompress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{inputSame: %s, done: %s, flushing: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done), - cvtBoolToConstZ(this->flushing), this->stream.avail_in); + strStcFmt( + debugLog, "{inputSame: %s, done: %s, flushing: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), + cvtBoolToConstZ(this->done), cvtBoolToConstZ(this->flushing), this->stream.avail_in); } #define FUNCTION_LOG_GZ_COMPRESS_TYPE \ GzCompress * #define FUNCTION_LOG_GZ_COMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, gzCompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, gzCompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Compression constants diff --git a/src/common/compress/gz/decompress.c b/src/common/compress/gz/decompress.c index cba0c6153..e18fe597a 100644 --- a/src/common/compress/gz/decompress.c +++ b/src/common/compress/gz/decompress.c @@ -29,18 +29,18 @@ typedef struct GzDecompress /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -gzDecompressToLog(const GzDecompress *this) +static void +gzDecompressToLog(const GzDecompress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{inputSame: %s, done: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done), + strStcFmt( + debugLog, "{inputSame: %s, done: %s, availIn: %u}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done), this->stream.avail_in); } #define FUNCTION_LOG_GZ_DECOMPRESS_TYPE \ GzDecompress * #define FUNCTION_LOG_GZ_DECOMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, gzDecompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, gzDecompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free inflate stream diff --git a/src/common/compress/lz4/compress.c b/src/common/compress/lz4/compress.c index f3140160b..a9a701478 100644 --- a/src/common/compress/lz4/compress.c +++ b/src/common/compress/lz4/compress.c @@ -44,18 +44,18 @@ typedef struct Lz4Compress /*********************************************************************************************************************************** Render as string for logging ***********************************************************************************************************************************/ -static String * -lz4CompressToLog(const Lz4Compress *this) +static void +lz4CompressToLog(const Lz4Compress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{level: %d, first: %s, inputSame: %s, flushing: %s}", this->prefs.compressionLevel, + strStcFmt( + debugLog, "{level: %d, first: %s, inputSame: %s, flushing: %s}", this->prefs.compressionLevel, cvtBoolToConstZ(this->first), cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->flushing)); } #define FUNCTION_LOG_LZ4_COMPRESS_TYPE \ Lz4Compress * #define FUNCTION_LOG_LZ4_COMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, lz4CompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, lz4CompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free compression context diff --git a/src/common/compress/lz4/decompress.c b/src/common/compress/lz4/decompress.c index f47ae3df0..d934b3296 100644 --- a/src/common/compress/lz4/decompress.c +++ b/src/common/compress/lz4/decompress.c @@ -32,18 +32,18 @@ typedef struct Lz4Decompress /*********************************************************************************************************************************** Render as string for logging ***********************************************************************************************************************************/ -static String * -lz4DecompressToLog(const Lz4Decompress *this) +static void +lz4DecompressToLog(const Lz4Decompress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame), this->inputOffset, - cvtBoolToConstZ(this->frameDone), cvtBoolToConstZ(this->done)); + strStcFmt( + debugLog, "{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame), + this->inputOffset, cvtBoolToConstZ(this->frameDone), cvtBoolToConstZ(this->done)); } #define FUNCTION_LOG_LZ4_DECOMPRESS_TYPE \ Lz4Decompress * #define FUNCTION_LOG_LZ4_DECOMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, lz4DecompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, lz4DecompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free decompression context diff --git a/src/common/compress/zst/compress.c b/src/common/compress/zst/compress.c index 4f8ee5672..868d079c0 100644 --- a/src/common/compress/zst/compress.c +++ b/src/common/compress/zst/compress.c @@ -32,18 +32,18 @@ typedef struct ZstCompress /*********************************************************************************************************************************** Render as string for logging ***********************************************************************************************************************************/ -static String * -zstCompressToLog(const ZstCompress *this) +static void +zstCompressToLog(const ZstCompress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{level: %d, inputSame: %s, inputOffset: %zu, flushing: %s}", this->level, cvtBoolToConstZ(this->inputSame), + strStcFmt( + debugLog, "{level: %d, inputSame: %s, inputOffset: %zu, flushing: %s}", this->level, cvtBoolToConstZ(this->inputSame), this->inputOffset, cvtBoolToConstZ(this->flushing)); } #define FUNCTION_LOG_ZST_COMPRESS_TYPE \ ZstCompress * #define FUNCTION_LOG_ZST_COMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, zstCompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, zstCompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free compression context diff --git a/src/common/compress/zst/decompress.c b/src/common/compress/zst/decompress.c index 2a1f09c49..d289fe075 100644 --- a/src/common/compress/zst/decompress.c +++ b/src/common/compress/zst/decompress.c @@ -31,18 +31,18 @@ typedef struct ZstDecompress /*********************************************************************************************************************************** Render as string for logging ***********************************************************************************************************************************/ -static String * -zstDecompressToLog(const ZstDecompress *this) +static void +zstDecompressToLog(const ZstDecompress *const this, StringStatic *const debugLog) { - return strNewFmt( - "{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame), this->inputOffset, + strStcFmt( + debugLog, "{inputSame: %s, inputOffset: %zu, frameDone %s, done: %s}", cvtBoolToConstZ(this->inputSame), this->inputOffset, cvtBoolToConstZ(this->frameDone), cvtBoolToConstZ(this->done)); } #define FUNCTION_LOG_ZST_DECOMPRESS_TYPE \ ZstDecompress * #define FUNCTION_LOG_ZST_DECOMPRESS_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, zstDecompressToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, zstDecompressToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free decompression context diff --git a/src/common/crypto/cipherBlock.c b/src/common/crypto/cipherBlock.c index a6971ebe0..522ab3b74 100644 --- a/src/common/crypto/cipherBlock.c +++ b/src/common/crypto/cipherBlock.c @@ -51,17 +51,16 @@ typedef struct CipherBlock /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String * -cipherBlockToLog(const CipherBlock *this) +FN_EXTERN void +cipherBlockToLog(const CipherBlock *const this, StringStatic *const debugLog) { - return strNewFmt( - "{inputSame: %s, done: %s}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done)); + strStcFmt(debugLog, "{inputSame: %s, done: %s}", cvtBoolToConstZ(this->inputSame), cvtBoolToConstZ(this->done)); } #define FUNCTION_LOG_CIPHER_BLOCK_TYPE \ CipherBlock * #define FUNCTION_LOG_CIPHER_BLOCK_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, cipherBlockToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, cipherBlockToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free cipher context diff --git a/src/common/crypto/hash.c b/src/common/crypto/hash.c index 36d97d96e..dbc788e9c 100644 --- a/src/common/crypto/hash.c +++ b/src/common/crypto/hash.c @@ -49,7 +49,7 @@ Macros for function logging #define FUNCTION_LOG_CRYPTO_HASH_TYPE \ CryptoHash * #define FUNCTION_LOG_CRYPTO_HASH_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "CryptoHash", buffer, bufferSize) + objNameToLog(value, "CryptoHash", buffer, bufferSize) /*********************************************************************************************************************************** Free hash context diff --git a/src/common/debug.c b/src/common/debug.c index 3e3d731c4..673940802 100644 --- a/src/common/debug.c +++ b/src/common/debug.c @@ -8,36 +8,53 @@ Debug Routines #include "common/debug.h" /**********************************************************************************************************************************/ -FN_EXTERN size_t -objToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize) +FN_EXTERN size_t objToLog(const void *const object, ObjToLogFormat formatFunc, char *const buffer, const size_t bufferSize) { - size_t result = 0; + StringStatic debugLog = strStcInit(buffer, bufferSize); if (object == NULL) - result = (size_t)snprintf(buffer, bufferSize, NULL_Z); + strStcCat(&debugLog, NULL_Z); else - result = (size_t)snprintf(buffer, bufferSize, "{%s}", objectName); + formatFunc(object, &debugLog); - return result; + return strStcResultSize(&debugLog); +} + +/**********************************************************************************************************************************/ +FN_EXTERN size_t +objNameToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize) +{ + StringStatic debugLog = strStcInit(buffer, bufferSize); + + if (object == NULL) + strStcCat(&debugLog, NULL_Z); + else + strStcFmt(&debugLog, "{%s}", objectName); + + return strStcResultSize(&debugLog); } /**********************************************************************************************************************************/ FN_EXTERN size_t ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t bufferSize) { - size_t result = 0; + StringStatic debugLog = strStcInit(buffer, bufferSize); if (pointer == NULL) - result = (size_t)snprintf(buffer, bufferSize, NULL_Z); + strStcCat(&debugLog, NULL_Z); else - result = (size_t)snprintf(buffer, bufferSize, "(%s)", pointerName); + strStcFmt(&debugLog, "(%s)", pointerName); - return result; + return strStcResultSize(&debugLog); } /**********************************************************************************************************************************/ FN_EXTERN size_t typeToLog(const char *typeName, char *buffer, size_t bufferSize) { - return (size_t)snprintf(buffer, bufferSize, "%s", typeName); + StringStatic debugLog = strStcInit(buffer, bufferSize); + + strStcFmt(&debugLog, "%s", typeName); + + return strStcResultSize(&debugLog); } diff --git a/src/common/debug.h b/src/common/debug.h index 523fe29b8..85094a128 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -7,6 +7,7 @@ Debug Routines #include "common/assert.h" #include "common/stackTrace.h" #include "common/type/convert.h" +#include "common/type/stringStatic.h" #include "common/type/stringZ.h" /*********************************************************************************************************************************** @@ -98,7 +99,15 @@ FUNCTION_LOG_VOID() is provided as a shortcut for functions that have no paramet Functions and macros to render various data types ***********************************************************************************************************************************/ // Convert object to a zero-terminated string for logging -FN_EXTERN size_t objToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize); +typedef void (*ObjToLogFormat)(const void *object, StringStatic *debugLog); + +FN_EXTERN size_t objToLog(const void *object, ObjToLogFormat formatFunc, char *buffer, size_t bufferSize); + +#define FUNCTION_LOG_OBJECT_FORMAT(object, formatFunc, buffer, bufferSize) \ + objToLog(object, (ObjToLogFormat)formatFunc, buffer, bufferSize) + +// Convert object name to a zero-terminated string for logging +FN_EXTERN size_t objNameToLog(const void *object, const char *objectName, char *buffer, size_t bufferSize); // Convert pointer to a zero-terminated string for logging FN_EXTERN size_t ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t bufferSize); diff --git a/src/common/error.h b/src/common/error.h index 2a82e4384..a32ce2810 100644 --- a/src/common/error.h +++ b/src/common/error.h @@ -355,6 +355,6 @@ Macros for function logging #define FUNCTION_LOG_ERROR_TYPE_TYPE \ ErrorType * #define FUNCTION_LOG_ERROR_TYPE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "ErrorType", buffer, bufferSize) + objNameToLog(value, "ErrorType", buffer, bufferSize) #endif diff --git a/src/common/exec.h b/src/common/exec.h index cbecb9cc1..f21808d56 100644 --- a/src/common/exec.h +++ b/src/common/exec.h @@ -75,6 +75,6 @@ Macros for function logging #define FUNCTION_LOG_EXEC_TYPE \ Exec * #define FUNCTION_LOG_EXEC_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Exec", buffer, bufferSize) + objNameToLog(value, "Exec", buffer, bufferSize) #endif diff --git a/src/common/ini.h b/src/common/ini.h index fa637b112..aba06e6c5 100644 --- a/src/common/ini.h +++ b/src/common/ini.h @@ -76,6 +76,6 @@ Macros for function logging #define FUNCTION_LOG_INI_TYPE \ Ini * #define FUNCTION_LOG_INI_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Ini", buffer, bufferSize) + objNameToLog(value, "Ini", buffer, bufferSize) #endif diff --git a/src/common/io/bufferRead.c b/src/common/io/bufferRead.c index 14df7399c..3e81a3771 100644 --- a/src/common/io/bufferRead.c +++ b/src/common/io/bufferRead.c @@ -26,7 +26,7 @@ Macros for function logging #define FUNCTION_LOG_IO_BUFFER_READ_TYPE \ IoBufferRead * #define FUNCTION_LOG_IO_BUFFER_READ_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoBufferRead", buffer, bufferSize) + objNameToLog(value, "IoBufferRead", buffer, bufferSize) /*********************************************************************************************************************************** Read data from the buffer diff --git a/src/common/io/bufferWrite.c b/src/common/io/bufferWrite.c index cddfbe15a..fb5825a35 100644 --- a/src/common/io/bufferWrite.c +++ b/src/common/io/bufferWrite.c @@ -23,7 +23,7 @@ Macros for function logging #define FUNCTION_LOG_IO_BUFFER_WRITE_TYPE \ IoBufferWrite * #define FUNCTION_LOG_IO_BUFFER_WRITE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoBufferWrite", buffer, bufferSize) + objNameToLog(value, "IoBufferWrite", buffer, bufferSize) /*********************************************************************************************************************************** Write to the buffer diff --git a/src/common/io/client.c b/src/common/io/client.c index 65fe45f30..c18211740 100644 --- a/src/common/io/client.c +++ b/src/common/io/client.c @@ -47,9 +47,13 @@ ioClientNew(void *driver, const IoClientInterface *interface) } /**********************************************************************************************************************************/ -FN_EXTERN String * -ioClientToLog(const IoClient *this) +FN_EXTERN void +ioClientToLog(const IoClient *const this, StringStatic *const debugLog) { - return strNewFmt( - "{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver))); + strStcCat(debugLog, "{type: "); + strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", driver: "); + this->pub.interface->toLog(this->pub.driver, debugLog); + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/client.h b/src/common/io/client.h index 687560e9d..121196f1c 100644 --- a/src/common/io/client.h +++ b/src/common/io/client.h @@ -62,11 +62,11 @@ ioClientFree(IoClient *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *ioClientToLog(const IoClient *this); +FN_EXTERN void ioClientToLog(const IoClient *this, StringStatic *debugLog); #define FUNCTION_LOG_IO_CLIENT_TYPE \ IoClient * #define FUNCTION_LOG_IO_CLIENT_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioClientToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, ioClientToLog, buffer, bufferSize) #endif diff --git a/src/common/io/client.intern.h b/src/common/io/client.intern.h index 0478364ba..2c373270e 100644 --- a/src/common/io/client.intern.h +++ b/src/common/io/client.intern.h @@ -23,7 +23,7 @@ typedef struct IoClientInterface IoSession *(*open)(void *driver); // Driver log function - String *(*toLog)(const void *driver); + void (*toLog)(const void *driver, StringStatic *debugLog); } IoClientInterface; /*********************************************************************************************************************************** @@ -37,6 +37,6 @@ Macros for function logging #define FUNCTION_LOG_IO_CLIENT_INTERFACE_TYPE \ IoClientInterface * #define FUNCTION_LOG_IO_CLIENT_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "IoClientInterface", buffer, bufferSize) + objNameToLog(&value, "IoClientInterface", buffer, bufferSize) #endif diff --git a/src/common/io/fdRead.c b/src/common/io/fdRead.c index ddde2a760..564e3bbe6 100644 --- a/src/common/io/fdRead.c +++ b/src/common/io/fdRead.c @@ -29,7 +29,7 @@ Macros for function logging #define FUNCTION_LOG_IO_FD_READ_TYPE \ IoFdRead * #define FUNCTION_LOG_IO_FD_READ_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoFdRead", buffer, bufferSize) + objNameToLog(value, "IoFdRead", buffer, bufferSize) /*********************************************************************************************************************************** Are there bytes ready to read immediately? diff --git a/src/common/io/fdWrite.c b/src/common/io/fdWrite.c index f2eb75f9e..b71e647d3 100644 --- a/src/common/io/fdWrite.c +++ b/src/common/io/fdWrite.c @@ -28,7 +28,7 @@ Macros for function logging #define FUNCTION_LOG_IO_FD_WRITE_TYPE \ IoFdWrite * #define FUNCTION_LOG_IO_FD_WRITE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoFdWrite", buffer, bufferSize) + objNameToLog(value, "IoFdWrite", buffer, bufferSize) /*********************************************************************************************************************************** // Can bytes be written immediately? diff --git a/src/common/io/filter/buffer.c b/src/common/io/filter/buffer.c index 9220361bb..c7b4c2fe1 100644 --- a/src/common/io/filter/buffer.c +++ b/src/common/io/filter/buffer.c @@ -28,16 +28,16 @@ typedef struct IoBuffer /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -ioBufferToLog(const IoBuffer *this) +static void +ioBufferToLog(const IoBuffer *const this, StringStatic *const debugLog) { - return strNewFmt("{inputSame: %s, inputPos: %zu}", cvtBoolToConstZ(this->inputSame), this->inputPos); + strStcFmt(debugLog, "{inputSame: %s, inputPos: %zu}", cvtBoolToConstZ(this->inputSame), this->inputPos); } #define FUNCTION_LOG_IO_BUFFER_TYPE \ IoBuffer * #define FUNCTION_LOG_IO_BUFFER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioBufferToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, ioBufferToLog, buffer, bufferSize) /*********************************************************************************************************************************** Move data from the input buffer to the output buffer diff --git a/src/common/io/filter/filter.c b/src/common/io/filter/filter.c index fcadd8359..6c1bff42a 100644 --- a/src/common/io/filter/filter.c +++ b/src/common/io/filter/filter.c @@ -154,8 +154,10 @@ ioFilterResult(const IoFilter *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -ioFilterToLog(const IoFilter *this) +FN_EXTERN void +ioFilterToLog(const IoFilter *const this, StringStatic *const debugLog) { - return strNewFmt("{type: %s}", strZ(strIdToStr(ioFilterType(this)))); + strStcCat(debugLog, "{type: "); + strStcResultSizeInc(debugLog, strIdToLog(ioFilterType(this), strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/filter/filter.h b/src/common/io/filter/filter.h index 6ab21c6af..c75994cba 100644 --- a/src/common/io/filter/filter.h +++ b/src/common/io/filter/filter.h @@ -45,11 +45,11 @@ ioFilterFree(IoFilter *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *ioFilterToLog(const IoFilter *this); +FN_EXTERN void ioFilterToLog(const IoFilter *this, StringStatic *debugLog); #define FUNCTION_LOG_IO_FILTER_TYPE \ IoFilter * #define FUNCTION_LOG_IO_FILTER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioFilterToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, ioFilterToLog, buffer, bufferSize) #endif diff --git a/src/common/io/filter/filter.intern.h b/src/common/io/filter/filter.intern.h index b3b922e85..e073e833d 100644 --- a/src/common/io/filter/filter.intern.h +++ b/src/common/io/filter/filter.intern.h @@ -125,6 +125,6 @@ Macros for function logging #define FUNCTION_LOG_IO_FILTER_INTERFACE_TYPE \ IoFilterInterface * #define FUNCTION_LOG_IO_FILTER_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "IoFilterInterface", buffer, bufferSize) + objNameToLog(&value, "IoFilterInterface", buffer, bufferSize) #endif diff --git a/src/common/io/filter/group.c b/src/common/io/filter/group.c index e316bbdb2..8ea1f2f04 100644 --- a/src/common/io/filter/group.c +++ b/src/common/io/filter/group.c @@ -30,7 +30,7 @@ typedef struct IoFilterData #define FUNCTION_LOG_IO_FILTER_DATA_TYPE \ IoFilterData * #define FUNCTION_LOG_IO_FILTER_DATA_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoFilterData", buffer, bufferSize) + objNameToLog(value, "IoFilterData", buffer, bufferSize) /*********************************************************************************************************************************** Filter results @@ -544,10 +544,11 @@ ioFilterGroupResultAllSet(IoFilterGroup *const this, const Pack *const filterRes } /**********************************************************************************************************************************/ -FN_EXTERN String * -ioFilterGroupToLog(const IoFilterGroup *this) +FN_EXTERN void +ioFilterGroupToLog(const IoFilterGroup *const this, StringStatic *const debugLog) { - return strNewFmt( + strStcFmt( + debugLog, "{inputSame: %s, done: %s" #ifdef DEBUG ", opened %s, flushing %s, closed %s" diff --git a/src/common/io/filter/group.h b/src/common/io/filter/group.h index ecccda18b..54e21a08d 100644 --- a/src/common/io/filter/group.h +++ b/src/common/io/filter/group.h @@ -122,11 +122,11 @@ ioFilterGroupFree(IoFilterGroup *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *ioFilterGroupToLog(const IoFilterGroup *this); +FN_EXTERN void ioFilterGroupToLog(const IoFilterGroup *this, StringStatic *debugLog); #define FUNCTION_LOG_IO_FILTER_GROUP_TYPE \ IoFilterGroup * #define FUNCTION_LOG_IO_FILTER_GROUP_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioFilterGroupToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, ioFilterGroupToLog, buffer, bufferSize) #endif diff --git a/src/common/io/filter/sink.c b/src/common/io/filter/sink.c index 0a88f1688..d906c1e80 100644 --- a/src/common/io/filter/sink.c +++ b/src/common/io/filter/sink.c @@ -23,7 +23,7 @@ Macros for function logging #define FUNCTION_LOG_IO_SINK_TYPE \ IoSink * #define FUNCTION_LOG_IO_SINK_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoSink", buffer, bufferSize) + objNameToLog(value, "IoSink", buffer, bufferSize) /*********************************************************************************************************************************** Discard all input diff --git a/src/common/io/filter/size.c b/src/common/io/filter/size.c index 9d32907b6..c3f99fa56 100644 --- a/src/common/io/filter/size.c +++ b/src/common/io/filter/size.c @@ -23,16 +23,16 @@ typedef struct IoSize /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -ioSizeToLog(const IoSize *this) +static void +ioSizeToLog(const IoSize *const this, StringStatic *const debugLog) { - return strNewFmt("{size: %" PRIu64 "}", this->size); + strStcFmt(debugLog, "{size: %" PRIu64 "}", this->size); } #define FUNCTION_LOG_IO_SIZE_TYPE \ IoSize * #define FUNCTION_LOG_IO_SIZE_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioSizeToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, ioSizeToLog, buffer, bufferSize) /*********************************************************************************************************************************** Count bytes in the input diff --git a/src/common/io/http/client.c b/src/common/io/http/client.c index 92fcc548b..209fccd03 100644 --- a/src/common/io/http/client.c +++ b/src/common/io/http/client.c @@ -115,10 +115,10 @@ httpClientReuse(HttpClient *this, HttpSession *session) } /**********************************************************************************************************************************/ -FN_EXTERN String * -httpClientToLog(const HttpClient *this) +FN_EXTERN void +httpClientToLog(const HttpClient *const this, StringStatic *const debugLog) { - return strNewFmt( - "{ioClient: %s, reusable: %u, timeout: %" PRIu64"}", strZ(ioClientToLog(this->ioClient)), lstSize(this->sessionReuseList), - httpClientTimeout(this)); + strStcCat(debugLog, "{ioClient: "); + ioClientToLog(this->ioClient, debugLog); + strStcFmt(debugLog, ", reusable: %u, timeout: %" PRIu64 "}", lstSize(this->sessionReuseList), httpClientTimeout(this)); } diff --git a/src/common/io/http/client.h b/src/common/io/http/client.h index c2a19512a..9a1ed817d 100644 --- a/src/common/io/http/client.h +++ b/src/common/io/http/client.h @@ -70,11 +70,11 @@ FN_EXTERN void httpClientReuse(HttpClient *this, HttpSession *session); /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *httpClientToLog(const HttpClient *this); +FN_EXTERN void httpClientToLog(const HttpClient *this, StringStatic *debugLog); #define FUNCTION_LOG_HTTP_CLIENT_TYPE \ HttpClient * #define FUNCTION_LOG_HTTP_CLIENT_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpClientToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, httpClientToLog, buffer, bufferSize) #endif diff --git a/src/common/io/http/header.c b/src/common/io/http/header.c index 96d9eef27..03ec79e04 100644 --- a/src/common/io/http/header.c +++ b/src/common/io/http/header.c @@ -202,26 +202,25 @@ httpHeaderRedact(const HttpHeader *this, const String *key) } /**********************************************************************************************************************************/ -FN_EXTERN String * -httpHeaderToLog(const HttpHeader *this) +FN_EXTERN void +httpHeaderToLog(const HttpHeader *const this, StringStatic *const debugLog) { - String *result = strCatZ(strNew(), "{"); - const StringList *keyList = httpHeaderList(this); + const VariantList *const keyList = kvKeyList(this->kv); - for (unsigned int keyIdx = 0; keyIdx < strLstSize(keyList); keyIdx++) + strStcCatChr(debugLog, '{'); + + for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++) { - const String *key = strLstGet(keyList, keyIdx); + const String *const key = varStr(varLstGet(keyList, keyIdx)); - if (strSize(result) != 1) - strCatZ(result, ", "); + if (keyIdx != 0) + strStcCat(debugLog, ", "); if (httpHeaderRedact(this, key)) - strCatFmt(result, "%s: ", strZ(key)); + strStcFmt(debugLog, "%s: ", strZ(key)); else - strCatFmt(result, "%s: '%s'", strZ(key), strZ(httpHeaderGet(this, key))); + strStcFmt(debugLog, "%s: '%s'", strZ(key), strZ(httpHeaderGet(this, key))); } - strCatZ(result, "}"); - - return result; + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/http/header.h b/src/common/io/http/header.h index b17dcbc89..e4f6d1f27 100644 --- a/src/common/io/http/header.h +++ b/src/common/io/http/header.h @@ -60,11 +60,11 @@ httpHeaderFree(HttpHeader *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *httpHeaderToLog(const HttpHeader *this); +FN_EXTERN void httpHeaderToLog(const HttpHeader *this, StringStatic *debugLog); #define FUNCTION_LOG_HTTP_HEADER_TYPE \ HttpHeader * #define FUNCTION_LOG_HTTP_HEADER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpHeaderToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, httpHeaderToLog, buffer, bufferSize) #endif diff --git a/src/common/io/http/query.c b/src/common/io/http/query.c index 349fdaaaf..0c9806492 100644 --- a/src/common/io/http/query.c +++ b/src/common/io/http/query.c @@ -288,28 +288,25 @@ httpQueryRender(const HttpQuery *this, HttpQueryRenderParam param) } /**********************************************************************************************************************************/ -FN_EXTERN String * -httpQueryToLog(const HttpQuery *this) +FN_EXTERN void +httpQueryToLog(const HttpQuery *const this, StringStatic *const debugLog) { - String *result = strCatZ(strNew(), "{"); - const StringList *keyList = httpQueryList(this); + const VariantList *const keyList = kvKeyList(this->kv); - for (unsigned int keyIdx = 0; keyIdx < strLstSize(keyList); keyIdx++) + strStcCatChr(debugLog, '{'); + + for (unsigned int keyIdx = 0; keyIdx < varLstSize(keyList); keyIdx++) { - const String *key = strLstGet(keyList, keyIdx); + const String *const key = varStr(varLstGet(keyList, keyIdx)); - if (strSize(result) != 1) - strCatZ(result, ", "); - - strCatFmt(result, "%s: ", strZ(key)); + if (keyIdx != 0) + strStcCat(debugLog, ", "); if (httpQueryRedact(this, key)) - strCatZ(result, ""); + strStcFmt(debugLog, "%s: ", strZ(key)); else - strCatFmt(result, "'%s'", strZ(httpQueryGet(this, key))); + strStcFmt(debugLog, "%s: '%s'", strZ(key), strZ(httpQueryGet(this, key))); } - strCatZ(result, "}"); - - return result; + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/http/query.h b/src/common/io/http/query.h index 6e041cc1d..92efbc014 100644 --- a/src/common/io/http/query.h +++ b/src/common/io/http/query.h @@ -95,11 +95,11 @@ httpQueryFree(HttpQuery *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *httpQueryToLog(const HttpQuery *this); +FN_EXTERN void httpQueryToLog(const HttpQuery *this, StringStatic *debugLog); #define FUNCTION_LOG_HTTP_QUERY_TYPE \ HttpQuery * #define FUNCTION_LOG_HTTP_QUERY_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpQueryToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, httpQueryToLog, buffer, bufferSize) #endif diff --git a/src/common/io/http/request.c b/src/common/io/http/request.c index 27343cb55..83a869048 100644 --- a/src/common/io/http/request.c +++ b/src/common/io/http/request.c @@ -302,11 +302,19 @@ httpRequestError(const HttpRequest *this, HttpResponse *response) } /**********************************************************************************************************************************/ -FN_EXTERN String * -httpRequestToLog(const HttpRequest *this) +FN_EXTERN void +httpRequestToLog(const HttpRequest *const this, StringStatic *const debugLog) { - return strNewFmt( - "{verb: %s, path: %s, query: %s, header: %s, contentSize: %zu}", strZ(httpRequestVerb(this)), strZ(httpRequestPath(this)), - httpRequestQuery(this) == NULL ? "null" : strZ(httpQueryToLog(httpRequestQuery(this))), - strZ(httpHeaderToLog(httpRequestHeader(this))), this->content == NULL ? 0 : bufUsed(this->content)); + strStcFmt( + debugLog, "{verb: %s, path: %s, contentSize: %zu, query: ", strZ(httpRequestVerb(this)), + strZ(httpRequestPath(this)), this->content == NULL ? 0 : bufUsed(this->content)); + + strStcResultSizeInc( + debugLog, + FUNCTION_LOG_OBJECT_FORMAT( + httpRequestQuery(this), httpQueryToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", header: "), + httpHeaderToLog(httpRequestHeader(this), debugLog); + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/http/request.h b/src/common/io/http/request.h index a06b410dc..9cd1240fe 100644 --- a/src/common/io/http/request.h +++ b/src/common/io/http/request.h @@ -149,11 +149,11 @@ httpRequestFree(HttpRequest *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *httpRequestToLog(const HttpRequest *this); +FN_EXTERN void httpRequestToLog(const HttpRequest *this, StringStatic *debugLog); #define FUNCTION_LOG_HTTP_REQUEST_TYPE \ HttpRequest * #define FUNCTION_LOG_HTTP_REQUEST_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpRequestToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, httpRequestToLog, buffer, bufferSize) #endif diff --git a/src/common/io/http/response.c b/src/common/io/http/response.c index d5577da27..a2957c387 100644 --- a/src/common/io/http/response.c +++ b/src/common/io/http/response.c @@ -399,13 +399,18 @@ httpResponseContent(HttpResponse *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -httpResponseToLog(const HttpResponse *this) +FN_EXTERN void +httpResponseToLog(const HttpResponse *const this, StringStatic *const debugLog) { - return strNewFmt( - "{code: %u, reason: %s, header: %s, contentChunked: %s, contentSize: %" PRIu64 ", contentRemaining: %" PRIu64 - ", closeOnContentEof: %s, contentExists: %s, contentEof: %s, contentCached: %s}", - httpResponseCode(this), strZ(httpResponseReason(this)), strZ(httpHeaderToLog(httpResponseHeader(this))), - cvtBoolToConstZ(this->contentChunked), this->contentSize, this->contentRemaining, cvtBoolToConstZ(this->closeOnContentEof), - cvtBoolToConstZ(this->contentExists), cvtBoolToConstZ(this->contentEof), cvtBoolToConstZ(this->content != NULL)); + strStcFmt( + debugLog, + "{code: %u, reason: %s, contentChunked: %s, contentSize: %" PRIu64 ", contentRemaining: %" PRIu64 ", closeOnContentEof: %s" + ", contentExists: %s, contentEof: %s, contentCached: %s}", + httpResponseCode(this), strZ(httpResponseReason(this)), cvtBoolToConstZ(this->contentChunked), this->contentSize, + this->contentRemaining, cvtBoolToConstZ(this->closeOnContentEof), cvtBoolToConstZ(this->contentExists), + cvtBoolToConstZ(this->contentEof), cvtBoolToConstZ(this->content != NULL)); + + strStcCat(debugLog, ", header: "), + httpHeaderToLog(httpResponseHeader(this), debugLog); + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/http/response.h b/src/common/io/http/response.h index a73fdaec4..fe9cef1ea 100644 --- a/src/common/io/http/response.h +++ b/src/common/io/http/response.h @@ -101,11 +101,11 @@ httpResponseFree(HttpResponse *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *httpResponseToLog(const HttpResponse *this); +FN_EXTERN void httpResponseToLog(const HttpResponse *this, StringStatic *debugLog); #define FUNCTION_LOG_HTTP_RESPONSE_TYPE \ HttpResponse * #define FUNCTION_LOG_HTTP_RESPONSE_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpResponseToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, httpResponseToLog, buffer, bufferSize) #endif diff --git a/src/common/io/http/session.h b/src/common/io/http/session.h index 66ef17c95..9ce2c08a0 100644 --- a/src/common/io/http/session.h +++ b/src/common/io/http/session.h @@ -68,6 +68,6 @@ Macros for function logging #define FUNCTION_LOG_HTTP_SESSION_TYPE \ HttpSession * #define FUNCTION_LOG_HTTP_SESSION_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "HttpSession", buffer, bufferSize) + objNameToLog(value, "HttpSession", buffer, bufferSize) #endif diff --git a/src/common/io/http/url.c b/src/common/io/http/url.c index 4a3ca9212..d2d45f47a 100644 --- a/src/common/io/http/url.c +++ b/src/common/io/http/url.c @@ -197,15 +197,15 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param) /**********************************************************************************************************************************/ #ifdef DEBUG -FN_EXTERN String * -httpUrlToLog(const HttpUrl *this) +FN_EXTERN void +httpUrlToLog(const HttpUrl *const this, StringStatic *const debugLog) { // Is IPv6 address? bool ipv6 = strChr(this->pub.host, ':') != -1; - return strNewFmt( - "{%s://%s%s%s:%u%s}", strZ(httpProtocolTypeStr(this->pub.type)), ipv6 ? "[" : "", strZ(this->pub.host), ipv6 ? "]" : "", - this->pub.port, strZ(this->pub.path)); + strStcFmt( + debugLog, "{%s://%s%s%s:%u%s}", strZ(httpProtocolTypeStr(this->pub.type)), ipv6 ? "[" : "", strZ(this->pub.host), + ipv6 ? "]" : "", this->pub.port, strZ(this->pub.path)); } #endif // DEBUG diff --git a/src/common/io/http/url.h b/src/common/io/http/url.h index 04409eb9a..c3b5fe283 100644 --- a/src/common/io/http/url.h +++ b/src/common/io/http/url.h @@ -100,12 +100,12 @@ Macros for function logging ***********************************************************************************************************************************/ #ifdef DEBUG -FN_EXTERN String *httpUrlToLog(const HttpUrl *this); +FN_EXTERN void httpUrlToLog(const HttpUrl *this, StringStatic *debugLog); #define FUNCTION_LOG_HTTP_URL_TYPE \ HttpUrl * #define FUNCTION_LOG_HTTP_URL_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpUrlToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, httpUrlToLog, buffer, bufferSize) #endif // DEBUG diff --git a/src/common/io/read.h b/src/common/io/read.h index fc1d0521f..c62fc2981 100644 --- a/src/common/io/read.h +++ b/src/common/io/read.h @@ -103,6 +103,6 @@ Macros for function logging #define FUNCTION_LOG_IO_READ_TYPE \ IoRead * #define FUNCTION_LOG_IO_READ_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoRead", buffer, bufferSize) + objNameToLog(value, "IoRead", buffer, bufferSize) #endif diff --git a/src/common/io/read.intern.h b/src/common/io/read.intern.h index 8de127ca4..bd25c6b46 100644 --- a/src/common/io/read.intern.h +++ b/src/common/io/read.intern.h @@ -69,6 +69,6 @@ Macros for function logging #define FUNCTION_LOG_IO_READ_INTERFACE_TYPE \ IoReadInterface #define FUNCTION_LOG_IO_READ_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "IoReadInterface", buffer, bufferSize) + objNameToLog(&value, "IoReadInterface", buffer, bufferSize) #endif diff --git a/src/common/io/server.c b/src/common/io/server.c index 434cf3f81..68f2e424b 100644 --- a/src/common/io/server.c +++ b/src/common/io/server.c @@ -48,9 +48,13 @@ ioServerNew(void *const driver, const IoServerInterface *const interface) } /**********************************************************************************************************************************/ -FN_EXTERN String * -ioServerToLog(const IoServer *const this) +FN_EXTERN void +ioServerToLog(const IoServer *const this, StringStatic *const debugLog) { - return strNewFmt( - "{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver))); + strStcCat(debugLog, "{type: "); + strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", driver: "); + this->pub.interface->toLog(this->pub.driver, debugLog); + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/server.h b/src/common/io/server.h index e4d31a710..0d68aa842 100644 --- a/src/common/io/server.h +++ b/src/common/io/server.h @@ -62,11 +62,11 @@ ioServerFree(IoServer *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *ioServerToLog(const IoServer *this); +FN_EXTERN void ioServerToLog(const IoServer *this, StringStatic *debugLog); #define FUNCTION_LOG_IO_SERVER_TYPE \ IoServer * #define FUNCTION_LOG_IO_SERVER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioServerToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, ioServerToLog, buffer, bufferSize) #endif diff --git a/src/common/io/server.intern.h b/src/common/io/server.intern.h index 270f13057..4fe319db7 100644 --- a/src/common/io/server.intern.h +++ b/src/common/io/server.intern.h @@ -23,7 +23,7 @@ typedef struct IoServerInterface IoSession *(*accept)(void *driver, IoSession *session); // Driver log function - String *(*toLog)(const void *driver); + void (*toLog)(const void *driver, StringStatic *debugLog); } IoServerInterface; /*********************************************************************************************************************************** @@ -37,6 +37,6 @@ Macros for function logging #define FUNCTION_LOG_IO_SERVER_INTERFACE_TYPE \ IoServerInterface * #define FUNCTION_LOG_IO_SERVER_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "IoServerInterface", buffer, bufferSize) + objNameToLog(&value, "IoServerInterface", buffer, bufferSize) #endif diff --git a/src/common/io/session.c b/src/common/io/session.c index f3509e7de..712cccd68 100644 --- a/src/common/io/session.c +++ b/src/common/io/session.c @@ -94,10 +94,16 @@ ioSessionPeerNameSet(IoSession *const this, const String *const peerName) } // {vm_covered} /**********************************************************************************************************************************/ -FN_EXTERN String * -ioSessionToLog(const IoSession *this) +FN_EXTERN void +ioSessionToLog(const IoSession *const this, StringStatic *const debugLog) { - return strNewFmt( - "{type: %s, role: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(strIdToStr(ioSessionRole(this))), - strZ(this->pub.interface->toLog(this->pub.driver))); + strStcCat(debugLog, "{type: "); + strStcResultSizeInc(debugLog, strIdToLog(this->pub.interface->type, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", role: "); + strStcResultSizeInc(debugLog, strIdToLog(ioSessionRole(this), strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", driver: "); + this->pub.interface->toLog(this->pub.driver, debugLog); + strStcCatChr(debugLog, '}'); } diff --git a/src/common/io/session.h b/src/common/io/session.h index 7730d3c14..208e4b026 100644 --- a/src/common/io/session.h +++ b/src/common/io/session.h @@ -117,11 +117,11 @@ ioSessionFree(IoSession *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *ioSessionToLog(const IoSession *this); +FN_EXTERN void ioSessionToLog(const IoSession *this, StringStatic *debugLog); #define FUNCTION_LOG_IO_SESSION_TYPE \ IoSession * #define FUNCTION_LOG_IO_SESSION_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioSessionToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, ioSessionToLog, buffer, bufferSize) #endif diff --git a/src/common/io/session.intern.h b/src/common/io/session.intern.h index 354c632eb..ae3c7daee 100644 --- a/src/common/io/session.intern.h +++ b/src/common/io/session.intern.h @@ -31,7 +31,7 @@ typedef struct IoSessionInterface IoSessionRole (*role)(const void *driver); // Driver log function - String *(*toLog)(const void *driver); + void (*toLog)(const void *driver, StringStatic *debugLog); } IoSessionInterface; /*********************************************************************************************************************************** @@ -54,6 +54,6 @@ Macros for function logging #define FUNCTION_LOG_IO_SESSION_INTERFACE_TYPE \ IoSessionInterface * #define FUNCTION_LOG_IO_SESSION_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "IoSessionInterface", buffer, bufferSize) + objNameToLog(&value, "IoSessionInterface", buffer, bufferSize) #endif diff --git a/src/common/io/socket/client.c b/src/common/io/socket/client.c index dbd521c41..f616460fb 100644 --- a/src/common/io/socket/client.c +++ b/src/common/io/socket/client.c @@ -40,20 +40,20 @@ typedef struct SocketClient /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -sckClientToLog(const THIS_VOID) +static void +sckClientToLog(const THIS_VOID, StringStatic *const debugLog) { THIS(const SocketClient); - return strNewFmt( - "{host: %s, port: %u, timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 "}", strZ(this->host), this->port, + strStcFmt( + debugLog, "{host: %s, port: %u, timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 "}", strZ(this->host), this->port, this->timeoutConnect, this->timeoutSession); } #define FUNCTION_LOG_SOCKET_CLIENT_TYPE \ SocketClient * #define FUNCTION_LOG_SOCKET_CLIENT_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, sckClientToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, sckClientToLog, buffer, bufferSize) /**********************************************************************************************************************************/ static IoSession * diff --git a/src/common/io/socket/server.c b/src/common/io/socket/server.c index ff758901a..24dbe14e2 100644 --- a/src/common/io/socket/server.c +++ b/src/common/io/socket/server.c @@ -40,18 +40,18 @@ typedef struct SocketServer /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -sckServerToLog(const THIS_VOID) +static void +sckServerToLog(const THIS_VOID, StringStatic *const debugLog) { THIS(const SocketServer); - return strNewFmt("{address: %s, port: %u, timeout: %" PRIu64 "}", strZ(this->address), this->port, this->timeout); + strStcFmt(debugLog, "{address: %s, port: %u, timeout: %" PRIu64 "}", strZ(this->address), this->port, this->timeout); } #define FUNCTION_LOG_SOCKET_SERVER_TYPE \ SocketServer * #define FUNCTION_LOG_SOCKET_SERVER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, sckServerToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, sckServerToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free connection diff --git a/src/common/io/socket/session.c b/src/common/io/socket/session.c index 52fa48cf0..1b24fc328 100644 --- a/src/common/io/socket/session.c +++ b/src/common/io/socket/session.c @@ -31,18 +31,19 @@ typedef struct SocketSession /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -sckSessionToLog(const THIS_VOID) +static void +sckSessionToLog(const THIS_VOID, StringStatic *const debugLog) { THIS(const SocketSession); - return strNewFmt("{fd %d, host: %s, port: %u, timeout: %" PRIu64 "}", this->fd, strZ(this->host), this->port, this->timeout); + strStcFmt( + debugLog, "{host: %s, port: %u, fd: %d, timeout: %" PRIu64 "}", strZ(this->host), this->port, this->fd, this->timeout); } #define FUNCTION_LOG_SOCKET_SESSION_TYPE \ SocketSession * #define FUNCTION_LOG_SOCKET_SESSION_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, sckSessionToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, sckSessionToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free connection diff --git a/src/common/io/tls/client.c b/src/common/io/tls/client.c index 765f9e88a..a75d16ffc 100644 --- a/src/common/io/tls/client.c +++ b/src/common/io/tls/client.c @@ -41,20 +41,23 @@ typedef struct TlsClient /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -tlsClientToLog(const THIS_VOID) +static void +tlsClientToLog(const THIS_VOID, StringStatic *const debugLog) { THIS(const TlsClient); - return strNewFmt( - "{ioClient: %s, timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 ", verifyPeer: %s}", - strZ(ioClientToLog(this->ioClient)), this->timeoutConnect, this->timeoutSession, cvtBoolToConstZ(this->verifyPeer)); + strStcCat(debugLog, "{ioClient: "); + ioClientToLog(this->ioClient, debugLog); + + strStcFmt( + debugLog, ", timeoutConnect: %" PRIu64 ", timeoutSession: %" PRIu64 ", verifyPeer: %s}", this->timeoutConnect, + this->timeoutSession, cvtBoolToConstZ(this->verifyPeer)); } #define FUNCTION_LOG_TLS_CLIENT_TYPE \ TlsClient * #define FUNCTION_LOG_TLS_CLIENT_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, tlsClientToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, tlsClientToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free connection diff --git a/src/common/io/tls/server.c b/src/common/io/tls/server.c index aeb7de4ad..ae3bcdc2a 100644 --- a/src/common/io/tls/server.c +++ b/src/common/io/tls/server.c @@ -39,18 +39,18 @@ typedef struct TlsServer /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -tlsServerToLog(const THIS_VOID) +static void +tlsServerToLog(const THIS_VOID, StringStatic *const debugLog) { THIS(const TlsServer); - return strNewFmt("{host: %s, timeout: %" PRIu64 "}", strZ(this->host), this->timeout); + strStcFmt(debugLog, "{host: %s, timeout: %" PRIu64 "}", strZ(this->host), this->timeout); } #define FUNCTION_LOG_TLS_SERVER_TYPE \ TlsServer * #define FUNCTION_LOG_TLS_SERVER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, tlsServerToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, tlsServerToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free context diff --git a/src/common/io/tls/session.c b/src/common/io/tls/session.c index ea7ad37a2..5c8cae436 100644 --- a/src/common/io/tls/session.c +++ b/src/common/io/tls/session.c @@ -34,20 +34,20 @@ typedef struct TlsSession /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -static String * -tlsSessionToLog(const THIS_VOID) +static void +tlsSessionToLog(const THIS_VOID, StringStatic *const debugLog) { THIS(const TlsSession); - return strNewFmt( - "{ioSession: %s, timeout: %" PRIu64", shutdownOnClose: %s}", strZ(ioSessionToLog(this->ioSession)), this->timeout, - cvtBoolToConstZ(this->shutdownOnClose)); + strStcCat(debugLog, "{ioSession: "); + ioSessionToLog(this->ioSession, debugLog); + strStcFmt(debugLog, ", timeout: %" PRIu64", shutdownOnClose: %s}", this->timeout, cvtBoolToConstZ(this->shutdownOnClose)); } #define FUNCTION_LOG_TLS_SESSION_TYPE \ TlsSession * #define FUNCTION_LOG_TLS_SESSION_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, tlsSessionToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, tlsSessionToLog, buffer, bufferSize) /*********************************************************************************************************************************** Free connection diff --git a/src/common/io/write.h b/src/common/io/write.h index 9ef37af31..b90d4e67b 100644 --- a/src/common/io/write.h +++ b/src/common/io/write.h @@ -91,6 +91,6 @@ Macros for function logging #define FUNCTION_LOG_IO_WRITE_TYPE \ IoWrite * #define FUNCTION_LOG_IO_WRITE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "IoWrite", buffer, bufferSize) + objNameToLog(value, "IoWrite", buffer, bufferSize) #endif diff --git a/src/common/io/write.intern.h b/src/common/io/write.intern.h index a09174209..4bdb28fb9 100644 --- a/src/common/io/write.intern.h +++ b/src/common/io/write.intern.h @@ -34,6 +34,6 @@ Macros for function logging #define FUNCTION_LOG_IO_WRITE_INTERFACE_TYPE \ IoWriteInterface #define FUNCTION_LOG_IO_WRITE_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "IoWriteInterface", buffer, bufferSize) + objNameToLog(&value, "IoWriteInterface", buffer, bufferSize) #endif diff --git a/src/common/memContext.h b/src/common/memContext.h index 779ea1f87..c658a3299 100644 --- a/src/common/memContext.h +++ b/src/common/memContext.h @@ -294,7 +294,7 @@ Macros for function logging #define FUNCTION_LOG_MEM_CONTEXT_TYPE \ MemContext * #define FUNCTION_LOG_MEM_CONTEXT_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "MemContext", buffer, bufferSize) + objNameToLog(value, "MemContext", buffer, bufferSize) /*********************************************************************************************************************************** Internal functions diff --git a/src/common/regExp.h b/src/common/regExp.h index 509fdd88b..872fcfc49 100644 --- a/src/common/regExp.h +++ b/src/common/regExp.h @@ -49,6 +49,6 @@ Macros for function logging #define FUNCTION_LOG_REGEXP_TYPE \ RegExp * #define FUNCTION_LOG_REGEXP_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "RegExp", buffer, bufferSize) + objNameToLog(value, "RegExp", buffer, bufferSize) #endif diff --git a/src/common/type/blob.h b/src/common/type/blob.h index b89f8e92f..69314022b 100644 --- a/src/common/type/blob.h +++ b/src/common/type/blob.h @@ -53,6 +53,6 @@ Macros for function logging #define FUNCTION_LOG_BLOB_TYPE \ Blob * #define FUNCTION_LOG_BLOB_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Blob", buffer, bufferSize) + objNameToLog(value, "Blob", buffer, bufferSize) #endif diff --git a/src/common/type/buffer.c b/src/common/type/buffer.c index 267c44d51..4139e1b07 100644 --- a/src/common/type/buffer.c +++ b/src/common/type/buffer.c @@ -345,12 +345,10 @@ bufUsedZero(Buffer *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -bufToLog(const Buffer *this) +FN_EXTERN void +bufToLog(const Buffer *const this, StringStatic *const debugLog) { - String *result = strNewFmt( - "{used: %zu, size: %zu%s", bufUsed(this), bufSize(this), - bufSizeLimit(this) ? zNewFmt(", sizeAlloc: %zu}", bufSizeAlloc(this)) : "}"); - - return result; + strStcFmt( + debugLog, "{used: %zu, size: %zu%s", bufUsed(this), bufSize(this), bufSizeLimit(this) ? zNewFmt(", sizeAlloc: %zu}", + bufSizeAlloc(this)) : "}"); } diff --git a/src/common/type/buffer.h b/src/common/type/buffer.h index 35d595092..22710077a 100644 --- a/src/common/type/buffer.h +++ b/src/common/type/buffer.h @@ -210,11 +210,11 @@ BUFFER_DECLARE(QUOTED_BUF); /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *bufToLog(const Buffer *this); +FN_EXTERN void bufToLog(const Buffer *this, StringStatic *debugLog); #define FUNCTION_LOG_BUFFER_TYPE \ Buffer * #define FUNCTION_LOG_BUFFER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, bufToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, bufToLog, buffer, bufferSize) #endif diff --git a/src/common/type/json.c b/src/common/type/json.c index 67a700412..544f995c9 100644 --- a/src/common/type/json.c +++ b/src/common/type/json.c @@ -1301,10 +1301,10 @@ jsonValidate(const String *const json) /**********************************************************************************************************************************/ #ifdef DEBUG -FN_EXTERN String * -jsonReadToLog(const JsonRead *const this) +FN_EXTERN void +jsonReadToLog(const JsonRead *const this, StringStatic *const debugLog) { - return strNewFmt("{json: %s}", this->json); + strStcFmt(debugLog, "{json: %s}", this->json); } #endif // DEBUG @@ -2053,10 +2053,10 @@ jsonFromVar(const Variant *const value) /**********************************************************************************************************************************/ #ifdef DEBUG -FN_EXTERN String * -jsonWriteToLog(const JsonWrite *const this) +FN_EXTERN void +jsonWriteToLog(const JsonWrite *const this, StringStatic *const debugLog) { - return strNewFmt("{size: %zu}", strSize(this->json)); + strStcFmt(debugLog, "{size: %zu}", strSize(this->json)); } #endif // DEBUG diff --git a/src/common/type/json.h b/src/common/type/json.h index 72f4c09c7..e585ec5e7 100644 --- a/src/common/type/json.h +++ b/src/common/type/json.h @@ -184,19 +184,19 @@ Macros for function logging ***********************************************************************************************************************************/ #ifdef DEBUG -FN_EXTERN String *jsonReadToLog(const JsonRead *this); +FN_EXTERN void jsonReadToLog(const JsonRead *this, StringStatic *debugLog); #define FUNCTION_LOG_JSON_READ_TYPE \ JsonRead * #define FUNCTION_LOG_JSON_READ_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, jsonReadToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, jsonReadToLog, buffer, bufferSize) -FN_EXTERN String *jsonWriteToLog(const JsonWrite *this); +FN_EXTERN void jsonWriteToLog(const JsonWrite *this, StringStatic *debugLog); #define FUNCTION_LOG_JSON_WRITE_TYPE \ JsonWrite * #define FUNCTION_LOG_JSON_WRITE_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, jsonWriteToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, jsonWriteToLog, buffer, bufferSize) #endif // DEBUG diff --git a/src/common/type/keyValue.h b/src/common/type/keyValue.h index 3189c5b23..73544903c 100644 --- a/src/common/type/keyValue.h +++ b/src/common/type/keyValue.h @@ -98,6 +98,6 @@ Macros for function logging #define FUNCTION_LOG_KEY_VALUE_TYPE \ KeyValue * #define FUNCTION_LOG_KEY_VALUE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "KeyValue", buffer, bufferSize) + objNameToLog(value, "KeyValue", buffer, bufferSize) #endif diff --git a/src/common/type/list.c b/src/common/type/list.c index 8f87e09c9..6a48043da 100644 --- a/src/common/type/list.c +++ b/src/common/type/list.c @@ -430,8 +430,8 @@ lstComparatorSet(List *this, ListComparator *comparator) } /**********************************************************************************************************************************/ -FN_EXTERN String * -lstToLog(const List *this) +FN_EXTERN void +lstToLog(const List *const this, StringStatic *const debugLog) { - return strNewFmt("{size: %u}", lstSize(this)); + strStcFmt(debugLog, "{size: %u}", lstSize(this)); } diff --git a/src/common/type/list.h b/src/common/type/list.h index 0c852f3fd..01007b5f3 100644 --- a/src/common/type/list.h +++ b/src/common/type/list.h @@ -158,11 +158,11 @@ lstFree(List *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *lstToLog(const List *this); +FN_EXTERN void lstToLog(const List *this, StringStatic *debugLog); #define FUNCTION_LOG_LIST_TYPE \ List * #define FUNCTION_LOG_LIST_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, lstToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, lstToLog, buffer, bufferSize) #endif diff --git a/src/common/type/pack.c b/src/common/type/pack.c index 44f53f4b8..9404a951b 100644 --- a/src/common/type/pack.c +++ b/src/common/type/pack.c @@ -1242,11 +1242,11 @@ pckReadEnd(PackRead *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -pckReadToLog(const PackRead *this) +FN_EXTERN void +pckReadToLog(const PackRead *const this, StringStatic *const debugLog) { - return strNewFmt( - "{depth: %u, idLast: %u, tagNextId: %u, tagNextType: %u, tagNextValue %" PRIu64 "}", this->tagStack.depth, + strStcFmt( + debugLog, "{depth: %u, idLast: %u, tagNextId: %u, tagNextType: %u, tagNextValue %" PRIu64 "}", this->tagStack.depth, this->tagStack.top->idLast, this->tagNextId, this->tagNextTypeMap, this->tagNextValue); } @@ -1946,8 +1946,9 @@ pckWriteResult(PackWrite *const this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -pckWriteToLog(const PackWrite *this) +FN_EXTERN void +pckWriteToLog(const PackWrite *const this, StringStatic *const debugLog) { - return strNewFmt("{depth: %u, idLast: %u}", this->tagStack.depth, this->tagStack.top == NULL ? 0 : this->tagStack.top->idLast); + strStcFmt( + debugLog, "{depth: %u, idLast: %u}", this->tagStack.depth, this->tagStack.top == NULL ? 0 : this->tagStack.top->idLast); } diff --git a/src/common/type/pack.h b/src/common/type/pack.h index 7733dbb78..9c7ae40ee 100644 --- a/src/common/type/pack.h +++ b/src/common/type/pack.h @@ -661,20 +661,20 @@ Macros for function logging #define FUNCTION_LOG_PACK_TYPE \ Pack * #define FUNCTION_LOG_PACK_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Pack", buffer, bufferSize) + objNameToLog(value, "Pack", buffer, bufferSize) -FN_EXTERN String *pckReadToLog(const PackRead *this); +FN_EXTERN void pckReadToLog(const PackRead *this, StringStatic *debugLog); #define FUNCTION_LOG_PACK_READ_TYPE \ PackRead * #define FUNCTION_LOG_PACK_READ_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pckReadToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, pckReadToLog, buffer, bufferSize) -FN_EXTERN String *pckWriteToLog(const PackWrite *this); +FN_EXTERN void pckWriteToLog(const PackWrite *this, StringStatic *debugLog); #define FUNCTION_LOG_PACK_WRITE_TYPE \ PackWrite * #define FUNCTION_LOG_PACK_WRITE_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pckWriteToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, pckWriteToLog, buffer, bufferSize) #endif diff --git a/src/common/type/string.c b/src/common/type/string.c index 600a988c1..ffa868693 100644 --- a/src/common/type/string.c +++ b/src/common/type/string.c @@ -998,27 +998,11 @@ strTruncIdx(String *this, int idx) FUNCTION_TEST_RETURN(STRING, this); } -/*********************************************************************************************************************************** -Convert an object to a zero-terminated string for logging -***********************************************************************************************************************************/ -FN_EXTERN size_t strObjToLog(const void *object, StrObjToLogFormat formatFunc, char *buffer, size_t bufferSize) -{ - size_t result = 0; - - MEM_CONTEXT_TEMP_BEGIN() - { - result = (size_t)snprintf(buffer, bufferSize, "%s", object == NULL ? NULL_Z : strZ(formatFunc(object))); - } - MEM_CONTEXT_TEMP_END(); - - return result; -} - /**********************************************************************************************************************************/ -FN_EXTERN String * -strToLog(const String *this) +FN_EXTERN void +strToLog(const String *const this, StringStatic *const debugLog) { - return this == NULL ? strDup(NULL_STR) : strNewFmt("{\"%s\"}", strZ(this)); + strStcFmt(debugLog, "{\"%s\"}", strZ(this)); } /**********************************************************************************************************************************/ diff --git a/src/common/type/string.h b/src/common/type/string.h index d85d09e3e..a17a341d0 100644 --- a/src/common/type/string.h +++ b/src/common/type/string.h @@ -23,6 +23,8 @@ old context and then back. Below is a simplified example: #include +#include "common/debug.h" + /*********************************************************************************************************************************** Minimum number of extra bytes to allocate for strings that are growing or are likely to grow ***********************************************************************************************************************************/ @@ -258,24 +260,14 @@ STRING_DECLARE(TRUE_STR); STRING_DECLARE(Y_STR); STRING_DECLARE(ZERO_STR); -/*********************************************************************************************************************************** -Helper function/macro for object logging -***********************************************************************************************************************************/ -typedef String *(*StrObjToLogFormat)(const void *object); - -FN_EXTERN size_t strObjToLog(const void *object, StrObjToLogFormat formatFunc, char *buffer, size_t bufferSize); - -#define FUNCTION_LOG_STRING_OBJECT_FORMAT(object, formatFunc, buffer, bufferSize) \ - strObjToLog(object, (StrObjToLogFormat)formatFunc, buffer, bufferSize) - /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *strToLog(const String *this); +FN_EXTERN void strToLog(const String *this, StringStatic *debugLog); #define FUNCTION_LOG_STRING_TYPE \ String * #define FUNCTION_LOG_STRING_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, strToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, strToLog, buffer, bufferSize) #endif diff --git a/src/common/type/stringId.h b/src/common/type/stringId.h index 2309d44e4..e1fc56e71 100644 --- a/src/common/type/stringId.h +++ b/src/common/type/stringId.h @@ -93,7 +93,7 @@ FN_EXTERN size_t strIdToZ(const StringId strId, char *const buffer); /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN size_t strIdToLog(const StringId strId, char *const buffer, const size_t bufferSize); +FN_EXTERN size_t strIdToLog(StringId strId, char *buffer, size_t bufferSize); #define FUNCTION_LOG_STRING_ID_TYPE \ StringId diff --git a/src/common/type/stringList.c b/src/common/type/stringList.c index 13498d542..f6a22ec16 100644 --- a/src/common/type/stringList.c +++ b/src/common/type/stringList.c @@ -435,8 +435,23 @@ strLstPtr(const StringList *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -strLstToLog(const StringList *this) +FN_EXTERN void +strLstToLog(const StringList *const this, StringStatic *const debugLog) { - return strNewFmt("{[%s]}", strZ(strLstJoinQuote(this, ", ", "\""))); + strStcCat(debugLog, "{["); + + for (unsigned int strLstIdx = 0; strLstIdx < strLstSize(this); strLstIdx++) + { + const String *const value = strLstGet(this, strLstIdx); + + if (strLstIdx != 0) + strStcCat(debugLog, ", "); + + if (value == NULL) + strStcCat(debugLog, NULL_Z); + else + strStcFmt(debugLog, "\"%s\"", strZ(value)); + } + + strStcCat(debugLog, "]}"); } diff --git a/src/common/type/stringList.h b/src/common/type/stringList.h index 5de026b50..9159b7cb2 100644 --- a/src/common/type/stringList.h +++ b/src/common/type/stringList.h @@ -174,11 +174,11 @@ strLstFree(StringList *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *strLstToLog(const StringList *this); +FN_EXTERN void strLstToLog(const StringList *this, StringStatic *debugLog); #define FUNCTION_LOG_STRING_LIST_TYPE \ StringList * #define FUNCTION_LOG_STRING_LIST_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, strLstToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, strLstToLog, buffer, bufferSize) #endif diff --git a/src/common/type/stringStatic.c b/src/common/type/stringStatic.c new file mode 100644 index 000000000..64eed3f78 --- /dev/null +++ b/src/common/type/stringStatic.c @@ -0,0 +1,61 @@ +/*********************************************************************************************************************************** +Static String Handler +***********************************************************************************************************************************/ +#include "build.auto.h" + +#include +#include +#include + +#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'; + } +} diff --git a/src/common/type/stringStatic.h b/src/common/type/stringStatic.h new file mode 100644 index 000000000..b7009f76e --- /dev/null +++ b/src/common/type/stringStatic.h @@ -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 + +/*********************************************************************************************************************************** +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 diff --git a/src/common/type/variant.c b/src/common/type/variant.c index cdf162339..ab6447dc5 100644 --- a/src/common/type/variant.c +++ b/src/common/type/variant.c @@ -1017,40 +1017,43 @@ varVarLst(const Variant *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -varToLog(const Variant *this) +FN_EXTERN void +varToLog(const Variant *const this, StringStatic *const debugLog) { - String *result = NULL; - - if (this == NULL) - result = strDup(NULL_STR); - else + switch (varType(this)) { - switch (varType(this)) - { - case varTypeString: - result = strToLog(varStr(this)); - break; + case varTypeString: + strStcResultSizeInc( + debugLog, + FUNCTION_LOG_OBJECT_FORMAT(varStr(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + break; - case varTypeKeyValue: - result = strNewZ("{KeyValue}"); - break; + case varTypeKeyValue: + strStcCat(debugLog, "{KeyValue}"); + break; - case varTypeVariantList: - result = strNewZ("{VariantList}"); - break; + case varTypeVariantList: + strStcCat(debugLog, "{VariantList}"); + break; - case varTypeBool: - case varTypeInt: - case varTypeInt64: - case varTypeUInt: - case varTypeUInt64: - { - result = strNewFmt("{%s}", strZ(varStrForce(this))); - break; - } - } + case varTypeBool: + strStcFmt(debugLog, "{%s}", cvtBoolToConstZ(varBool(this))); + break; + + case varTypeInt: + strStcFmt(debugLog, "{%d}", varInt(this)); + break; + + case varTypeInt64: + strStcFmt(debugLog, "{%" PRId64 "}", varInt64(this)); + break; + + case varTypeUInt: + strStcFmt(debugLog, "{%u}", varUInt(this)); + break; + + case varTypeUInt64: + strStcFmt(debugLog, "{%" PRIu64 "}", varUInt64(this)); + break; } - - return result; } diff --git a/src/common/type/variant.h b/src/common/type/variant.h index 6548eac0e..671ca5d33 100644 --- a/src/common/type/variant.h +++ b/src/common/type/variant.h @@ -220,11 +220,11 @@ VARIANT_DECLARE(BOOL_TRUE_VAR); /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *varToLog(const Variant *this); +FN_EXTERN void varToLog(const Variant *this, StringStatic *debugLog); #define FUNCTION_LOG_VARIANT_TYPE \ Variant * #define FUNCTION_LOG_VARIANT_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, varToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, varToLog, buffer, bufferSize) #endif diff --git a/src/common/type/variantList.h b/src/common/type/variantList.h index 0af949988..81b0b6b10 100644 --- a/src/common/type/variantList.h +++ b/src/common/type/variantList.h @@ -85,6 +85,6 @@ Macros for function logging #define FUNCTION_LOG_VARIANT_LIST_TYPE \ VariantList * #define FUNCTION_LOG_VARIANT_LIST_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "VariantList", buffer, bufferSize) + objNameToLog(value, "VariantList", buffer, bufferSize) #endif diff --git a/src/common/type/xml.h b/src/common/type/xml.h index d66ee49df..a264bd74f 100644 --- a/src/common/type/xml.h +++ b/src/common/type/xml.h @@ -113,16 +113,16 @@ Macros for function logging #define FUNCTION_LOG_XML_DOCUMENT_TYPE \ XmlDocument * #define FUNCTION_LOG_XML_DOCUMENT_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "XmlDocument", buffer, bufferSize) + objNameToLog(value, "XmlDocument", buffer, bufferSize) #define FUNCTION_LOG_XML_NODE_TYPE \ XmlNode * #define FUNCTION_LOG_XML_NODE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "XmlNode", buffer, bufferSize) + objNameToLog(value, "XmlNode", buffer, bufferSize) #define FUNCTION_LOG_XML_NODE_LIST_TYPE \ XmlNodeList * #define FUNCTION_LOG_XML_NODE_LIST_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "XmlNodeList", buffer, bufferSize) + objNameToLog(value, "XmlNodeList", buffer, bufferSize) #endif diff --git a/src/common/wait.h b/src/common/wait.h index e4386dc0d..563398e84 100644 --- a/src/common/wait.h +++ b/src/common/wait.h @@ -53,6 +53,6 @@ Macros for function logging #define FUNCTION_LOG_WAIT_TYPE \ Wait * #define FUNCTION_LOG_WAIT_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Wait", buffer, bufferSize) + objNameToLog(value, "Wait", buffer, bufferSize) #endif diff --git a/src/db/db.c b/src/db/db.c index 50c744d9f..60541a39b 100644 --- a/src/db/db.c +++ b/src/db/db.c @@ -851,10 +851,17 @@ dbWalSwitch(Db *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -dbToLog(const Db *this) +FN_EXTERN void +dbToLog(const Db *const this, StringStatic *const debugLog) { - return strNewFmt( - "{client: %s, remoteClient: %s}", this->client == NULL ? NULL_Z : strZ(pgClientToLog(this->client)), - this->remoteClient == NULL ? NULL_Z : strZ(protocolClientToLog(this->remoteClient))); + strStcCat(debugLog, "{client: "); + strStcResultSizeInc( + debugLog, FUNCTION_LOG_OBJECT_FORMAT(this->client, pgClientToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", remoteClient: "); + strStcResultSizeInc( + debugLog, + FUNCTION_LOG_OBJECT_FORMAT( + this->remoteClient, protocolClientToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcCatChr(debugLog, '}'); } diff --git a/src/db/db.h b/src/db/db.h index 9ceb99c38..5fc6255ef 100644 --- a/src/db/db.h +++ b/src/db/db.h @@ -159,11 +159,11 @@ dbFree(Db *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *dbToLog(const Db *this); +FN_EXTERN void dbToLog(const Db *this, StringStatic *debugLog); #define FUNCTION_LOG_DB_TYPE \ Db * #define FUNCTION_LOG_DB_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, dbToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, dbToLog, buffer, bufferSize) #endif diff --git a/src/db/helper.h b/src/db/helper.h index 5e994bed2..1c9f4a482 100644 --- a/src/db/helper.h +++ b/src/db/helper.h @@ -30,6 +30,6 @@ Macros for function logging #define FUNCTION_LOG_DB_GET_RESULT_TYPE \ DbGetResult #define FUNCTION_LOG_DB_GET_RESULT_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "DbGetResult", buffer, bufferSize) + objNameToLog(&value, "DbGetResult", buffer, bufferSize) #endif diff --git a/src/info/info.h b/src/info/info.h index a6ae64554..7dde1c939 100644 --- a/src/info/info.h +++ b/src/info/info.h @@ -89,11 +89,11 @@ Macros for function logging #define FUNCTION_LOG_INFO_TYPE \ Info * #define FUNCTION_LOG_INFO_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Info", buffer, bufferSize) + objNameToLog(value, "Info", buffer, bufferSize) #define FUNCTION_LOG_INFO_SAVE_TYPE \ InfoSave * #define FUNCTION_LOG_INFO_SAVE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "InfoSave", buffer, bufferSize) + objNameToLog(value, "InfoSave", buffer, bufferSize) #endif diff --git a/src/info/infoArchive.h b/src/info/infoArchive.h index e00a0a8f1..3af296c02 100644 --- a/src/info/infoArchive.h +++ b/src/info/infoArchive.h @@ -106,6 +106,6 @@ Macros for function logging #define FUNCTION_LOG_INFO_ARCHIVE_TYPE \ InfoArchive * #define FUNCTION_LOG_INFO_ARCHIVE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "InfoArchive", buffer, bufferSize) + objNameToLog(value, "InfoArchive", buffer, bufferSize) #endif diff --git a/src/info/infoBackup.c b/src/info/infoBackup.c index 000dbb3d4..f65d5559a 100644 --- a/src/info/infoBackup.c +++ b/src/info/infoBackup.c @@ -850,8 +850,8 @@ infoBackupSaveFile( } /**********************************************************************************************************************************/ -FN_EXTERN String * -infoBackupDataToLog(const InfoBackupData *this) +FN_EXTERN void +infoBackupDataToLog(const InfoBackupData *const this, StringStatic *const debugLog) { - return strNewFmt("{label: %s, pgId: %u}", strZ(this->backupLabel), this->backupPgId); + strStcFmt(debugLog, "{label: %s, pgId: %u}", strZ(this->backupLabel), this->backupPgId); } diff --git a/src/info/infoBackup.h b/src/info/infoBackup.h index 5b58c69f8..c5c26927b 100644 --- a/src/info/infoBackup.h +++ b/src/info/infoBackup.h @@ -184,15 +184,15 @@ FN_EXTERN void infoBackupSaveFile( /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *infoBackupDataToLog(const InfoBackupData *this); +FN_EXTERN void infoBackupDataToLog(const InfoBackupData *this, StringStatic *debugLog); #define FUNCTION_LOG_INFO_BACKUP_TYPE \ InfoBackup * #define FUNCTION_LOG_INFO_BACKUP_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "InfoBackup", buffer, bufferSize) + objNameToLog(value, "InfoBackup", buffer, bufferSize) #define FUNCTION_LOG_INFO_BACKUP_DATA_TYPE \ InfoBackupData #define FUNCTION_LOG_INFO_BACKUP_DATA_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, infoBackupDataToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(&value, infoBackupDataToLog, buffer, bufferSize) #endif diff --git a/src/info/infoPg.c b/src/info/infoPg.c index 607ecbecc..d10272f92 100644 --- a/src/info/infoPg.c +++ b/src/info/infoPg.c @@ -456,10 +456,10 @@ infoPgCurrentDataId(const InfoPg *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -infoPgDataToLog(const InfoPgData *this) +FN_EXTERN void +infoPgDataToLog(const InfoPgData *const this, StringStatic *const debugLog) { - return strNewFmt( - "{id: %u, version: %u, systemId: %" PRIu64 ", catalogVersion: %u}", this->id, this->version, this->systemId, + strStcFmt( + debugLog, "{id: %u, version: %u, systemId: %" PRIu64 ", catalogVersion: %u}", this->id, this->version, this->systemId, this->catalogVersion); } diff --git a/src/info/infoPg.h b/src/info/infoPg.h index d0456c06b..1665511de 100644 --- a/src/info/infoPg.h +++ b/src/info/infoPg.h @@ -113,17 +113,17 @@ FN_EXTERN InfoPg *infoPgSet( /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *infoPgDataToLog(const InfoPgData *this); +FN_EXTERN void infoPgDataToLog(const InfoPgData *this, StringStatic *debugLog); #define FUNCTION_LOG_INFO_PG_TYPE \ InfoPg * #define FUNCTION_LOG_INFO_PG_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "InfoPg", buffer, bufferSize) + objNameToLog(value, "InfoPg", buffer, bufferSize) #define FUNCTION_LOG_INFO_PG_DATA_TYPE \ InfoPgData #define FUNCTION_LOG_INFO_PG_DATA_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, infoPgDataToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(&value, infoPgDataToLog, buffer, bufferSize) #endif diff --git a/src/info/manifest.h b/src/info/manifest.h index d7b62fbcf..46baa289b 100644 --- a/src/info/manifest.h +++ b/src/info/manifest.h @@ -457,31 +457,31 @@ Macros for function logging #define FUNCTION_LOG_MANIFEST_TYPE \ Manifest * #define FUNCTION_LOG_MANIFEST_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "Manifest", buffer, bufferSize) + objNameToLog(value, "Manifest", buffer, bufferSize) #define FUNCTION_LOG_MANIFEST_DB_TYPE \ ManifestDb * #define FUNCTION_LOG_MANIFEST_DB_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "ManifestDb", buffer, bufferSize) + objNameToLog(value, "ManifestDb", buffer, bufferSize) #define FUNCTION_LOG_MANIFEST_FILE_TYPE \ ManifestFile * #define FUNCTION_LOG_MANIFEST_FILE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "ManifestFile", buffer, bufferSize) + objNameToLog(value, "ManifestFile", buffer, bufferSize) #define FUNCTION_LOG_MANIFEST_LINK_TYPE \ ManifestLink * #define FUNCTION_LOG_MANIFEST_LINK_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "ManifestLink", buffer, bufferSize) + objNameToLog(value, "ManifestLink", buffer, bufferSize) #define FUNCTION_LOG_MANIFEST_PATH_TYPE \ ManifestPath * #define FUNCTION_LOG_MANIFEST_PATH_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "ManifestPath", buffer, bufferSize) + objNameToLog(value, "ManifestPath", buffer, bufferSize) #define FUNCTION_LOG_MANIFEST_TARGET_TYPE \ ManifestTarget * #define FUNCTION_LOG_MANIFEST_TARGET_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "ManifestTarget", buffer, bufferSize) + objNameToLog(value, "ManifestTarget", buffer, bufferSize) #endif diff --git a/src/meson.build b/src/meson.build index 11a9aa1ab..223d9ed28 100644 --- a/src/meson.build +++ b/src/meson.build @@ -49,9 +49,10 @@ src_common = files( 'common/type/list.c', 'common/type/object.c', 'common/type/pack.c', - 'common/type/stringZ.c', 'common/type/stringId.c', 'common/type/stringList.c', + 'common/type/stringStatic.c', + 'common/type/stringZ.c', 'common/type/variant.c', 'common/type/variantList.c', 'common/user.c', diff --git a/src/postgres/client.c b/src/postgres/client.c index 8af2837b5..2823ce450 100644 --- a/src/postgres/client.c +++ b/src/postgres/client.c @@ -377,10 +377,22 @@ pgClientClose(PgClient *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -pgClientToLog(const PgClient *this) +FN_EXTERN void +pgClientToLog(const PgClient *const this, StringStatic *const debugLog) { - return strNewFmt( - "{host: %s, port: %u, database: %s, user: %s, queryTimeout %" PRIu64 "}", strZ(strToLog(pgClientHost(this))), - pgClientPort(this), strZ(strToLog(pgClientDatabase(this))), strZ(strToLog(pgClientUser(this))), pgClientTimeout(this)); + strStcCat(debugLog, "{host: "); + strStcResultSizeInc( + debugLog, + FUNCTION_LOG_OBJECT_FORMAT(pgClientHost(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", database: "); + strToLog(pgClientDatabase(this), debugLog); + + strStcCat(debugLog, ", user: "); + strStcResultSizeInc( + debugLog, + FUNCTION_LOG_OBJECT_FORMAT(pgClientUser(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcFmt( + debugLog, ", port: %u, queryTimeout %" PRIu64 "}", pgClientPort(this), pgClientTimeout(this)); } diff --git a/src/postgres/client.h b/src/postgres/client.h index 9aaf60c8e..6144d65ab 100644 --- a/src/postgres/client.h +++ b/src/postgres/client.h @@ -113,11 +113,11 @@ pgClientFree(PgClient *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *pgClientToLog(const PgClient *this); +FN_EXTERN void pgClientToLog(const PgClient *this, StringStatic *debugLog); #define FUNCTION_LOG_PG_CLIENT_TYPE \ PgClient * #define FUNCTION_LOG_PG_CLIENT_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, pgClientToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, pgClientToLog, buffer, bufferSize) #endif diff --git a/src/postgres/interface.c b/src/postgres/interface.c index 7ceed4fde..4be7f5a63 100644 --- a/src/postgres/interface.c +++ b/src/postgres/interface.c @@ -556,16 +556,16 @@ pgVersionToStr(unsigned int version) } /**********************************************************************************************************************************/ -FN_EXTERN String * -pgControlToLog(const PgControl *pgControl) +FN_EXTERN void +pgControlToLog(const PgControl *const pgControl, StringStatic *const debugLog) { - return strNewFmt( - "{version: %u, systemId: %" PRIu64 ", walSegmentSize: %u, pageChecksum: %s}", pgControl->version, pgControl->systemId, - pgControl->walSegmentSize, cvtBoolToConstZ(pgControl->pageChecksum)); + strStcFmt( + debugLog, "{version: %u, systemId: %" PRIu64 ", walSegmentSize: %u, pageChecksum: %s}", pgControl->version, + pgControl->systemId, pgControl->walSegmentSize, cvtBoolToConstZ(pgControl->pageChecksum)); } -FN_EXTERN String * -pgWalToLog(const PgWal *pgWal) +FN_EXTERN void +pgWalToLog(const PgWal *const pgWal, StringStatic *const debugLog) { - return strNewFmt("{version: %u, systemId: %" PRIu64 "}", pgWal->version, pgWal->systemId); + strStcFmt(debugLog, "{version: %u, systemId: %" PRIu64 "}", pgWal->version, pgWal->systemId); } diff --git a/src/postgres/interface.h b/src/postgres/interface.h index 94e4d4cf3..fbb0da1e9 100644 --- a/src/postgres/interface.h +++ b/src/postgres/interface.h @@ -177,17 +177,17 @@ FN_EXTERN const String *pgXactPath(unsigned int pgVersion); /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *pgControlToLog(const PgControl *pgControl); -FN_EXTERN String *pgWalToLog(const PgWal *pgWal); +FN_EXTERN void pgControlToLog(const PgControl *pgControl, StringStatic *debugLog); +FN_EXTERN void pgWalToLog(const PgWal *pgWal, StringStatic *debugLog); #define FUNCTION_LOG_PG_CONTROL_TYPE \ PgControl #define FUNCTION_LOG_PG_CONTROL_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, pgControlToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(&value, pgControlToLog, buffer, bufferSize) #define FUNCTION_LOG_PG_WAL_TYPE \ PgWal #define FUNCTION_LOG_PG_WAL_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(&value, pgWalToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(&value, pgWalToLog, buffer, bufferSize) #endif diff --git a/src/protocol/client.c b/src/protocol/client.c index dbdd1ec68..fe2d38b4c 100644 --- a/src/protocol/client.c +++ b/src/protocol/client.c @@ -403,8 +403,10 @@ protocolClientNoOp(ProtocolClient *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -protocolClientToLog(const ProtocolClient *this) +FN_EXTERN void +protocolClientToLog(const ProtocolClient *const this, StringStatic *const debugLog) { - return strNewFmt("{name: %s, state: %s}", strZ(this->name), strZ(strIdToStr(this->state))); + strStcFmt(debugLog, "{name: %s, state: ", strZ(this->name)); + strStcResultSizeInc(debugLog, strIdToLog(this->state, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcCatChr(debugLog, '}'); } diff --git a/src/protocol/client.h b/src/protocol/client.h index 29e1bc1b9..aeaf98097 100644 --- a/src/protocol/client.h +++ b/src/protocol/client.h @@ -121,11 +121,11 @@ protocolClientFree(ProtocolClient *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *protocolClientToLog(const ProtocolClient *this); +FN_EXTERN void protocolClientToLog(const ProtocolClient *this, StringStatic *debugLog); #define FUNCTION_LOG_PROTOCOL_CLIENT_TYPE \ ProtocolClient * #define FUNCTION_LOG_PROTOCOL_CLIENT_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, protocolClientToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, protocolClientToLog, buffer, bufferSize) #endif diff --git a/src/protocol/command.c b/src/protocol/command.c index 692e7da5b..c52344568 100644 --- a/src/protocol/command.c +++ b/src/protocol/command.c @@ -102,8 +102,10 @@ protocolCommandParam(ProtocolCommand *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -protocolCommandToLog(const ProtocolCommand *this) +FN_EXTERN void +protocolCommandToLog(const ProtocolCommand *const this, StringStatic *const debugLog) { - return strNewFmt("{command: %s}", strZ(strIdToStr(this->command))); + strStcFmt(debugLog, "{name: "); + strStcResultSizeInc(debugLog, strIdToLog(this->command, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcCatChr(debugLog, '}'); } diff --git a/src/protocol/command.h b/src/protocol/command.h index 3547d4a7d..86e6409a9 100644 --- a/src/protocol/command.h +++ b/src/protocol/command.h @@ -46,11 +46,11 @@ protocolCommandFree(ProtocolCommand *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *protocolCommandToLog(const ProtocolCommand *this); +FN_EXTERN void protocolCommandToLog(const ProtocolCommand *this, StringStatic *debugLog); #define FUNCTION_LOG_PROTOCOL_COMMAND_TYPE \ ProtocolCommand * #define FUNCTION_LOG_PROTOCOL_COMMAND_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, protocolCommandToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, protocolCommandToLog, buffer, bufferSize) #endif diff --git a/src/protocol/parallel.c b/src/protocol/parallel.c index 057e50c07..230a65da8 100644 --- a/src/protocol/parallel.c +++ b/src/protocol/parallel.c @@ -275,10 +275,10 @@ protocolParallelDone(ProtocolParallel *this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -protocolParallelToLog(const ProtocolParallel *this) +FN_EXTERN void +protocolParallelToLog(const ProtocolParallel *const this, StringStatic *const debugLog) { - return strNewFmt( - "{state: %s, clientTotal: %u, jobTotal: %u}", strZ(strIdToStr(this->state)), lstSize(this->clientList), - lstSize(this->jobList)); + strStcCat(debugLog, "{state: "); + strStcResultSizeInc(debugLog, strIdToLog(this->state, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcFmt(debugLog, ", clientTotal: %u, jobTotal: %u}", lstSize(this->clientList), lstSize(this->jobList)); } diff --git a/src/protocol/parallel.h b/src/protocol/parallel.h index 32f30d382..c73c566de 100644 --- a/src/protocol/parallel.h +++ b/src/protocol/parallel.h @@ -57,11 +57,11 @@ protocolParallelFree(ProtocolParallel *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *protocolParallelToLog(const ProtocolParallel *this); +FN_EXTERN void protocolParallelToLog(const ProtocolParallel *this, StringStatic *debugLog); #define FUNCTION_LOG_PROTOCOL_PARALLEL_TYPE \ ProtocolParallel * #define FUNCTION_LOG_PROTOCOL_PARALLEL_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, protocolParallelToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, protocolParallelToLog, buffer, bufferSize) #endif diff --git a/src/protocol/parallelJob.c b/src/protocol/parallelJob.c index d33bf5548..e5181aa43 100644 --- a/src/protocol/parallelJob.c +++ b/src/protocol/parallelJob.c @@ -130,13 +130,29 @@ protocolParallelJobStateSet(ProtocolParallelJob *this, ProtocolParallelJobState FUNCTION_LOG_RETURN_VOID(); } -FN_EXTERN String * -protocolParallelJobToLog(const ProtocolParallelJob *this) +FN_EXTERN void +protocolParallelJobToLog(const ProtocolParallelJob *const this, StringStatic *const debugLog) { - return strNewFmt( - "{state: %s, key: %s, command: %s, code: %d, message: %s, result: %s}", - strZ(strIdToStr(protocolParallelJobState(this))), strZ(varToLog(protocolParallelJobKey(this))), - strZ(protocolCommandToLog(protocolParallelJobCommand(this))), protocolParallelJobErrorCode(this), - strZ(strToLog(protocolParallelJobErrorMessage(this))), - protocolParallelJobResult(this) == NULL ? NULL_Z : strZ(pckReadToLog(protocolParallelJobResult(this)))); + strStcCat(debugLog, "{state: "); + strStcResultSizeInc(debugLog, strIdToLog(protocolParallelJobState(this), strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcCat(debugLog, ", key: "); + varToLog(protocolParallelJobKey(this), debugLog); + + strStcCat(debugLog, ", command: "); + protocolCommandToLog(protocolParallelJobCommand(this), debugLog); + + strStcCat(debugLog, ", result: "); + strStcResultSizeInc( + debugLog, + FUNCTION_LOG_OBJECT_FORMAT( + protocolParallelJobResult(this), pckReadToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcFmt(debugLog, "code: %d, message: ", protocolParallelJobErrorCode(this)); + + strStcResultSizeInc( + debugLog, + FUNCTION_LOG_OBJECT_FORMAT( + protocolParallelJobErrorMessage(this), strToLog, strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcCatChr(debugLog, '}'); } diff --git a/src/protocol/parallelJob.h b/src/protocol/parallelJob.h index cc2c03ee5..60936ca6f 100644 --- a/src/protocol/parallelJob.h +++ b/src/protocol/parallelJob.h @@ -123,11 +123,11 @@ protocolParallelJobFree(ProtocolParallelJob *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *protocolParallelJobToLog(const ProtocolParallelJob *this); +FN_EXTERN void protocolParallelJobToLog(const ProtocolParallelJob *this, StringStatic *debugLog); #define FUNCTION_LOG_PROTOCOL_PARALLEL_JOB_TYPE \ ProtocolParallelJob * #define FUNCTION_LOG_PROTOCOL_PARALLEL_JOB_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, protocolParallelJobToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, protocolParallelJobToLog, buffer, bufferSize) #endif diff --git a/src/protocol/server.c b/src/protocol/server.c index bff13408c..9947e3b96 100644 --- a/src/protocol/server.c +++ b/src/protocol/server.c @@ -383,8 +383,8 @@ protocolServerDataEndPut(ProtocolServer *const this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -protocolServerToLog(const ProtocolServer *this) +FN_EXTERN void +protocolServerToLog(const ProtocolServer *const this, StringStatic *const debugLog) { - return strNewFmt("{name: %s}", strZ(this->name)); + strStcFmt(debugLog, "{name: %s}", strZ(this->name)); } diff --git a/src/protocol/server.h b/src/protocol/server.h index d70a3aeec..7249d225d 100644 --- a/src/protocol/server.h +++ b/src/protocol/server.h @@ -84,11 +84,11 @@ protocolServerFree(ProtocolServer *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *protocolServerToLog(const ProtocolServer *this); +FN_EXTERN void protocolServerToLog(const ProtocolServer *this, StringStatic *debugLog); #define FUNCTION_LOG_PROTOCOL_SERVER_TYPE \ ProtocolServer * #define FUNCTION_LOG_PROTOCOL_SERVER_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, protocolServerToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, protocolServerToLog, buffer, bufferSize) #endif diff --git a/src/storage/azure/read.c b/src/storage/azure/read.c index 4cdca9d19..accbe4f09 100644 --- a/src/storage/azure/read.c +++ b/src/storage/azure/read.c @@ -27,7 +27,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_READ_AZURE_TYPE \ StorageReadAzure * #define FUNCTION_LOG_STORAGE_READ_AZURE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageReadAzure", buffer, bufferSize) + objNameToLog(value, "StorageReadAzure", buffer, bufferSize) /*********************************************************************************************************************************** Open the file diff --git a/src/storage/azure/storage.intern.h b/src/storage/azure/storage.intern.h index 25e402111..f9c244e72 100644 --- a/src/storage/azure/storage.intern.h +++ b/src/storage/azure/storage.intern.h @@ -75,6 +75,6 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_AZURE_TYPE \ StorageAzure * #define FUNCTION_LOG_STORAGE_AZURE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageAzure", buffer, bufferSize) + objNameToLog(value, "StorageAzure", buffer, bufferSize) #endif diff --git a/src/storage/azure/write.c b/src/storage/azure/write.c index ef86fa14a..b9b10eda9 100644 --- a/src/storage/azure/write.c +++ b/src/storage/azure/write.c @@ -53,7 +53,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_WRITE_AZURE_TYPE \ StorageWriteAzure * #define FUNCTION_LOG_STORAGE_WRITE_AZURE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageWriteAzure", buffer, bufferSize) + objNameToLog(value, "StorageWriteAzure", buffer, bufferSize) /*********************************************************************************************************************************** Open the file diff --git a/src/storage/gcs/read.c b/src/storage/gcs/read.c index 3e59ba947..b5cdd9209 100644 --- a/src/storage/gcs/read.c +++ b/src/storage/gcs/read.c @@ -33,7 +33,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_READ_GCS_TYPE \ StorageReadGcs * #define FUNCTION_LOG_STORAGE_READ_GCS_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageReadGcs", buffer, bufferSize) + objNameToLog(value, "StorageReadGcs", buffer, bufferSize) /*********************************************************************************************************************************** Open the file diff --git a/src/storage/gcs/storage.intern.h b/src/storage/gcs/storage.intern.h index 622cc58d1..2cf932ea8 100644 --- a/src/storage/gcs/storage.intern.h +++ b/src/storage/gcs/storage.intern.h @@ -101,6 +101,6 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_GCS_TYPE \ StorageGcs * #define FUNCTION_LOG_STORAGE_GCS_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageGcs", buffer, bufferSize) + objNameToLog(value, "StorageGcs", buffer, bufferSize) #endif diff --git a/src/storage/gcs/write.c b/src/storage/gcs/write.c index a64a3b4c5..b7b3c5d80 100644 --- a/src/storage/gcs/write.c +++ b/src/storage/gcs/write.c @@ -42,7 +42,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_WRITE_GCS_TYPE \ StorageWriteGcs * #define FUNCTION_LOG_STORAGE_WRITE_GCS_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageWriteGcs", buffer, bufferSize) + objNameToLog(value, "StorageWriteGcs", buffer, bufferSize) /*********************************************************************************************************************************** Open the file diff --git a/src/storage/info.h b/src/storage/info.h index 2f78b745d..7d6f99631 100644 --- a/src/storage/info.h +++ b/src/storage/info.h @@ -74,6 +74,6 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_INFO_TYPE \ StorageInfo #define FUNCTION_LOG_STORAGE_INFO_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "StorageInfo", buffer, bufferSize) + objNameToLog(&value, "StorageInfo", buffer, bufferSize) #endif diff --git a/src/storage/iterator.c b/src/storage/iterator.c index ada2ae56e..aa9919e82 100644 --- a/src/storage/iterator.c +++ b/src/storage/iterator.c @@ -274,8 +274,10 @@ FN_EXTERN StorageInfo storageItrNext(StorageIterator *const this) } /**********************************************************************************************************************************/ -FN_EXTERN String * -storageItrToLog(const StorageIterator *const this) +FN_EXTERN void +storageItrToLog(const StorageIterator *const this, StringStatic *const debugLog) { - return strNewFmt("{stack: %s}", strZ(lstToLog(this->stack))); + strStcCat(debugLog, "{stack: "); + lstToLog(this->stack, debugLog); + strStcCatChr(debugLog, '}'); } diff --git a/src/storage/iterator.h b/src/storage/iterator.h index 0eff27dc8..dee48bbfe 100644 --- a/src/storage/iterator.h +++ b/src/storage/iterator.h @@ -48,11 +48,11 @@ storageItrFree(StorageIterator *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *storageItrToLog(const StorageIterator *this); +FN_EXTERN void storageItrToLog(const StorageIterator *this, StringStatic *debugLog); #define FUNCTION_LOG_STORAGE_ITERATOR_TYPE \ StorageIterator * #define FUNCTION_LOG_STORAGE_ITERATOR_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, storageItrToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, storageItrToLog, buffer, bufferSize) #endif diff --git a/src/storage/list.c b/src/storage/list.c index 02e0c1719..8194355bb 100644 --- a/src/storage/list.c +++ b/src/storage/list.c @@ -208,8 +208,8 @@ storageLstGet(StorageList *const this, const unsigned int idx) } /**********************************************************************************************************************************/ -FN_EXTERN String * -storageLstToLog(const StorageList *const this) +FN_EXTERN void +storageLstToLog(const StorageList *const this, StringStatic *const debugLog) { - return strNewFmt("{size: %u}", lstSize(this->pub.list)); + strStcFmt(debugLog, "{size: %u}", lstSize(this->pub.list)); } diff --git a/src/storage/list.h b/src/storage/list.h index c68043f61..0ed31cdab 100644 --- a/src/storage/list.h +++ b/src/storage/list.h @@ -89,11 +89,11 @@ storageLstFree(StorageList *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *storageLstToLog(const StorageList *this); +FN_EXTERN void storageLstToLog(const StorageList *this, StringStatic *debugLog); #define FUNCTION_LOG_STORAGE_LIST_TYPE \ StorageList * #define FUNCTION_LOG_STORAGE_LIST_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, storageLstToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, storageLstToLog, buffer, bufferSize) #endif diff --git a/src/storage/posix/read.c b/src/storage/posix/read.c index 84df1e95d..34b1ee342 100644 --- a/src/storage/posix/read.c +++ b/src/storage/posix/read.c @@ -33,7 +33,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_READ_POSIX_TYPE \ StorageReadPosix * #define FUNCTION_LOG_STORAGE_READ_POSIX_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageReadPosix", buffer, bufferSize) + objNameToLog(value, "StorageReadPosix", buffer, bufferSize) /*********************************************************************************************************************************** Close file descriptor diff --git a/src/storage/posix/storage.intern.h b/src/storage/posix/storage.intern.h index 217b0e2c8..d72953083 100644 --- a/src/storage/posix/storage.intern.h +++ b/src/storage/posix/storage.intern.h @@ -24,6 +24,6 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_POSIX_TYPE \ StoragePosix * #define FUNCTION_LOG_STORAGE_POSIX_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StoragePosix *", buffer, bufferSize) + objNameToLog(value, "StoragePosix *", buffer, bufferSize) #endif diff --git a/src/storage/posix/write.c b/src/storage/posix/write.c index 9bb94b7aa..663f6f8e5 100644 --- a/src/storage/posix/write.c +++ b/src/storage/posix/write.c @@ -35,7 +35,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_WRITE_POSIX_TYPE \ StorageWritePosix * #define FUNCTION_LOG_STORAGE_WRITE_POSIX_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageWritePosix", buffer, bufferSize) + objNameToLog(value, "StorageWritePosix", buffer, bufferSize) /*********************************************************************************************************************************** File open constants diff --git a/src/storage/read.c b/src/storage/read.c index 9e235228c..bdaa542b6 100644 --- a/src/storage/read.c +++ b/src/storage/read.c @@ -23,7 +23,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_READ_INTERFACE_TYPE \ StorageReadInterface #define FUNCTION_LOG_STORAGE_READ_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "StorageReadInterface", buffer, bufferSize) + objNameToLog(&value, "StorageReadInterface", buffer, bufferSize) /**********************************************************************************************************************************/ FN_EXTERN StorageRead * @@ -56,10 +56,11 @@ storageReadNew(void *driver, const StorageReadInterface *interface) } /**********************************************************************************************************************************/ -FN_EXTERN String * -storageReadToLog(const StorageRead *this) +FN_EXTERN void +storageReadToLog(const StorageRead *const this, StringStatic *const debugLog) { - return strNewFmt( - "{type: %s, name: %s, ignoreMissing: %s}", strZ(strIdToStr(storageReadType(this))), strZ(strToLog(storageReadName(this))), - cvtBoolToConstZ(storageReadIgnoreMissing(this))); + strStcCat(debugLog, "{type: "); + strStcResultSizeInc(debugLog, strIdToLog(storageReadType(this), strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcFmt( + debugLog, ", name: %s, ignoreMissing: %s}", strZ(storageReadName(this)), cvtBoolToConstZ(storageReadIgnoreMissing(this))); } diff --git a/src/storage/read.h b/src/storage/read.h index 7b7411b18..731784d53 100644 --- a/src/storage/read.h +++ b/src/storage/read.h @@ -87,11 +87,11 @@ storageReadFree(StorageRead *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *storageReadToLog(const StorageRead *this); +FN_EXTERN void storageReadToLog(const StorageRead *this, StringStatic *debugLog); #define FUNCTION_LOG_STORAGE_READ_TYPE \ StorageRead * #define FUNCTION_LOG_STORAGE_READ_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, storageReadToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, storageReadToLog, buffer, bufferSize) #endif diff --git a/src/storage/remote/read.c b/src/storage/remote/read.c index 17a2af22e..7fd34d714 100644 --- a/src/storage/remote/read.c +++ b/src/storage/remote/read.c @@ -42,7 +42,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_READ_REMOTE_TYPE \ StorageReadRemote * #define FUNCTION_LOG_STORAGE_READ_REMOTE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageReadRemote", buffer, bufferSize) + objNameToLog(value, "StorageReadRemote", buffer, bufferSize) /*********************************************************************************************************************************** Clear protocol if the entire file is not read or an error occurs before the read is complete. This is required to clear the diff --git a/src/storage/remote/storage.intern.h b/src/storage/remote/storage.intern.h index d3e843942..9be3072bb 100644 --- a/src/storage/remote/storage.intern.h +++ b/src/storage/remote/storage.intern.h @@ -17,6 +17,6 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_REMOTE_TYPE \ StorageRemote * #define FUNCTION_LOG_STORAGE_REMOTE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageRemote", buffer, bufferSize) + objNameToLog(value, "StorageRemote", buffer, bufferSize) #endif diff --git a/src/storage/remote/write.c b/src/storage/remote/write.c index 4046b2b52..c2795f58b 100644 --- a/src/storage/remote/write.c +++ b/src/storage/remote/write.c @@ -34,7 +34,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_WRITE_REMOTE_TYPE \ StorageWriteRemote * #define FUNCTION_LOG_STORAGE_WRITE_REMOTE_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageWriteRemote", buffer, bufferSize) + objNameToLog(value, "StorageWriteRemote", buffer, bufferSize) /*********************************************************************************************************************************** Close file on the remote diff --git a/src/storage/s3/read.c b/src/storage/s3/read.c index 179c2fe34..9b10d8660 100644 --- a/src/storage/s3/read.c +++ b/src/storage/s3/read.c @@ -30,7 +30,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_READ_S3_TYPE \ StorageReadS3 * #define FUNCTION_LOG_STORAGE_READ_S3_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageReadS3", buffer, bufferSize) + objNameToLog(value, "StorageReadS3", buffer, bufferSize) /*********************************************************************************************************************************** Open the file diff --git a/src/storage/s3/storage.intern.h b/src/storage/s3/storage.intern.h index 8ef5a105d..64dcc58e8 100644 --- a/src/storage/s3/storage.intern.h +++ b/src/storage/s3/storage.intern.h @@ -66,6 +66,6 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_S3_TYPE \ StorageS3 * #define FUNCTION_LOG_STORAGE_S3_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageS3", buffer, bufferSize) + objNameToLog(value, "StorageS3", buffer, bufferSize) #endif diff --git a/src/storage/s3/write.c b/src/storage/s3/write.c index 7c1c662cd..8df3e90a1 100644 --- a/src/storage/s3/write.c +++ b/src/storage/s3/write.c @@ -47,7 +47,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_WRITE_S3_TYPE \ StorageWriteS3 * #define FUNCTION_LOG_STORAGE_WRITE_S3_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "StorageWriteS3", buffer, bufferSize) + objNameToLog(value, "StorageWriteS3", buffer, bufferSize) /*********************************************************************************************************************************** Open the file diff --git a/src/storage/storage.c b/src/storage/storage.c index 7a03045dd..d55a55386 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -756,10 +756,10 @@ storageRemove(const Storage *this, const String *fileExp, StorageRemoveParam par } /**********************************************************************************************************************************/ -FN_EXTERN String * -storageToLog(const Storage *this) +FN_EXTERN void +storageToLog(const Storage *const this, StringStatic *const debugLog) { - return strNewFmt( - "{type: %s, path: %s, write: %s}", strZ(strIdToStr(storageType(this))), strZ(strToLog(this->path)), - cvtBoolToConstZ(this->write)); + strStcCat(debugLog, "{type: "), + strStcResultSizeInc(debugLog, strIdToLog(storageType(this), strStcRemains(debugLog), strStcRemainsSize(debugLog))); + strStcFmt(debugLog, ", path: %s, write: %s}", strZ(this->path), cvtBoolToConstZ(this->write)); } diff --git a/src/storage/storage.h b/src/storage/storage.h index 5d9b23760..49bc3cff4 100644 --- a/src/storage/storage.h +++ b/src/storage/storage.h @@ -292,11 +292,11 @@ storageType(const Storage *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *storageToLog(const Storage *this); +FN_EXTERN void storageToLog(const Storage *this, StringStatic *debugLog); #define FUNCTION_LOG_STORAGE_TYPE \ Storage * #define FUNCTION_LOG_STORAGE_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, storageToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, storageToLog, buffer, bufferSize) #endif diff --git a/src/storage/storage.intern.h b/src/storage/storage.intern.h index 9bed05d36..cef4794e7 100644 --- a/src/storage/storage.intern.h +++ b/src/storage/storage.intern.h @@ -355,6 +355,6 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_INTERFACE_TYPE \ StorageInterface #define FUNCTION_LOG_STORAGE_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "StorageInterface", buffer, bufferSize) + objNameToLog(&value, "StorageInterface", buffer, bufferSize) #endif diff --git a/src/storage/write.c b/src/storage/write.c index b67325450..bd053f808 100644 --- a/src/storage/write.c +++ b/src/storage/write.c @@ -23,7 +23,7 @@ Macros for function logging #define FUNCTION_LOG_STORAGE_WRITE_INTERFACE_TYPE \ StorageWriteInterface #define FUNCTION_LOG_STORAGE_WRITE_INTERFACE_FORMAT(value, buffer, bufferSize) \ - objToLog(&value, "StorageWriteInterface", buffer, bufferSize) + objNameToLog(&value, "StorageWriteInterface", buffer, bufferSize) /*********************************************************************************************************************************** This object expects its context to be created in advance. This is so the calling function can add whatever data it wants without @@ -57,12 +57,15 @@ storageWriteNew(void *driver, const StorageWriteInterface *interface) } /**********************************************************************************************************************************/ -FN_EXTERN String * -storageWriteToLog(const StorageWrite *this) +FN_EXTERN void +storageWriteToLog(const StorageWrite *const this, StringStatic *const debugLog) { - return strNewFmt( - "{type: %s, name: %s, modeFile: %04o, modePath: %04o, createPath: %s, syncFile: %s, syncPath: %s, atomic: %s}", - strZ(strIdToStr(storageWriteType(this))), strZ(strToLog(storageWriteName(this))), storageWriteModeFile(this), - storageWriteModePath(this), cvtBoolToConstZ(storageWriteCreatePath(this)), cvtBoolToConstZ(storageWriteSyncFile(this)), + strStcCat(debugLog, "{type: "); + strStcResultSizeInc(debugLog, strIdToLog(storageWriteType(this), strStcRemains(debugLog), strStcRemainsSize(debugLog))); + + strStcFmt( + debugLog, ", name: %s, modeFile: %04o, modePath: %04o, createPath: %s, syncFile: %s, syncPath: %s, atomic: %s}", + strZ(storageWriteName(this)), storageWriteModeFile(this), storageWriteModePath(this), + cvtBoolToConstZ(storageWriteCreatePath(this)), cvtBoolToConstZ(storageWriteSyncFile(this)), cvtBoolToConstZ(storageWriteSyncPath(this)), cvtBoolToConstZ(storageWriteAtomic(this))); } diff --git a/src/storage/write.h b/src/storage/write.h index 600cd628c..6674c155c 100644 --- a/src/storage/write.h +++ b/src/storage/write.h @@ -119,11 +119,11 @@ storageWriteFree(StorageWrite *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ -FN_EXTERN String *storageWriteToLog(const StorageWrite *this); +FN_EXTERN void storageWriteToLog(const StorageWrite *this, StringStatic *debugLog); #define FUNCTION_LOG_STORAGE_WRITE_TYPE \ StorageWrite * #define FUNCTION_LOG_STORAGE_WRITE_FORMAT(value, buffer, bufferSize) \ - FUNCTION_LOG_STRING_OBJECT_FORMAT(value, storageWriteToLog, buffer, bufferSize) + FUNCTION_LOG_OBJECT_FORMAT(value, storageWriteToLog, buffer, bufferSize) #endif diff --git a/test/define.yaml b/test/define.yaml index c0fcf01c5..950ede889 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -77,6 +77,7 @@ unit: depend: - common/debug + - common/type/stringStatic # ---------------------------------------------------------------------------------------------------------------------------- - name: type-convert @@ -98,9 +99,6 @@ unit: total: 1 define: -DNDEBUG - coverage: - - common/debug - # ---------------------------------------------------------------------------------------------------------------------------- - name: assert-on feature: assert @@ -211,11 +209,12 @@ unit: # ---------------------------------------------------------------------------------------------------------------------------- - name: debug-on - total: 3 + total: 4 feature: debug coverage: - common/debug + - common/type/stringStatic # ---------------------------------------------------------------------------------------------------------------------------- - name: fork diff --git a/test/src/command/test/build.h b/test/src/command/test/build.h index b726d7811..ac2663810 100644 --- a/test/src/command/test/build.h +++ b/test/src/command/test/build.h @@ -172,6 +172,6 @@ Macros for function logging #define FUNCTION_LOG_TEST_BUILD_TYPE \ TestBuild * #define FUNCTION_LOG_TEST_BUILD_FORMAT(value, buffer, bufferSize) \ - objToLog(value, "TestBuild", buffer, bufferSize) + objNameToLog(value, "TestBuild", buffer, bufferSize) #endif diff --git a/test/src/module/common/compressTest.c b/test/src/module/common/compressTest.c index c3d9aa456..100236dc2 100644 --- a/test/src/module/common/compressTest.c +++ b/test/src/module/common/compressTest.c @@ -206,14 +206,18 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("gzDecompressToLog() and gzCompressToLog()"); + char buffer[STACK_TRACE_PARAM_MAX]; + GzDecompress *decompress = (GzDecompress *)ioFilterDriver(gzDecompressNew()); - TEST_RESULT_STR_Z(gzDecompressToLog(decompress), "{inputSame: false, done: false, availIn: 0}", "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(decompress, gzDecompressToLog, buffer, sizeof(buffer)), "gzDecompressToLog"); + TEST_RESULT_Z(buffer, "{inputSame: false, done: false, availIn: 0}", "check log"); decompress->inputSame = true; decompress->done = true; - TEST_RESULT_STR_Z(gzDecompressToLog(decompress), "{inputSame: true, done: true, availIn: 0}", "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(decompress, gzDecompressToLog, buffer, sizeof(buffer)), "gzDecompressToLog"); + TEST_RESULT_Z(buffer, "{inputSame: true, done: true, availIn: 0}", "check log"); } // ***************************************************************************************************************************** @@ -251,19 +255,22 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("bz2DecompressToLog() and bz2CompressToLog()"); + char buffer[STACK_TRACE_PARAM_MAX]; + Bz2Compress *compress = (Bz2Compress *)ioFilterDriver(bz2CompressNew(1)); compress->stream.avail_in = 999; - TEST_RESULT_STR_Z( - bz2CompressToLog(compress), "{inputSame: false, done: false, flushing: false, avail_in: 999}", "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(compress, bz2CompressToLog, buffer, sizeof(buffer)), "bz2CompressToLog"); + TEST_RESULT_Z(buffer, "{inputSame: false, done: false, flushing: false, avail_in: 999}", "check log"); Bz2Decompress *decompress = (Bz2Decompress *)ioFilterDriver(bz2DecompressNew()); decompress->inputSame = true; decompress->done = true; - TEST_RESULT_STR_Z(bz2DecompressToLog(decompress), "{inputSame: true, done: true, avail_in: 0}", "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(decompress, bz2DecompressToLog, buffer, sizeof(buffer)), "bz2DecompressToLog"); + TEST_RESULT_Z(buffer, "{inputSame: true, done: true, avail_in: 0}", "check log"); } // ***************************************************************************************************************************** @@ -289,13 +296,15 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("lz4DecompressToLog() and lz4CompressToLog()"); + char buffer[STACK_TRACE_PARAM_MAX]; + Lz4Compress *compress = (Lz4Compress *)ioFilterDriver(lz4CompressNew(7)); compress->inputSame = true; compress->flushing = true; - TEST_RESULT_STR_Z( - lz4CompressToLog(compress), "{level: 7, first: true, inputSame: true, flushing: true}", "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(compress, lz4CompressToLog, buffer, sizeof(buffer)), "lz4CompressToLog"); + TEST_RESULT_Z(buffer, "{level: 7, first: true, inputSame: true, flushing: true}", "check log"); Lz4Decompress *decompress = (Lz4Decompress *)ioFilterDriver(lz4DecompressNew()); @@ -303,9 +312,8 @@ testRun(void) decompress->done = true; decompress->inputOffset = 999; - TEST_RESULT_STR_Z( - lz4DecompressToLog(decompress), "{inputSame: true, inputOffset: 999, frameDone false, done: true}", - "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(decompress, lz4DecompressToLog, buffer, sizeof(buffer)), "lz4DecompressToLog"); + TEST_RESULT_Z(buffer, "{inputSame: true, inputOffset: 999, frameDone false, done: true}", "check log"); #else TEST_ERROR(compressTypePresent(compressTypeLz4), OptionInvalidValueError, "pgBackRest not compiled with lz4 support"); #endif // HAVE_LIBLZ4 @@ -334,14 +342,16 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("zstDecompressToLog() and zstCompressToLog()"); + char buffer[STACK_TRACE_PARAM_MAX]; + ZstCompress *compress = (ZstCompress *)ioFilterDriver(zstCompressNew(14)); compress->inputSame = true; compress->inputOffset = 49; compress->flushing = true; - TEST_RESULT_STR_Z( - zstCompressToLog(compress), "{level: 14, inputSame: true, inputOffset: 49, flushing: true}", "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(compress, zstCompressToLog, buffer, sizeof(buffer)), "zstCompressToLog"); + TEST_RESULT_Z(buffer, "{level: 14, inputSame: true, inputOffset: 49, flushing: true}", "check log"); ZstDecompress *decompress = (ZstDecompress *)ioFilterDriver(zstDecompressNew()); @@ -349,9 +359,8 @@ testRun(void) decompress->done = true; decompress->inputOffset = 999; - TEST_RESULT_STR_Z( - zstDecompressToLog(decompress), "{inputSame: true, inputOffset: 999, frameDone false, done: true}", - "format object"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(decompress, zstDecompressToLog, buffer, sizeof(buffer)), "zstDecompressToLog"); + TEST_RESULT_Z(buffer, "{inputSame: true, inputOffset: 999, frameDone false, done: true}", "check log"); #else TEST_ERROR(compressTypePresent(compressTypeZst), OptionInvalidValueError, "pgBackRest not compiled with zst support"); #endif // HAVE_LIBZST diff --git a/test/src/module/common/debugOnTest.c b/test/src/module/common/debugOnTest.c index 3f38664a0..ce661e535 100644 --- a/test/src/module/common/debugOnTest.c +++ b/test/src/module/common/debugOnTest.c @@ -42,6 +42,11 @@ testFunction1( FUNCTION_LOG_RETURN(INT, 1); } +static void testObjToLog(const char *const object, StringStatic *const debugLog) +{ + strStcFmt(debugLog, "{%s}", object); +} + /*********************************************************************************************************************************** Test Run ***********************************************************************************************************************************/ @@ -51,30 +56,99 @@ testRun(void) FUNCTION_HARNESS_VOID(); // ***************************************************************************************************************************** - if (testBegin("objToLog(), ptrToLog, and strzToLog()")) + if (testBegin("strStc*()")) + { + const char *test8 = "12345678"; + char buffer9[9]; + + StringStatic debugLog = strStcInit(buffer9, sizeof(buffer9) - 1); + TEST_RESULT_UINT(strStcResultSize(strStcFmt(&debugLog, "%s", test8)), 7, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 1, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 7, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "1234567", "check buffer"); + + debugLog = strStcInit(buffer9, sizeof(buffer9)); + TEST_RESULT_UINT(strStcResultSize(strStcFmt(&debugLog, "%s", test8)), 8, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 1, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 8, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "12345678", "check buffer"); + + TEST_RESULT_UINT(strStcResultSize(strStcFmt(&debugLog, "%s", test8)), 8, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 1, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 8, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "12345678", "check buffer"); + + debugLog = strStcInit(buffer9, 4); + TEST_RESULT_VOID(strStcCat(&debugLog, "AA"), "cat all"); + TEST_RESULT_UINT(strStcResultSize(&debugLog), 2, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 2, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 2, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "AA", "check buffer"); + + TEST_RESULT_VOID(strStcCat(&debugLog, "BB"), "cat partial"); + TEST_RESULT_UINT(strStcResultSize(&debugLog), 3, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 1, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 3, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "AAB", "check buffer"); + + TEST_RESULT_VOID(strStcCat(&debugLog, "CC"), "cat none"); + TEST_RESULT_UINT(strStcResultSize(&debugLog), 3, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 1, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 3, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "AAB", "check buffer"); + + debugLog = strStcInit(buffer9, 2); + TEST_RESULT_VOID(strStcCatChr(&debugLog, 'Z'), "cat char"); + TEST_RESULT_UINT(strStcResultSize(&debugLog), 1, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 1, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 1, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "Z", "check buffer"); + + TEST_RESULT_VOID(strStcCatChr(&debugLog, 'Y'), "cat char"); + TEST_RESULT_UINT(strStcResultSize(&debugLog), 1, "result size"); + TEST_RESULT_UINT(strStcRemainsSize(&debugLog), 1, "buffer size"); + TEST_RESULT_PTR(strStcRemains(&debugLog), buffer9 + 1, "buffer remains"); + TEST_RESULT_Z(debugLog.buffer, "Z", "check buffer"); + } + + // ***************************************************************************************************************************** + if (testBegin("objToLog(), objNameToLog(), ptrToLog, and strzToLog()")) { char buffer[STACK_TRACE_PARAM_MAX]; - TEST_RESULT_UINT(objToLog(NULL, "Object", buffer, 4), 4, "truncated null"); - TEST_RESULT_Z(buffer, "nul", " check truncated null"); + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("objToLog()"); - TEST_RESULT_UINT(objToLog(NULL, "Object", buffer, sizeof(buffer)), 4, "full null"); + TEST_RESULT_UINT(objToLog(NULL, (ObjToLogFormat)testObjToLog, buffer, sizeof(buffer)), 4, "null"); TEST_RESULT_Z(buffer, "null", " check full null"); - TEST_RESULT_UINT(objToLog((void *)1, "Object", buffer, 4), 8, "truncated object"); + TEST_RESULT_UINT(objToLog("test", (ObjToLogFormat)testObjToLog, buffer, 4), 3, "null"); + TEST_RESULT_Z(buffer, "{te", " check full null"); + + TEST_RESULT_UINT(objToLog("test", (ObjToLogFormat)testObjToLog, buffer, sizeof(buffer)), 6, "null"); + TEST_RESULT_Z(buffer, "{test}", " check full null"); + + // ------------------------------------------------------------------------------------------------------------------------- + TEST_RESULT_UINT(objNameToLog(NULL, "Object", buffer, 4), 3, "truncated null"); + TEST_RESULT_Z(buffer, "nul", " check truncated null"); + + TEST_RESULT_UINT(objNameToLog(NULL, "Object", buffer, sizeof(buffer)), 4, "full null"); + TEST_RESULT_Z(buffer, "null", " check full null"); + + TEST_RESULT_UINT(objNameToLog((void *)1, "Object", buffer, 4), 3, "truncated object"); TEST_RESULT_Z(buffer, "{Ob", " check truncated object"); - TEST_RESULT_UINT(objToLog((void *)1, "Object", buffer, sizeof(buffer)), 8, "full object"); + TEST_RESULT_UINT(objNameToLog((void *)1, "Object", buffer, sizeof(buffer)), 8, "full object"); TEST_RESULT_Z(buffer, "{Object}", " check full object"); // ------------------------------------------------------------------------------------------------------------------------- - TEST_RESULT_UINT(ptrToLog(NULL, "char *", buffer, 4), 4, "truncated null"); + TEST_RESULT_UINT(ptrToLog(NULL, "char *", buffer, 4), 3, "truncated null"); TEST_RESULT_Z(buffer, "nul", " check truncated null"); TEST_RESULT_UINT(ptrToLog(NULL, "char *", buffer, sizeof(buffer)), 4, "full null"); TEST_RESULT_Z(buffer, "null", " check full null"); - TEST_RESULT_UINT(ptrToLog((void *)1, "char *", buffer, 4), 8, "truncated pointer"); + TEST_RESULT_UINT(ptrToLog((void *)1, "char *", buffer, 4), 3, "truncated pointer"); TEST_RESULT_Z(buffer, "(ch", " check truncated pointer"); TEST_RESULT_UINT(ptrToLog((void *)1, "char *", buffer, sizeof(buffer)), 8, "full pointer"); diff --git a/test/src/module/common/ioHttpTest.c b/test/src/module/common/ioHttpTest.c index 5b0b01701..0a28ea193 100644 --- a/test/src/module/common/ioHttpTest.c +++ b/test/src/module/common/ioHttpTest.c @@ -55,6 +55,7 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("HttpHeader")) { + char logBuf[STACK_TRACE_PARAM_MAX]; HttpHeader *header = NULL; MEM_CONTEXT_TEMP_BEGIN() @@ -88,7 +89,8 @@ testRun(void) httpHeaderGet(httpHeaderPutRange(header, 44, NULL), HTTP_HEADER_RANGE_STR), "bytes=44-", "put range header with offset"); - TEST_RESULT_STR_Z(httpHeaderToLog(header), "{key1: 'value1', key2: 'value2a, value2b', range: 'bytes=44-'}", "log output"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(header, httpHeaderToLog, logBuf, sizeof(logBuf)), "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{key2: 'value2a, value2b', key1: 'value1', range: 'bytes=44-'}", "check log"); TEST_RESULT_VOID(httpHeaderFree(header), "free header"); @@ -101,25 +103,29 @@ testRun(void) httpHeaderAdd(header, STRDEF("secret"), STRDEF("secret-value")); httpHeaderAdd(header, STRDEF("public"), STRDEF("public-value")); - TEST_RESULT_STR_Z(httpHeaderToLog(header), "{public: 'public-value', secret: }", "log output"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(header, httpHeaderToLog, logBuf, sizeof(logBuf)), "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{secret: , public: 'public-value'}", "check log"); // Duplicate // ------------------------------------------------------------------------------------------------------------------------- redact = strLstNew(); strLstAddZ(redact, "public"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpHeaderDup(header, NULL)), "{public: 'public-value', secret: }", - "dup and keep redactions"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpHeaderDup(header, redact)), "{public: , secret: 'secret-value'}", - "dup and change redactions"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpHeaderDup(header, NULL), httpHeaderToLog, logBuf, sizeof(logBuf)), "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{secret: , public: 'public-value'}", "check log"); + + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpHeaderDup(header, redact), httpHeaderToLog, logBuf, sizeof(logBuf)), "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{secret: 'secret-value', public: }", "check log"); + TEST_RESULT_PTR(httpHeaderDup(NULL, NULL), NULL, "dup null header"); } // ***************************************************************************************************************************** if (testBegin("HttpQuery")) { + char logBuf[STACK_TRACE_PARAM_MAX]; HttpQuery *query = NULL; MEM_CONTEXT_TEMP_BEGIN() @@ -152,7 +158,8 @@ testRun(void) TEST_RESULT_STR_Z(httpQueryGet(query, STRDEF("key2")), "value2a", "get value"); TEST_RESULT_STR(httpQueryGet(query, STRDEF(BOGUS_STR)), NULL, "get missing value"); - TEST_RESULT_STR_Z(httpQueryToLog(query), "{key1: 'value 1?', key2: }", "log output"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(query, httpQueryToLog, logBuf, sizeof(logBuf)), "httpQueryToLog"); + TEST_RESULT_Z(logBuf, "{key2: , key1: 'value 1?'}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("dup query with redaction"); @@ -161,7 +168,8 @@ testRun(void) strLstAddZ(redactList, "key1"); TEST_ASSIGN(query, httpQueryDupP(query, .redactList = redactList), "dup query"); - TEST_RESULT_STR_Z(httpQueryToLog(query), "{key1: , key2: 'value2a'}", "log output"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(query, httpQueryToLog, logBuf, sizeof(logBuf)), "httpQueryToLog"); + TEST_RESULT_Z(logBuf, "{key2: 'value2a', key1: }", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("new query from string"); @@ -187,6 +195,7 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("HttpUrl")) { + char logBuf[STACK_TRACE_PARAM_MAX]; HttpUrl *url = NULL; // ------------------------------------------------------------------------------------------------------------------------- @@ -209,7 +218,8 @@ testRun(void) TEST_RESULT_STR_Z(httpUrlPath(url), "/", "check path"); TEST_RESULT_UINT(httpUrlPort(url), 80, "check port"); TEST_RESULT_UINT(httpUrlProtocolType(url), httpProtocolTypeHttp, "check protocol"); - TEST_RESULT_STR_Z(httpUrlToLog(url), "{http://test:80/}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(url, httpUrlToLog, logBuf, sizeof(logBuf)), "httpUrlToLog"); + TEST_RESULT_Z(logBuf, "{http://test:80/}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("host and port"); @@ -220,7 +230,8 @@ testRun(void) TEST_RESULT_STR_Z(httpUrlPath(url), "/", "check path"); TEST_RESULT_UINT(httpUrlPort(url), 4443, "check port"); TEST_RESULT_UINT(httpUrlProtocolType(url), httpProtocolTypeHttps, "check protocol"); - TEST_RESULT_STR_Z(httpUrlToLog(url), "{https://gcs:4443/}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(url, httpUrlToLog, logBuf, sizeof(logBuf)), "httpUrlToLog"); + TEST_RESULT_Z(logBuf, "{https://gcs:4443/}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("http but expected https"); @@ -238,7 +249,8 @@ testRun(void) TEST_RESULT_STR_Z(httpUrlPath(url), "/path", "check path"); TEST_RESULT_UINT(httpUrlPort(url), 445, "check port"); TEST_RESULT_UINT(httpUrlProtocolType(url), httpProtocolTypeHttps, "check protocol"); - TEST_RESULT_STR_Z(httpUrlToLog(url), "{https://test.com:445/path}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(url, httpUrlToLog, logBuf, sizeof(logBuf)), "httpUrlToLog"); + TEST_RESULT_Z(logBuf, "{https://test.com:445/path}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("host only"); @@ -249,7 +261,8 @@ testRun(void) TEST_RESULT_STR_Z(httpUrlPath(url), "/", "check path"); TEST_RESULT_UINT(httpUrlPort(url), 443, "check port"); TEST_RESULT_UINT(httpUrlProtocolType(url), httpProtocolTypeHttps, "check protocol"); - TEST_RESULT_STR_Z(httpUrlToLog(url), "{https://test.com:443/}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(url, httpUrlToLog, logBuf, sizeof(logBuf)), "httpUrlToLog"); + TEST_RESULT_Z(logBuf, "{https://test.com:443/}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("IPv6"); @@ -260,7 +273,8 @@ testRun(void) TEST_RESULT_STR_Z(httpUrlPath(url), "/", "check path"); TEST_RESULT_UINT(httpUrlPort(url), 81, "check port"); TEST_RESULT_UINT(httpUrlProtocolType(url), httpProtocolTypeHttp, "check protocol"); - TEST_RESULT_STR_Z(httpUrlToLog(url), "{http://[2001:db8::ff00:42:8329]:81/}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(url, httpUrlToLog, logBuf, sizeof(logBuf)), "httpUrlToLog"); + TEST_RESULT_Z(logBuf, "{http://[2001:db8::ff00:42:8329]:81/}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("IPv6 no port"); @@ -271,7 +285,8 @@ testRun(void) TEST_RESULT_STR_Z(httpUrlPath(url), "/url", "check path"); TEST_RESULT_UINT(httpUrlPort(url), 80, "check port"); TEST_RESULT_UINT(httpUrlProtocolType(url), httpProtocolTypeHttp, "check protocol"); - TEST_RESULT_STR_Z(httpUrlToLog(url), "{http://[2001:db8::ff00:42:8329]:80/url}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(url, httpUrlToLog, logBuf, sizeof(logBuf)), "httpUrlToLog"); + TEST_RESULT_Z(logBuf, "{http://[2001:db8::ff00:42:8329]:80/url}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("free"); @@ -282,6 +297,7 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("HttpClient")) { + char logBuf[STACK_TRACE_PARAM_MAX]; HttpClient *client = NULL; TEST_ASSIGN(client, httpClientNew(sckClientNew(STRDEF("localhost"), hrnServerPort(0), 500, 500), 500), "new client"); @@ -503,9 +519,11 @@ testRun(void) TEST_RESULT_BOOL(httpResponseCodeOk(response), true, "check response code ok"); TEST_RESULT_STR_Z(httpResponseReason(response), "OK", "check response message"); TEST_RESULT_UINT(httpResponseEof(response), true, "io is eof"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), - "{connection: 'ack', content-length: '0', key1: '0', key2: 'value2'}", "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z( + logBuf, "{key1: '0', key2: 'value2', connection: 'ack', content-length: '0'}", "check response headers"); TEST_RESULT_UINT(bufSize(httpResponseContent(response)), 0, "content is empty"); TEST_RESULT_VOID(httpResponseFree(response), "free response"); @@ -524,8 +542,10 @@ testRun(void) TEST_RESULT_STR_Z(httpResponseReason(response), "OK", "check response message"); TEST_RESULT_BOOL(httpResponseEof(response), true, "io is eof"); TEST_RESULT_PTR(response->session, NULL, "session is not busy"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{content-length: '380'}", "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{content-length: '380'}", "check response headers"); // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("head request with transfer encoding but no content"); @@ -540,8 +560,10 @@ testRun(void) TEST_RESULT_STR_Z(httpResponseReason(response), "OK", "check response message"); TEST_RESULT_BOOL(httpResponseEof(response), true, "io is eof"); TEST_RESULT_PTR(response->session, NULL, "session is not busy"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{transfer-encoding: 'chunked'}", "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{transfer-encoding: 'chunked'}", "check response headers"); // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("head request with connection close but no content"); @@ -556,8 +578,10 @@ testRun(void) TEST_RESULT_STR_Z(httpResponseReason(response), "OK", "check response message"); TEST_RESULT_BOOL(httpResponseEof(response), true, "io is eof"); TEST_RESULT_PTR(response->session, NULL, "session is not busy"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{connection: 'close'}", "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{connection: 'close'}", "check response headers"); // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("error with content (with a few slow down errors)"); @@ -585,8 +609,10 @@ testRun(void) TEST_RESULT_UINT(httpResponseCode(response), 404, "check response code"); TEST_RESULT_BOOL(httpResponseCodeOk(response), false, "check response code error"); TEST_RESULT_STR_Z(httpResponseReason(response), "Not Found", "check response message"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{}", "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{}", "check response headers"); TEST_ERROR( httpRequestError(request, response), ProtocolError, @@ -617,9 +643,10 @@ testRun(void) TEST_ASSIGN(response, httpRequestResponse(request, false), "response"); TEST_RESULT_UINT(httpResponseCode(response), 403, "check response code"); TEST_RESULT_STR_Z(httpResponseReason(response), "", "check empty response message"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{connection: 'close', content-type: 'application/json'}", - "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{connection: 'close', content-type: 'application/json'}", "check response headers"); TEST_RESULT_STR_Z(strNewBuf(httpResponseContent(response)), "CONTENT", "check response content"); TEST_ERROR( @@ -702,9 +729,10 @@ testRun(void) .content = BUFSTRDEF("012345678901234567890123456789")), true), "request"); TEST_RESULT_BOOL(httpResponseReadIgnoreUnexpectedEof(response), true, "check unexpected eof allowed"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{connection: 'close', content-type: 'application/xml'}", - "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{connection: 'close', content-type: 'application/xml'}", "check response headers"); TEST_RESULT_STR_Z(strNewBuf(httpResponseContent(response)), "01234567890123456789012345678901", "check response"); TEST_RESULT_UINT(httpResponseRead(response, bufNew(1), true), 0, "call internal read to check eof"); @@ -761,8 +789,10 @@ testRun(void) "0\r\n\r\n"); TEST_ASSIGN(response, httpRequestResponse(httpRequestNewP(client, STRDEF("GET"), STRDEF("/")), false), "request"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{transfer-encoding: 'chunked'}", "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{transfer-encoding: 'chunked'}", "check response headers"); Buffer *buffer = bufNew(35); @@ -779,8 +809,10 @@ testRun(void) "0\r\n\r\n"); TEST_ASSIGN(response, httpRequestResponse(httpRequestNewP(client, STRDEF("GET"), STRDEF("/")), false), "request"); - TEST_RESULT_STR_Z( - httpHeaderToLog(httpResponseHeader(response)), "{transfer-encoding: 'chunked'}", "check response headers"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(httpResponseHeader(response), httpHeaderToLog, logBuf, sizeof(logBuf)), + "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{transfer-encoding: 'chunked'}", "check response headers"); buffer = bufNew(0); diff --git a/test/src/module/common/ioTlsTest.c b/test/src/module/common/ioTlsTest.c index 902333950..dd9c92660 100644 --- a/test/src/module/common/ioTlsTest.c +++ b/test/src/module/common/ioTlsTest.c @@ -333,8 +333,18 @@ testRun(void) // Wait for connection. Use port 1 to avoid port conflicts later. IoServer *server = sckServerNew(STRDEF("127.0.0.1"), hrnServerPort(1), 5000); - HRN_FORK_CHILD_NOTIFY_PUT(); + // ----------------------------------------------------------------------------------------------------------------- + TEST_TITLE("ioServerToLog()"); + + char buffer[STACK_TRACE_PARAM_MAX]; + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(server, ioServerToLog, buffer, sizeof(buffer)), "ioServerToLog"); + TEST_RESULT_Z( + buffer, zNewFmt("{type: socket, driver: {address: 127.0.0.1, port: %u, timeout: 5000}}", hrnServerPort(1)), + "check log"); + + HRN_FORK_CHILD_NOTIFY_PUT(); TEST_RESULT_PTR(ioServerAccept(server, NULL), NULL, "connection interrupted"); } HRN_FORK_CHILD_END(); @@ -815,6 +825,30 @@ testRun(void) TEST_RESULT_INT(ioSessionFd(session), -1, "no fd for tls session"); + // ----------------------------------------------------------------------------------------------------------------- + TEST_TITLE("ioClientToLog() and ioSessionToLog()"); + + char buffer[STACK_TRACE_PARAM_MAX]; + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(client, ioClientToLog, buffer, sizeof(buffer)), "ioClientToLog"); + TEST_RESULT_Z( + buffer, + zNewFmt( + "{type: tls, driver: {ioClient: {type: socket, driver: {host: %s, port: %u, timeoutConnect: 5000" + ", timeoutSession: 5000}}, timeoutConnect: 0, timeoutSession: 0, verifyPeer: %s}}", + strZ(hrnServerHost()), hrnServerPort(0), cvtBoolToConstZ(TEST_IN_CONTAINER)), + "check log"); + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(session, ioSessionToLog, buffer, sizeof(buffer)), "ioSessionToLog"); + TEST_RESULT_Z( + buffer, + zNewFmt( + "{type: tls, role: client, driver: {ioSession: {type: socket, role: client, driver: {host: %s, port: %u" + ", fd: %d, timeout: 5000}}, timeout: 0, shutdownOnClose: true}}", + strZ(hrnServerHost()), hrnServerPort(0), + ((SocketSession *)((TlsSession *)session->pub.driver)->ioSession->pub.driver)->fd), + "check log"); + // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("uncovered errors"); diff --git a/test/src/module/common/typeBufferTest.c b/test/src/module/common/typeBufferTest.c index 154024f58..0957b4ec4 100644 --- a/test/src/module/common/typeBufferTest.c +++ b/test/src/module/common/typeBufferTest.c @@ -152,11 +152,15 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("bufToLog()")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + Buffer *buffer = bufNew(100); - TEST_RESULT_STR_Z(bufToLog(buffer), "{used: 0, size: 100}", "buf to log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(buffer, bufToLog, logBuf, sizeof(logBuf)), "bufToLog"); + TEST_RESULT_Z(logBuf, "{used: 0, size: 100}", "check log"); bufLimitSet(buffer, 50); - TEST_RESULT_STR_Z(bufToLog(buffer), "{used: 0, size: 50, sizeAlloc: 100}", "buf to log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(buffer, bufToLog, logBuf, sizeof(logBuf)), "bufToLog"); + TEST_RESULT_Z(logBuf, "{used: 0, size: 50, sizeAlloc: 100}", "check log"); } FUNCTION_HARNESS_RETURN_VOID(); diff --git a/test/src/module/common/typeListTest.c b/test/src/module/common/typeListTest.c index 9d5ef9de8..2c7468628 100644 --- a/test/src/module/common/typeListTest.c +++ b/test/src/module/common/typeListTest.c @@ -32,6 +32,7 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("lstNew*(), lstMemContext(), lstToLog(), and lstFree()")) { + char logBuf[STACK_TRACE_PARAM_MAX]; List *list = lstNewP(sizeof(void *)); TEST_RESULT_UINT(list->itemSize, sizeof(void *), "item size"); @@ -42,10 +43,12 @@ testRun(void) void *ptr = NULL; TEST_RESULT_VOID(lstAdd(list, &ptr), "add item"); - TEST_RESULT_STR_Z(lstToLog(list), "{size: 1}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(list, lstToLog, logBuf, sizeof(logBuf)), "bufToLog"); + TEST_RESULT_Z(logBuf, "{size: 1}", "check log"); TEST_RESULT_VOID(lstClear(list), "clear list"); - TEST_RESULT_STR_Z(lstToLog(list), "{size: 0}", "check log after clear"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(list, lstToLog, logBuf, sizeof(logBuf)), "bufToLog"); + TEST_RESULT_Z(logBuf, "{size: 0}", "check log"); TEST_RESULT_VOID(lstFree(list), "free list"); TEST_RESULT_VOID(lstFree(lstNewP(1)), "free empty list"); diff --git a/test/src/module/common/typePackTest.c b/test/src/module/common/typePackTest.c index dc7ea7648..8583b4965 100644 --- a/test/src/module/common/typePackTest.c +++ b/test/src/module/common/typePackTest.c @@ -17,6 +17,8 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("PackWrite and PackRead")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + TEST_TITLE("type size"); TEST_RESULT_UINT(sizeof(PackType), 4, "PackType"); @@ -37,9 +39,11 @@ testRun(void) } MEM_CONTEXT_TEMP_END(); - TEST_RESULT_STR_Z(pckWriteToLog(packWrite), "{depth: 0, idLast: 0}", "log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(packWrite, pckWriteToLog, logBuf, sizeof(logBuf)), "pckWriteToLog"); + TEST_RESULT_Z(logBuf, "{depth: 0, idLast: 0}", "check log"); TEST_RESULT_VOID(pckWriteU64P(packWrite, 0750), "write mode"); - TEST_RESULT_STR_Z(pckWriteToLog(packWrite), "{depth: 0, idLast: 1}", "log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(packWrite, pckWriteToLog, logBuf, sizeof(logBuf)), "pckWriteToLog"); + TEST_RESULT_Z(logBuf, "{depth: 0, idLast: 1}", "check log"); TEST_RESULT_VOID(pckWriteU64P(packWrite, 1911246845), "write timestamp"); TEST_RESULT_VOID(pckWriteU64P(packWrite, 0xFFFFFFFFFFFFFFFF, .id = 7), "write max u64"); TEST_RESULT_VOID(pckWriteU64P(packWrite, 1, .id = 10), "write 1"); diff --git a/test/src/module/common/typeStringTest.c b/test/src/module/common/typeStringTest.c index 70de97ff5..b600da3fd 100644 --- a/test/src/module/common/typeStringTest.c +++ b/test/src/module/common/typeStringTest.c @@ -306,17 +306,12 @@ testRun(void) } // ***************************************************************************************************************************** - if (testBegin("strToLog() and strObjToLog()")) + if (testBegin("strToLog()")) { - TEST_RESULT_STR_Z(strToLog(STRDEF("test")), "{\"test\"}", "format string"); - TEST_RESULT_STR_Z(strToLog(NULL), "null", "format null string"); + char logBuf[STACK_TRACE_PARAM_MAX]; - char buffer[256]; - TEST_RESULT_UINT(strObjToLog(NULL, (StrObjToLogFormat)strToLog, buffer, sizeof(buffer)), 4, "format null string"); - TEST_RESULT_Z(buffer, "null", "check null string"); - - TEST_RESULT_UINT(strObjToLog(STRDEF("teststr"), (StrObjToLogFormat)strToLog, buffer, sizeof(buffer)), 11, "format string"); - TEST_RESULT_Z(buffer, "{\"teststr\"}", "check string"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(STRDEF("test"), strToLog, logBuf, sizeof(logBuf)), "strToLog"); + TEST_RESULT_Z(logBuf, "{\"test\"}", "check log"); } // ***************************************************************************************************************************** @@ -716,16 +711,21 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("strLstToLog()")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + StringList *list = strLstNew(); - TEST_RESULT_STR_Z(strLstToLog(list), "{[]}", "format empty list"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(list, strLstToLog, logBuf, sizeof(logBuf)), "strLstToLog"); + TEST_RESULT_Z(logBuf, "{[]}", "check log"); strLstInsert(list, 0, STRDEF("item3")); - TEST_RESULT_STR_Z(strLstToLog(list), "{[\"item3\"]}", "format 1 item list"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(list, strLstToLog, logBuf, sizeof(logBuf)), "strLstToLog"); + TEST_RESULT_Z(logBuf, "{[\"item3\"]}", "check log"); strLstInsert(list, 0, STRDEF("item1")); - strLstInsert(list, 1, STRDEF("item2")); - TEST_RESULT_STR_Z(strLstToLog(list), "{[\"item1\", \"item2\", \"item3\"]}", "format 3 item list"); + strLstInsert(list, 1, NULL); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(list, strLstToLog, logBuf, sizeof(logBuf)), "strLstToLog"); + TEST_RESULT_Z(logBuf, "{[\"item1\", null, \"item3\"]}", "check log"); } FUNCTION_HARNESS_RETURN_VOID(); diff --git a/test/src/module/common/typeVariantTest.c b/test/src/module/common/typeVariantTest.c index ddb6935e6..f886f4266 100644 --- a/test/src/module/common/typeVariantTest.c +++ b/test/src/module/common/typeVariantTest.c @@ -286,6 +286,7 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_STR_Z(varStrForce(VARSTRDEF("teststring")), "teststring", "force string to string"); TEST_RESULT_STR_Z(varStrForce(VARINT(999)), "999", "force int to string"); + TEST_RESULT_STR_Z(varStrForce(VARUINT(888)), "888", "force uint to string"); TEST_RESULT_STR_Z(varStrForce(VARINT64(9223372036854775807L)), "9223372036854775807", "force int64 to string"); TEST_RESULT_STR_Z(varStrForce(varNewBool(true)), "true", "force bool to string"); TEST_RESULT_STR_Z(varStrForce(varNewBool(false)), "false", "force bool to string"); @@ -369,11 +370,19 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("varToLog")) { - TEST_RESULT_STR_Z(varToLog(varNewStrZ("testme")), "{\"testme\"}", "format String"); - TEST_RESULT_STR_Z(varToLog(varNewBool(false)), "{false}", "format bool"); - TEST_RESULT_STR_Z(varToLog(varNewKv(kvNew())), "{KeyValue}", "format KeyValue"); - TEST_RESULT_STR_Z(varToLog(varNewVarLst(varLstNew())), "{VariantList}", "format VariantList"); - TEST_RESULT_STR_Z(varToLog(NULL), "null", "format null"); + char logBuf[STACK_TRACE_PARAM_MAX]; + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(varNewStrZ("testme"), varToLog, logBuf, sizeof(logBuf)), "varToLog"); + TEST_RESULT_Z(logBuf, "{\"testme\"}", "check log"); + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(varNewBool(false), varToLog, logBuf, sizeof(logBuf)), "varToLog"); + TEST_RESULT_Z(logBuf, "{false}", "check log"); + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(varNewKv(kvNew()), varToLog, logBuf, sizeof(logBuf)), "varToLog"); + TEST_RESULT_Z(logBuf, "{KeyValue}", "check log"); + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(varNewVarLst(varLstNew()), varToLog, logBuf, sizeof(logBuf)), "varToLog"); + TEST_RESULT_Z(logBuf, "{VariantList}", "check log"); } // ***************************************************************************************************************************** diff --git a/test/src/module/info/infoBackupTest.c b/test/src/module/info/infoBackupTest.c index 49451b015..7169673af 100644 --- a/test/src/module/info/infoBackupTest.c +++ b/test/src/module/info/infoBackupTest.c @@ -252,8 +252,11 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("infoBackupDataToLog()"); - TEST_RESULT_STR_Z( - infoBackupDataToLog(&backupData), "{label: 20161219-212741F_20161219-212918I, pgId: 1}", "check log format"); + char logBuf[STACK_TRACE_PARAM_MAX]; + + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(&backupData, infoBackupDataToLog, logBuf, sizeof(logBuf)), "infoBackupDataToLog"); + TEST_RESULT_Z(logBuf, "{label: 20161219-212741F_20161219-212918I, pgId: 1}", "check log"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("infoBackupDataAdd - full backup"); diff --git a/test/src/module/info/infoPgTest.c b/test/src/module/info/infoPgTest.c index ff70d24a7..bf209485e 100644 --- a/test/src/module/info/infoPgTest.c +++ b/test/src/module/info/infoPgTest.c @@ -208,10 +208,11 @@ testRun(void) pgDataTest.version = (unsigned int)4294967295; pgDataTest.systemId = 18446744073709551615U; pgDataTest.catalogVersion = 200101011; + char logBuf[STACK_TRACE_PARAM_MAX]; - TEST_RESULT_STR_Z( - infoPgDataToLog(&pgDataTest), - "{id: 4294967295, version: 4294967295, systemId: 18446744073709551615, catalogVersion: 200101011}", - " check max format"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(&pgDataTest, infoPgDataToLog, logBuf, sizeof(logBuf)), "infoPgDataToLog"); + TEST_RESULT_Z( + logBuf, "{id: 4294967295, version: 4294967295, systemId: 18446744073709551615, catalogVersion: 200101011}", + "check log"); } } diff --git a/test/src/module/postgres/interfaceTest.c b/test/src/module/postgres/interfaceTest.c index db9d42d83..45e6ec4d7 100644 --- a/test/src/module/postgres/interfaceTest.c +++ b/test/src/module/postgres/interfaceTest.c @@ -236,6 +236,8 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("pgControlToLog()")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + PgControl pgControl = { .version = PG_VERSION_11, @@ -244,21 +246,24 @@ testRun(void) .pageChecksum = true }; - TEST_RESULT_STR_Z( - pgControlToLog(&pgControl), "{version: 110000, systemId: 1030522662895, walSegmentSize: 16777216, pageChecksum: true}", - "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(&pgControl, pgControlToLog, logBuf, sizeof(logBuf)), "pgControlToLog"); + TEST_RESULT_Z( + logBuf, "{version: 110000, systemId: 1030522662895, walSegmentSize: 16777216, pageChecksum: true}", "check log"); } // ***************************************************************************************************************************** if (testBegin("pgWalToLog()")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + PgWal pgWal = { .version = PG_VERSION_10, .systemId = 0xFEFEFEFEFE }; - TEST_RESULT_STR_Z(pgWalToLog(&pgWal), "{version: 100000, systemId: 1095199817470}", "check log"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(&pgWal, pgWalToLog, logBuf, sizeof(logBuf)), "pgWalToLog"); + TEST_RESULT_Z(logBuf, "{version: 100000, systemId: 1095199817470}", "check log"); } FUNCTION_HARNESS_RETURN_VOID(); diff --git a/test/src/module/protocol/protocolTest.c b/test/src/module/protocol/protocolTest.c index e895c2ffd..7f7d96dcc 100644 --- a/test/src/module/protocol/protocolTest.c +++ b/test/src/module/protocol/protocolTest.c @@ -888,6 +888,8 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("ProtocolParallel and ProtocolParallelJob")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("job state transitions"); @@ -974,7 +976,9 @@ testRun(void) TestParallelJobCallback data = {.jobList = lstNewP(sizeof(ProtocolParallelJob *))}; ProtocolParallel *parallel = NULL; TEST_ASSIGN(parallel, protocolParallelNew(2000, testParallelJobCallback, &data), "create parallel"); - TEST_RESULT_STR_Z(protocolParallelToLog(parallel), "{state: pending, clientTotal: 0, jobTotal: 0}", "check log"); + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(parallel, protocolParallelToLog, logBuf, sizeof(logBuf)), "protocolParallelToLog"); + TEST_RESULT_Z(logBuf, "{state: pending, clientTotal: 0, jobTotal: 0}", "check log"); // Add client ProtocolClient *client[HRN_FORK_CHILD_MAX]; diff --git a/test/src/module/storage/azureTest.c b/test/src/module/storage/azureTest.c index 636991b48..b26618c5f 100644 --- a/test/src/module/storage/azureTest.c +++ b/test/src/module/storage/azureTest.c @@ -382,6 +382,8 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("storageAzureAuth()")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + StorageAzure *storage = NULL; HttpHeader *header = NULL; const String *dateTime = STRDEF("Sun, 21 Jun 2020 12:46:19 GMT"); @@ -401,10 +403,11 @@ testRun(void) header = httpHeaderAdd(httpHeaderNew(NULL), HTTP_HEADER_CONTENT_LENGTH_STR, ZERO_STR); TEST_RESULT_VOID(storageAzureAuth(storage, HTTP_VERB_GET_STR, STRDEF("/path"), NULL, dateTime, header), "auth"); - TEST_RESULT_STR_Z( - httpHeaderToLog(header), - "{authorization: 'SharedKey account:edqgT7EhsiIN3q6Al2HCZlpXr2D5cJFavr2ZCkhG9R8=', content-length: '0'" - ", date: 'Sun, 21 Jun 2020 12:46:19 GMT', host: 'account.blob.core.windows.net', x-ms-version: '2019-02-02'}", + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(header, httpHeaderToLog, logBuf, sizeof(logBuf)), "httpHeaderToLog"); + TEST_RESULT_Z( + logBuf, + "{content-length: '0', host: 'account.blob.core.windows.net', date: 'Sun, 21 Jun 2020 12:46:19 GMT'" + ", x-ms-version: '2019-02-02', authorization: 'SharedKey account:edqgT7EhsiIN3q6Al2HCZlpXr2D5cJFavr2ZCkhG9R8='}", "check headers"); // ------------------------------------------------------------------------------------------------------------------------- @@ -416,11 +419,12 @@ testRun(void) HttpQuery *query = httpQueryAdd(httpQueryNewP(), STRDEF("a"), STRDEF("b")); TEST_RESULT_VOID(storageAzureAuth(storage, HTTP_VERB_GET_STR, STRDEF("/path/file"), query, dateTime, header), "auth"); - TEST_RESULT_STR_Z( - httpHeaderToLog(header), - "{authorization: 'SharedKey account:5qAnroLtbY8IWqObx8+UVwIUysXujsfWZZav7PrBON0=', content-length: '44'" - ", content-md5: 'b64f49553d5c441652e95697a2c5949e', date: 'Sun, 21 Jun 2020 12:46:19 GMT'" - ", host: 'account.blob.core.windows.net', x-ms-version: '2019-02-02'}", + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(header, httpHeaderToLog, logBuf, sizeof(logBuf)), "httpHeaderToLog"); + TEST_RESULT_Z( + logBuf, + "{content-length: '44', content-md5: 'b64f49553d5c441652e95697a2c5949e', host: 'account.blob.core.windows.net'" + ", date: 'Sun, 21 Jun 2020 12:46:19 GMT', x-ms-version: '2019-02-02'" + ", authorization: 'SharedKey account:5qAnroLtbY8IWqObx8+UVwIUysXujsfWZZav7PrBON0='}", "check headers"); // ------------------------------------------------------------------------------------------------------------------------- @@ -438,8 +442,8 @@ testRun(void) header = httpHeaderAdd(httpHeaderNew(NULL), HTTP_HEADER_CONTENT_LENGTH_STR, STRDEF("66")); TEST_RESULT_VOID(storageAzureAuth(storage, HTTP_VERB_GET_STR, STRDEF("/path/file"), query, dateTime, header), "auth"); - TEST_RESULT_STR_Z( - httpHeaderToLog(header), "{content-length: '66', host: 'account.blob.core.usgovcloudapi.net'}", "check headers"); + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(header, httpHeaderToLog, logBuf, sizeof(logBuf)), "httpHeaderToLog"); + TEST_RESULT_Z(logBuf, "{content-length: '66', host: 'account.blob.core.usgovcloudapi.net'}", "check headers"); TEST_RESULT_STR_Z(httpQueryRenderP(query), "a=b&sig=key", "check query"); } diff --git a/test/src/module/storage/s3Test.c b/test/src/module/storage/s3Test.c index 0b51a0b0f..b55eb38e2 100644 --- a/test/src/module/storage/s3Test.c +++ b/test/src/module/storage/s3Test.c @@ -275,6 +275,8 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("storageS3DateTime() and storageS3Auth()")) { + char logBuf[STACK_TRACE_PARAM_MAX]; + TEST_RESULT_STR_Z(storageS3DateTime(1491267845), "20170404T010405Z", "static date"); // ------------------------------------------------------------------------------------------------------------------------- @@ -291,9 +293,10 @@ testRun(void) TEST_RESULT_STR(driver->accessKey, accessKey, "check access key"); TEST_RESULT_STR(driver->secretAccessKey, secretAccessKey, "check secret access key"); TEST_RESULT_STR(driver->securityToken, NULL, "check security token"); - TEST_RESULT_STR( - httpClientToLog(driver->httpClient), - strNewFmt( + + TEST_RESULT_VOID(FUNCTION_LOG_OBJECT_FORMAT(driver->httpClient, httpClientToLog, logBuf, sizeof(logBuf)), "httpClientToLog"); + TEST_RESULT_Z(logBuf, + zNewFmt( "{ioClient: {type: tls, driver: {ioClient: {type: socket, driver: {host: bucket.s3.amazonaws.com, port: 443" ", timeoutConnect: 60000, timeoutSession: 60000}}, timeoutConnect: 60000, timeoutSession: 60000" ", verifyPeer: %s}}, reusable: 0, timeout: 60000}", @@ -361,9 +364,10 @@ testRun(void) driver = (StorageS3 *)storageDriver(storageRepoGet(0, false)); TEST_RESULT_STR(driver->securityToken, securityToken, "check security token"); - TEST_RESULT_STR( - httpClientToLog(driver->httpClient), - strNewFmt( + TEST_RESULT_VOID( + FUNCTION_LOG_OBJECT_FORMAT(driver->httpClient, httpClientToLog, logBuf, sizeof(logBuf)), "httpClientToLog"); + TEST_RESULT_Z(logBuf, + zNewFmt( "{ioClient: {type: tls, driver: {ioClient: {type: socket, driver: {host: bucket.custom.endpoint, port: 333" ", timeoutConnect: 60000, timeoutSession: 60000}}, timeoutConnect: 60000, timeoutSession: 60000" ", verifyPeer: %s}}, reusable: 0, timeout: 60000}", diff --git a/test/src/module/test/testTest.c b/test/src/module/test/testTest.c index 6c8b9d8d6..0a2f7f037 100644 --- a/test/src/module/test/testTest.c +++ b/test/src/module/test/testTest.c @@ -166,6 +166,7 @@ testRun(void) " - common/error.inc: included\n" " depend:\n" " - common/stackTrace\n" + " - common/type/stringStatic\n" "\n" " - name: stack-trace\n" " total: 4\n" @@ -178,6 +179,7 @@ testRun(void) " - stackTraceBackCallback\n" " coverage:\n" " - common/stackTrace\n" + " - common/type/stringStatic\n" " depend:\n" " - common/debug\n" "\n" @@ -240,6 +242,8 @@ testRun(void) "src/common/stackTrace.h", "src/common/type/convert.h", "src/common/type/param.h", + "src/common/type/stringStatic.h", + "src/common/type/stringStatic.c", "src/common/type/stringZ.h", "test/src/common/harnessDebug.h", "test/src/common/harnessLog.h", @@ -341,6 +345,11 @@ testRun(void) strReplace(testCDup, STRDEF("{[C_TEST_PROJECT_EXE]}"), STRDEF(TEST_PATH "/test/build/none/src/pgbackrest")); strReplace(testCDup, STRDEF("{[C_TEST_TZ]}"), STRDEF("// No timezone specified")); + strReplace( + testCDup, STRDEF("{[C_INCLUDE]}"), + STRDEF( + "#include \"test/src/common/harnessStackTrace.c\"\n" + "#include \"../../../repo/src/common/type/stringStatic.c\"")); strReplace(testCDup, STRDEF("{[C_INCLUDE]}"), STRDEF("#include \"test/src/common/harnessStackTrace.c\"")); strReplace( testCDup, STRDEF("{[C_TEST_INCLUDE]}"), @@ -400,6 +409,7 @@ testRun(void) MESON_COMMENT_BLOCK "\n" "src_unit = files(\n" " '../../../repo/src/common/stackTrace.c',\n" + " '../../../repo/src/common/type/stringStatic.c',\n" " '../../../repo/test/src/common/harnessTest.c',\n" " 'test.c',\n" ")\n" @@ -596,6 +606,7 @@ testRun(void) "# Unit test\n" MESON_COMMENT_BLOCK "\n" "src_unit = files(\n" + " '../../../repo/src/common/type/stringStatic.c',\n" " '../../../repo/src/common/debug.c',\n" " 'test/src/common/harnessStackTrace.c',\n" " '../../../repo/test/src/common/harnessNoShim.c',\n" @@ -760,6 +771,7 @@ testRun(void) "# Unit test\n" MESON_COMMENT_BLOCK "\n" "src_unit = files(\n" + " '../../../repo/src/common/type/stringStatic.c',\n" " '../../../repo/src/common/debug.c',\n" " 'test/src/common/harnessError.c',\n" " 'test/src/common/harnessStackTrace.c',\n"