Skip to content

Commit

Permalink
fixed the expansion of the logger macros when VASQ_NO_LOGGING is defined
Browse files Browse the repository at this point in the history
changed the version to 5.2.3
  • Loading branch information
nickeldan committed Feb 1, 2022
1 parent 6232e2a commit 2b157e7
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 110 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Vanilla Squad
=============

:Author: Daniel Walker
:Version: 5.2.2
:Date: 2022-01-26
:Version: 5.2.3
:Date: 2022-01-31

Overview
========
Expand Down
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
5.2.3:
- Fixed the expansion of the logger macros when VASQ_NO_LOGGING is defined.

5.2.2:
- Fixed a typo in the VASQ_REALLOC macro definition for when VASQ_NO_LOGGING is defined.

Expand Down
2 changes: 1 addition & 1 deletion include/vasq/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @brief Current version of the library.
*/
#define VASQ_VERSION "5.2.2"
#define VASQ_VERSION "5.2.3"

#ifndef NO_OP
#define NO_OP ((void)0)
Expand Down
228 changes: 121 additions & 107 deletions include/vasq/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ typedef enum vasqLogLevel {
VASQ_LL_DEBUG,
} vasqLogLevel_t;

#ifndef VASQ_NO_LOGGING

#define VASQ_CONTEXT_DECL const char *file_name, const char *function_name, unsigned int line_no
#define VASQ_CONTEXT_PARAMS __FILE__, __func__, __LINE__

#ifndef VASQ_NO_LOGGING

typedef struct vasqLogger vasqLogger;

/*
Expand Down Expand Up @@ -190,6 +190,74 @@ vasqSetLoggerUserData(vasqLogger *logger, void *user);
void
vasqLogStatement(const vasqLogger *logger, vasqLogLevel_t level, VASQ_CONTEXT_DECL, const char *format, ...);

/**
* @brief Emit a message at the ALWAYS level.
*/
#define VASQ_ALWAYS(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_ALWAYS, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the CRITICAL level.
*/
#define VASQ_CRITICAL(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_CRITICAL, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the ERROR level.
*/
#define VASQ_ERROR(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_ERROR, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the WARNING level.
*/
#define VASQ_WARNING(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_WARNING, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the INFO level.
*/
#define VASQ_INFO(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_INFO, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the DEBUG level.
*/
#define VASQ_DEBUG(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_DEBUG, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Logging equivalent of the perror function at the CRITICAL level.
*
* @param logger The logger handle.
* @param msg The argument that would normally be passed to perror.
* @param errnum The errno value.
*
* @warning msg must be a string literal and not a variable.
*/
#define VASQ_PCRITICAL(logger, msg, errnum) VASQ_CRITICAL(logger, msg ": %s", strerror(errnum))
/**
* @brief Logging equivalent of the perror function at the ERROR level.
*
* @param logger The logger handle.
* @param msg The argument that would normally be passed to perror.
* @param errnum The errno value.
*
* @warning msg must be a string literal and not a variable.
*/
#define VASQ_PERROR(logger, msg, errnum) VASQ_ERROR(logger, msg ": %s", strerror(errnum))

/**
* @brief Logging equivalent of the perror function at the WARNING level.
*
* @param logger The logger handle.
* @param msg The argument that would normally be passed to perror.
* @param errnum The errno value.
*
* @warning msg must be a string literal and not a variable.
*/
#define VASQ_PWARNING(logger, msg, errnum) VASQ_WARNING(logger, msg ": %s", strerror(errnum))

/**
* @brief Same as vasqLogStatement but takes a va_list instead of variable arguments.
*/
Expand Down Expand Up @@ -226,6 +294,11 @@ vasqVRawLog(const vasqLogger *logger, const char *format, va_list args);
void
vasqHexDump(const vasqLogger *logger, VASQ_CONTEXT_DECL, const char *name, const void *data, size_t size);

