From 32982fd0a42800e3ceac792b7aeac7eba96fc3de Mon Sep 17 00:00:00 2001 From: Antoine Date: Sat, 31 Aug 2024 21:34:58 +0800 Subject: [PATCH] Split reference in several pages --- book/Doxyfile.cfg | 1 + book/pages/index.rst | 2 +- book/pages/reference/index.md | 6 +++ book/pages/reference/log.md | 4 ++ .../{reference.md => reference/token.md} | 8 +-- include/blackmagic/log.h | 50 ++++++++++++++++--- include/blackmagic/token.h | 6 ++- 7 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 book/pages/reference/index.md create mode 100644 book/pages/reference/log.md rename book/pages/{reference.md => reference/token.md} (64%) diff --git a/book/Doxyfile.cfg b/book/Doxyfile.cfg index 166e7ad..37b76f5 100644 --- a/book/Doxyfile.cfg +++ b/book/Doxyfile.cfg @@ -17,3 +17,4 @@ QT_AUTOBRIEF = YES HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_CLASSES = YES MAX_INITIALIZER_LINES = 0 +PREDEFINED = LOG_LEVEL=LOG_LEVEL_TRACE diff --git a/book/pages/index.rst b/book/pages/index.rst index ae4fe3b..4d53de9 100644 --- a/book/pages/index.rst +++ b/book/pages/index.rst @@ -17,4 +17,4 @@ Black Magic 04_default 05_range quotes - reference + reference/index diff --git a/book/pages/reference/index.md b/book/pages/reference/index.md new file mode 100644 index 0000000..488fac9 --- /dev/null +++ b/book/pages/reference/index.md @@ -0,0 +1,6 @@ +# Reference + +:::{toctree} +token +log +::: diff --git a/book/pages/reference/log.md b/book/pages/reference/log.md new file mode 100644 index 0000000..8707da5 --- /dev/null +++ b/book/pages/reference/log.md @@ -0,0 +1,4 @@ +# Logging Library + +:::{doxygenfile} log.h +::: diff --git a/book/pages/reference.md b/book/pages/reference/token.md similarity index 64% rename from book/pages/reference.md rename to book/pages/reference/token.md index 018b50a..be0c6e2 100644 --- a/book/pages/reference.md +++ b/book/pages/reference/token.md @@ -1,14 +1,14 @@ -# Reference +# Token manipulation -## Token manipulation +## Create a string literal -### Create a string literal :::{doxygendefine} LITERAL_STRINGIZE ::: :::{doxygendefine} STRINGIZE ::: -### Combine tokens +## Combine tokens + :::{doxygendefine} LITERAL_CONCAT ::: :::{doxygendefine} CONCAT diff --git a/include/blackmagic/log.h b/include/blackmagic/log.h index 201311a..7b99eee 100644 --- a/include/blackmagic/log.h +++ b/include/blackmagic/log.h @@ -89,19 +89,53 @@ LEVEL, __func__ __VA_OPT__(,) __VA_ARGS__) #elif LOG_FORMAT == LOG_FORMAT_MARKDOWN # define log_log(LEVEL, IGNORED, MESSAGE, ...) \ - fprintf(LOG_FILE, "|" LEVEL "|`" __FILE__ "`|`%s`|" STRINGIZE(__LINE__) "|" MESSAGE "\n", \ + fprintf(LOG_FILE, "|" LEVEL "|`" __FILE__ "`|`%s`|" STRINGIZE(__LINE__) "|" MESSAGE "|\n", \ __func__ __VA_OPT__(,) __VA_ARGS__) #endif -#define log_fatal(MESSAGE, ...) \ +#if LOG_LEVEL >= LOG_LEVEL_FATAL +/** Report a condition that forces to program to terminate */ +# define log_fatal(MESSAGE, ...) \ log_log("FATAL", COLOR(BOLD, WHITE, BG_RED), MESSAGE __VA_OPT__(,) __VA_ARGS__) -#define log_error(MESSAGE, ...) \ +#else +# define log_fatal(M, ...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_ERROR +/** Report a condition that forces the current operation to be aborted */ +# define log_error(MESSAGE, ...) \ log_log("ERROR", COLOR(BOLD, RED), MESSAGE __VA_OPT__(,) __VA_ARGS__) -#define log_warning(MESSAGE, ...) \ +#else +# define log_error(M, ...) +#endif + + +#if LOG_LEVEL >= LOG_LEVEL_WARNING +/** Report an abnormal condition */ +# define log_warning(MESSAGE, ...) \ log_log("WARN", COLOR(BOLD, YELLOW), MESSAGE __VA_OPT__(,) __VA_ARGS__) -#define log_info(MESSAGE, ...) \ +#else +# define log_warning(M, ...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_INFO +/** Report significant information */ +# define log_info(MESSAGE, ...) \ log_log("INFO", COLOR(BOLD, GREEN), MESSAGE __VA_OPT__(,) __VA_ARGS__) -#define log_debug(MESSAGE, ...) \ +#else +# define log_info(M, ...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_DEBUG +# define log_debug(MESSAGE, ...) \ log_log("DEBUG", COLOR(BOLD, BLUE), MESSAGE __VA_OPT__(,) __VA_ARGS__) -#define log_trace(MESSAGE, ...) \ - log_log("DEBUG", COLOR(NORMAL), MESSAGE __VA_OPT__(,) __VA_ARGS__) +#else +# define log_debug(M, ...) +#endif + +#if LOG_LEVEL >= LOG_LEVEL_TRACE +# define log_trace(MESSAGE, ...) \ + log_log("TRACE", COLOR(NORMAL), MESSAGE __VA_OPT__(,) __VA_ARGS__) +#else +# define log_trace(M, ...) +#endif diff --git a/include/blackmagic/token.h b/include/blackmagic/token.h index 3f6f82f..2078cb1 100644 --- a/include/blackmagic/token.h +++ b/include/blackmagic/token.h @@ -8,7 +8,8 @@ /** * Evaluates as a string literal containing @p TEXT, without performing macro expansion. - * # Example + * + * __Example__ * ``` * LITERAL_STRINGIZE(__LINE__) * ``` @@ -22,7 +23,8 @@ /** * Evaluates as a string literal containing @p EXPRESSION with its macros expanded. - * # Example + * + * __Example__ * ``` * STRINGIZE(__LINE__) * ```