/**
* @brief Wrap vasqHexDump by automatically supplying the file name, function name, and line number.
*/
#define VASQ_HEXDUMP(logger, name, data, size) vasqHexDump(logger, VASQ_CONTEXT_PARAMS, name, data, size)

/**
* @brief Wrap malloc.
*
Expand All @@ -242,6 +315,11 @@ vasqHexDump(const vasqLogger *logger, VASQ_CONTEXT_DECL, const char *name, const
void *
vasqMalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t size);

/**
* @brief Wrap vasqMalloc by automatically supplying the file name, function name, and line number.
*/
#define VASQ_MALLOC(logger, size) vasqMalloc(logger, VASQ_CONTEXT_PARAMS, size)

/**
* @brief Wrap calloc.
*
Expand All @@ -259,6 +337,11 @@ vasqMalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t size);
void *
vasqCalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t nmemb, size_t size);

/**
* @brief Wrap vasqCalloc by automatically supplying the file name, function name, and line number.
*/
#define VASQ_CALLOC(logger, nmemb, size) vasqCalloc(logger, VASQ_CONTEXT_PARAMS, nmemb, size)

/**
* @brief Wrap realloc.
*
Expand All @@ -276,6 +359,11 @@ vasqCalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t nmemb, size_t siz
void *
vasqRealloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, void *ptr, size_t size);

/**
* @brief Wrap vasqRealloc by automatically supplying the file name, function name, and line number.
*/
#define VASQ_REALLOC(logger, ptr, size) vasqRealloc(logger, VASQ_CONTEXT_PARAMS, ptr, size)

/**
* @brief Wrap fork.
*
Expand All @@ -292,6 +380,11 @@ vasqRealloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, void *ptr, size_t size)
pid_t
vasqFork(const vasqLogger *logger, VASQ_CONTEXT_DECL);

/**
* @brief Wrap vasqFork by automatically supplying the file name, function name, and line number.
*/
#define VASQ_FORK(logger) vasqFork(logger, VASQ_DECL_PARAMS)

/**
* @brief Wrap exit or _exit.
*
Expand All @@ -308,136 +401,57 @@ vasqFork(const vasqLogger *logger, VASQ_CONTEXT_DECL);
void
vasqExit(vasqLogger *logger, VASQ_CONTEXT_DECL, int value, bool quick) __attribute__((noreturn));

/**
* @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting
* quick to false.
*/
#define VASQ_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, false)

/**
* @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting
* quick to true.
*/
#define VASQ_QUICK_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, true)

#else // VASQ_NO_LOGGING

#define vasqLoggerCreate(...) VASQ_RET_OK
#define vasqLoggerFree(logger) NO_OP
#define vasqLoggerFd(logger) -1
#define vasqSetLoggerFormat(logger, format) true
#define vasqLoggerLevel(logger) VASQ_LL_NONE
#define vasqsetLoggerLevel(logger, level) NO_OP
#define vasqSetLoggerProcessor(logger, processor) NO_OP
#define vasqLoggerUserData(logger) NULL
#define vasqSetLogerUserData(logger, user) NO_OP

#define vasqLogStatement(...) NO_OP
#define vasqVLogStatement(...) NO_OP
#define VASQ_ALWAYS(...) NO_OP
#define VASQ_CRITICAL(...) NO_OP
#define VASQ_ERROR(...) NO_OP
#define VASQ_WARNING(...) NO_OP
#define VASQ_INFO(...) NO_OP
#define VASQ_DEBUG(...) NO_OP
#define vasqRawLog(...) NO_OP
#define vasqVRawLog(...) NO_OP
#define vasqHexDump(...) NO_OP
#define VASQ_HEXDUMP(...) NO_OP

#define vasqMalloc(logger, file, func, line, size) malloc(size)
#define VASQ_MALLOC(logger, size) malloc(size)
#define vasqCalloc(logger, file, func, line, nmemb, size) calloc(nmemb, size)
#define VASQ_CALLOC(logger, nmemb, size) calloc(nmemb, size)
#define vasqRealloc(logger, file, func, line, ptr, size) realloc(ptr, size)
#define VASQ_REALLOC(logger, ptr, size) realloc(ptr, size)
#define vasqFork(...) fork()
#define VASQ_FORK() fork()
#define vasqExit(logger, file, func, line, value, quick) (((quick) ? _exit : exit)(value))
#define VASQ_EXIT(logger, value) exit(value)
#define VASQ_QUICK_EXIT(logger, value) _exit(value)

#endif // VASQ_NO_LOGGING

/**
* @brief Emit a message at the ALWAYS level.
*/
#define VASQ_ALWAYS(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_ALWAYS, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the CRITICAL level.
*/
#define VASQ_CRITICAL(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_CRITICAL, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the ERROR level.
*/
#define VASQ_ERROR(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_ERROR, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the WARNING level.
*/
#define VASQ_WARNING(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_WARNING, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the INFO level.
*/
#define VASQ_INFO(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_INFO, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Emit a message at the DEBUG level.
*/
#define VASQ_DEBUG(logger, format, ...) \
vasqLogStatement(logger, VASQ_LL_DEBUG, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__)

/**
* @brief Logging equivalent of the perror function at the CRITICAL level.
*
* @param logger The logger handle.
* @param msg The argument that would normally be passed to perror.
* @param errnum The errno value.
*
* @warning msg must be a string literal and not a variable.
*/
#define VASQ_PCRITICAL(logger, msg, errnum) VASQ_CRITICAL(logger, msg ": %s", strerror(errnum))
/**
* @brief Logging equivalent of the perror function at the ERROR level.
*
* @param logger The logger handle.
* @param msg The argument that would normally be passed to perror.
* @param errnum The errno value.
*
* @warning msg must be a string literal and not a variable.
*/
#define VASQ_PERROR(logger, msg, errnum) VASQ_ERROR(logger, msg ": %s", strerror(errnum))

/**
* @brief Logging equivalent of the perror function at the WARNING level.
*
* @param logger The logger handle.
* @param msg The argument that would normally be passed to perror.
* @param errnum The errno value.
*
* @warning msg must be a string literal and not a variable.
*/
#define VASQ_PWARNING(logger, msg, errnum) VASQ_WARNING(logger, msg ": %s", strerror(errnum))

/**
* @brief Wrap vasqHexDump by automatically supplying the file name, function name, and line number.
*/
#define VASQ_HEXDUMP(logger, name, data, size) vasqHexDump(logger, VASQ_CONTEXT_PARAMS, name, data, size)

/**
* @brief Wrap vasqMalloc by automatically supplying the file name, function name, and line number.
*/
#define VASQ_MALLOC(logger, size) vasqMalloc(logger, VASQ_CONTEXT_PARAMS, size)

/**
* @brief Wrap vasqCalloc by automatically supplying the file name, function name, and line number.
*/
#define VASQ_CALLOC(logger, nmemb, size) vasqCalloc(logger, VASQ_CONTEXT_PARAMS, nmemb, size)

/**
* @brief Wrap vasqRealloc by automatically supplying the file name, function name, and line number.
*/
#define VASQ_REALLOC(logger, ptr, size) vasqRealloc(logger, VASQ_CONTEXT_PARAMS, ptr, size)

/**
* @brief Wrap vasqFork by automatically supplying the file name, function name, and line number.
*/
#define VASQ_FORK(logger) vasqFork(logger, VASQ_DECL_PARAMS)

/**
* @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting
* quick to false.
*/
#define VASQ_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, false)

/**
* @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting
* quick to true.
*/
#define VASQ_QUICK_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, true)

#ifdef DEBUG

#ifdef VASQ_TEST_ASSERT
Expand Down

0 comments on commit 2b157e7

Please sign in to comment.