From 02a59ba4d858edfea55f561926075a1fba78ef29 Mon Sep 17 00:00:00 2001 From: aadewale Date: Fri, 13 May 2022 12:19:05 +0100 Subject: [PATCH] fix type as sugested by Michael Litwak --- README.md | 79 ++++++++++++------------ docs/docs/callbacks.md | 6 +- docs/docs/logging_levels.md | 12 ++-- docs/docs/logging_with_logaxlogger.md | 6 +- docs/docs/logging_without_logaxlogger.md | 14 ++--- docs/docs/modularity.md | 6 +- docs/docs/options.md | 4 +- docs/docs/output_formats.md | 24 +++---- docs/how_it_works/index.md | 4 +- docs/index.md | 10 +-- include/exotic/logax.h | 38 +++++++----- test/CMakeLists.txt | 4 +- test/test_basics.c | 2 +- test/test_no_callback.c | 2 +- 14 files changed, 110 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index c011fee..6bb1e3a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Blazing fast, simple and modular header-only logging library with zero allocation for C and C++, implemented in C90. Allow logging into various output formats such as Key-Value and JSON. -Time and space are very important concepts in programming, a logging library should slow down the program or add to the memory ussage hence why logax's API is designed with speed and modularity in mind, each components can be removed to adjust to an environment or increase compile/runtime speed by defining the [exclusion macro](#modularity) for that component. +Logax is designed with speed and modularity in mind,. It requires no heap-allocated memory. Each components can be excluded by defining an [exclusion macro](#modularity), to adjust to an environment or increase compile/runtime speed. ```c #include @@ -24,8 +24,7 @@ Output ![](https://raw.githubusercontent.com/exoticlibraries/exoticlibraries.github.io/main/assets/images/liblogax/crash_test_output.png) - -The log oputput can be formatted to the following output [text](#text), [key value](#key-value) and [json](#json), and in case where the output is not required or the platform does not have any output stream (e.g. andruino, stm32) a callback can be registered that will receive the log event to be processed whichever way. +The log output can be formatted as text, key/value or json. Where the output is not required or the platform does not have any output stream (e.g. Arduino, stm32) a callback can be registered that will process the log event. ___ @@ -41,7 +40,7 @@ ___ - [Usage](#usage) - [Logging without LogaxLogger](#logging-without-logaxLogger) - [Logging with LogaxLogger](#logging-with-logaxLogger) - - [Initialize LogaxLogger](#initialize-logaxLogger) + - [Iinitialized LogaxLogger](#iinitialized-logaxLogger) - [LogaxLogger Loggers](#logaxLogger-loggers) - [Callbacks](#callbacks) - [Output Formats](#output-formats) @@ -66,13 +65,13 @@ ___ - Speed. logax was developed with speed and zero performance intrusion in mind. - Modular, excluded un-used features from your test, [modularity](https://exoticlibraries.github.io/liblogax/docs/modularity.html). - Zero allocation, No memory allocation. -- Levelled logging to customize and differenciate the outputs. +- Levelled logging to customize and differentiate the outputs. - Support for callbacks and hooks. -- Very portable, compatiple with ANSI C and C++98 without any trade off in functionalities. +- Very portable, compatible with ANSI C and C++98 without any trade off in functionalities. - Output log in text, key-value and JSON encoding formats. - Pretty logging for all supported output formats. -- Simple method to achive options in the logging system using bitwise operations. -- Detail docuentation with examples and API references. +- Simple method to achieve options in the logging system using bitwise operations. +- Detail documentation with examples and API references. ## Standards Compliance and Portability @@ -88,7 +87,7 @@ If you install the library file `logax.h` using any of the commands below, it ca ### Windows -Install the library using powershell. It auto detect your insalled C and C++ compilers include directory and install liblogax into the include folder. Execute the command in powershell as admin. +Install the library using powershell. It auto detect your installed C and C++ compilers include directory and install liblogax into the include folder. Execute the command in powershell as admin. ```powershell & $([scriptblock]::Create((New-Object Net.WebClient).DownloadString("https://exoticlibraries.github.io/magic/install.ps1"))) liblogax @@ -126,45 +125,45 @@ it allows the log to be reported to custom function with optional printing to ou ### Logging without LogaxLogger -The library can be used to output log without need to setup the `LogaxLogger` struct, this will require the platform to have output stream or can write to file. If the macro LOGAX_NO_LOGGER is defined before including the logax.h geader file, the LogaxLogger struct and all related functions will not be compiled. The following functions provides the API to write to output stream in the supported formats +The library can be used to output log without need to setup the `LogaxLogger` struct, this will require the platform to have output stream or can write to file. If the macro LOGAX_NO_LOGGER is defined before including the logax.h header file, the LogaxLogger struct and all related functions will not be compiled. The following functions provides the API to write to output stream in the supported formats - logax_write_text_format_to_stream - logax_write_key_value_format_to_stream - logax_write_json_format_to_stream -`logax_write_text_format_to_stream` write the output in plain text format, the first paramater is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. +`logax_write_text_format_to_stream` write the output in plain text format, the first parameter is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. ```c #include int main(int argc, char **argv) { - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } // output // 2021-11-21 06:34:07 TRACE crash_test.c:13 Logging the test for TRACE ``` -`logax_write_key_value_format_to_stream` write the output in a key-value format coloring is ignored in this format, the first paramater is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. +`logax_write_key_value_format_to_stream` write the output in a key-value format coloring is ignored in this format, the first parameter is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. ```c #include int main(int argc, char **argv) { - logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } // output // date="2021-11-21" time="06:41:34" level="TRACE" file="crash_test.c" line_number=8 function="main" message="This is a trace output" ``` -`logax_write_json_format_to_stream` write the output in a json format, the first paramater is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. +`logax_write_json_format_to_stream` write the output in a json format, the first parameter is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. ```c #include int main(int argc, char **argv) { - logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } // output @@ -173,11 +172,11 @@ int main(int argc, char **argv) { ### Logging with LogaxLogger -In a situation where callback is needed, no FILE* ability on the platform or the flags/options want to be shared across the log, the `LogaxLogger` struct can be used. No memory allocation is required when initaili +In a situation where callback is needed, no FILE* ability on the platform or the flags/options want to be shared across the log, the `LogaxLogger` struct can be used. No memory allocation is required when initialized. -#### Initialize LogaxLogger +#### Iinitialized LogaxLogger -To initialize the LogaxLogger the function `logax_init_logger` can be used, it not neccessary to call the logax_init_logger function, all it does is set the LogaxLogger flags to default value, output_stream to stdout and fill the empty callbacks with NULL, these can be self-managed. +To iinitialized the LogaxLogger the function `logax_init_logger` can be used, it not necessary to call the logax_init_logger function, all it does is set the LogaxLogger flags to default value, output_stream to stdout and fill the empty callbacks with NULL, these can be self-managed. ```c #include @@ -199,7 +198,7 @@ For each of the logging level in logax a function is provider that accepts `Loga - logax_logger_error - logax_logger_fatal -Each of the function above invoke the coresponding `logax_write_*_format_to_stream` respectively, the default formatter when LogaxLogger is nitialize with the function logax_init_logger is `LOGAX_FORMATTER_TEXT`, the output format can be changed using the function `logax_set_formatter`. +Each of the function above invoke the corresponding `logax_write_*_format_to_stream` respectively, the default formatter when LogaxLogger is initialized with the function logax_init_logger is `LOGAX_FORMATTER_TEXT`, the output format can be changed using the function `logax_set_formatter`. ```c #include @@ -220,7 +219,7 @@ int main(int argc, char **argv) { ### Callbacks -LogaxLogger supports callback (or hook), the callbacks are invoked when a new log is sent. The callback can be used to create a custom output format or used to changed out the log is processed (e.g. blink bulb on andruino e.t.c). The output stream can be completely disabled by defining the macro `LOGAX_NO_OUTPUT_STREAM` or setiing the option to QUITE using the function `logax_set_quite`, in this case if callbacks are registered they will be invoked with the log event. +LogaxLogger supports callback (or hook), the callbacks are invoked when a new log is sent. The callback can be used to create a custom output format or used to changed out the log is processed (e.g. blink bulb on andruino e.t.c). The output stream can be completely disabled by defining the macro `LOGAX_NO_OUTPUT_STREAM` or setting the option to QUIET using the function `logax_set_quiet`, in this case if callbacks are registered they will be invoked with the log event. The callback function signature is @@ -228,7 +227,7 @@ The callback function signature is typedef void (*logax_callback)(const char *date, const char *time, const int level, const char *file, const size_t line_number, const char *function_name, const char *fmt, ...); ``` -The example belows shows how to register a callback which is invoked when there is a new log +The example below shows how to register a callback which is invoked when there is a new log ```c #include @@ -251,7 +250,7 @@ int main(int argc, char **argv) { LogaxLogger logax_logger; logax_init_logger(&logax_logger); - logax_set_quite(&logax_logger, 1); + logax_set_quiet(&logax_logger, 1); logax_logger_add_callback(&logax_logger, on_new_log_callback); logax_logger_trace(&logax_logger, "%s", "Logging the test for TRACE"); logax_logger_debug(&logax_logger, "%s", "Logging the test for DEBUG"); @@ -302,11 +301,11 @@ Output as text using `logax_write_text_format_to_stream` #include int main(int argc, char **argv) { - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -2021-11-21 08:41:19 TRACE crash_test.c:6 --- [main ] Enemy approching from X=108,Y=877 +2021-11-21 08:41:19 TRACE crash_test.c:6 --- [main ] Enemy approaching from X=108,Y=877 ``` Output as text using the `LOGAX_FORMATTER_TEXT` option with LogaxLogger. @@ -319,11 +318,11 @@ int main(int argc, char **argv) { logax_init_logger(&logax_logger); logax_set_formatter(&logax_logger, LOGAX_FORMATTER_TEXT); - logax_logger_trace(&logax_logger, "%s", "Enemy approching from X=108,Y=877"); + logax_logger_trace(&logax_logger, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -2021-11-21 08:38:38 TRACE crash_test.c:10 Enemy approching from X=108,Y=877 +2021-11-21 08:38:38 TRACE crash_test.c:10 Enemy approaching from X=108,Y=877 ``` #### Key Value @@ -334,11 +333,11 @@ Output as key value using `logax_write_key_value_format_to_stream` #include int main(int argc, char **argv) { - logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -date="2021-11-21" time="08:43:59" level="TRACE" file="crash_test.c" line_number=6 function="main" message="Enemy approching from X=108,Y=877" +date="2021-11-21" time="08:43:59" level="TRACE" file="crash_test.c" line_number=6 function="main" message="Enemy approaching from X=108,Y=877" ``` Output as key value using the `LOGAX_FORMATTER_KEY_VALUE` option with LogaxLogger. @@ -351,11 +350,11 @@ int main(int argc, char **argv) { logax_init_logger(&logax_logger); logax_set_formatter(&logax_logger, LOGAX_FORMATTER_KEY_VALUE); - logax_logger_trace(&logax_logger, "%s", "Enemy approching from X=108,Y=877"); + logax_logger_trace(&logax_logger, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -date="2021-11-21" time="08:46:00" level="TRACE" file="crash_test.c" line_number=10 message="Enemy approching from X=108,Y=877" +date="2021-11-21" time="08:46:00" level="TRACE" file="crash_test.c" line_number=10 message="Enemy approaching from X=108,Y=877" ``` #### JSON @@ -366,11 +365,11 @@ Output as json using `logax_write_json_format_to_stream` #include int main(int argc, char **argv) { - logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } ``` ```json -{"date":"2021-11-21","time":"08:44:58","level":"TRACE","file":"crash_test.c","line_number":6,"function":"main","message":"Enemy approching from X=108,Y=877"}, +{"date":"2021-11-21","time":"08:44:58","level":"TRACE","file":"crash_test.c","line_number":6,"function":"main","message":"Enemy approaching from X=108,Y=877"}, ``` Output as json using the `LOGAX_FORMATTER_JSON` option with LogaxLogger. @@ -383,11 +382,11 @@ int main(int argc, char **argv) { logax_init_logger(&logax_logger); logax_set_formatter(&logax_logger, LOGAX_FORMATTER_JSON); - logax_logger_trace(&logax_logger, "%s", "Enemy approching from X=108,Y=877"); + logax_logger_trace(&logax_logger, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -{"date":"2021-11-21","time":"08:45:36","level":"TRACE","file":"crash_test.c","line_number":10,"message":"Enemy approching from X=108,Y=877"}, +{"date":"2021-11-21","time":"08:45:36","level":"TRACE","file":"crash_test.c","line_number":10,"message":"Enemy approaching from X=108,Y=877"}, ``` ## Modularity @@ -403,7 +402,7 @@ liblogax is big on modularity, each component of the library can be excluded at ### LOGAX_USE_OLD_CONSOLE_MODE -If this macro is define the library will use the Windows API to color the log outputs, this macro is only effective on Windows system. This macro is most useful for old windows platform which the console cannot procecess the ANSI Color Codes. +If this macro is define the library will use the Windows API to color the log outputs, this macro is only effective on Windows system. This macro is most useful for old windows platform which the console cannot process the ANSI Color Codes. ``` #define LOGAX_USE_OLD_CONSOLE_MODE @@ -449,7 +448,7 @@ Define this macro to exclude the callback and hook feature of the library, this ### LOGAX_NO_COLORING -If this macro is define the library will not be compiled with preety print capability. The flag `LOGAX_OPTION_COLORED` will also not be available for use to customize the output. +If this macro is define the library will not be compiled with pretty print capability. The flag `LOGAX_OPTION_COLORED` will also not be available for use to customize the output. ```c #define LOGAX_NO_COLORING @@ -460,7 +459,7 @@ If this macro is define the library will not be compiled with preety print capab ### LOGAX_NO_TIME -On a system that does not have floating point capability or the time headers are anot available this macro can be defined to exclude adding data and time capability to the logging. Defining this macro will make the following macros unavailable `LOGAX_OPTION_DATE`, `LOGAX_OPTION_TIME`, `LOGAX_OPTION_DATE_TIME`. +On a system that does not have floating point capability or the time headers are not available this macro can be defined to exclude adding data and time capability to the logging. Defining this macro will make the following macros unavailable `LOGAX_OPTION_DATE`, `LOGAX_OPTION_TIME`, `LOGAX_OPTION_DATE_TIME`. ```c #define LOGAX_NO_TIME @@ -476,9 +475,9 @@ These three internal functions are responsible for the actual logging to output - logax_write_key_value_format_to_stream - logax_write_json_format_to_stream -The functions accept variadic parameters, the first 3 parameters are culmpulsory and the followed X parameters are for the vfprintf function for formating. The first parameter is the output stream `FILE *`, the second parameters is the flags to customize the outputs, the third parameter is the fmt to processes the variadic values. +The functions accept variadic parameters, the first 3 parameters are compulsory and the followed X parameters are for the vfprintf function for formatting. The first parameter is the output stream `FILE *`, the second parameters is the flags to customize the outputs, the third parameter is the fmt to processes the variadic values. -`LogaxLogger` struct allows logging properties and output stream to be shared across function calls, it internally uses the 3 functions above to otput the log. The special feature of LogaxLogger is the callback. On new log entry all the registered callbacks are invoked with the log event. +`LogaxLogger` struct allows logging properties and output stream to be shared across function calls, it internally uses the 3 functions above to output the log. The special feature of LogaxLogger is the callback. On new log entry all the registered callbacks are invoked with the log event. See the pages at [how it works](https://exoticlibraries.github.io/liblogax/how_it_works/index.html) for more explanation. diff --git a/docs/docs/callbacks.md b/docs/docs/callbacks.md index d98e5f9..9594f99 100644 --- a/docs/docs/callbacks.md +++ b/docs/docs/callbacks.md @@ -1,7 +1,7 @@ # Callback and Hook -LogaxLogger supports callback (or hook), the callbacks are invoked when a new log is sent. The callback can be used to create a custom output format or used to changed out the log is processed (e.g. blink bulb on andruino e.t.c). The output stream can be completely disabled by defining the macro `LOGAX_NO_OUTPUT_STREAM` or setiing the option to QUITE using the function `logax_set_quite`, in this case if callbacks are registered they will be invoked with the log event. +LogaxLogger supports callback (or hook), the callbacks are invoked when a new log is sent. The callback can be used to create a custom output format or used to changed out the log is processed (e.g. blink bulb on andruino e.t.c). The output stream can be completely disabled by defining the macro `LOGAX_NO_OUTPUT_STREAM` or setting the option to QUIET using the function `logax_set_quiet`, in this case if callbacks are registered they will be invoked with the log event. The callback function signature is @@ -9,7 +9,7 @@ The callback function signature is typedef void (*logax_callback)(const char *date, const char *time, const int level, const char *file, const size_t line_number, const char *function_name, const char *fmt, ...); ``` -The example belows shows how to register a callback which is invoked when there is a new log +The example below shows how to register a callback which is invoked when there is a new log ```c #include @@ -32,7 +32,7 @@ int main(int argc, char **argv) { LogaxLogger logax_logger; logax_init_logger(&logax_logger); - logax_set_quite(&logax_logger, 1); + logax_set_quiet(&logax_logger, 1); logax_logger_add_callback(&logax_logger, on_new_log_callback); logax_logger_trace(&logax_logger, "%s", "Logging the test for TRACE"); logax_logger_debug(&logax_logger, "%s", "Logging the test for DEBUG"); diff --git a/docs/docs/logging_levels.md b/docs/docs/logging_levels.md index d121881..196cf49 100644 --- a/docs/docs/logging_levels.md +++ b/docs/docs/logging_levels.md @@ -41,12 +41,12 @@ Trace is a verbose basic logging level and the default logging level, the color #include int main(int argc, char **argv) { - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_DEBUG, "%s", "Enemy approching from X=108,Y=877"); - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_INFO, "%s", "Enemy approching from X=108,Y=877"); - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_WARN, "%s", "Enemy approching from X=108,Y=877"); - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_ERROR, "%s", "Enemy approching from X=108,Y=877"); - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_FATAL, "%s", "Enemy approching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_DEBUG, "%s", "Enemy approaching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_INFO, "%s", "Enemy approaching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_WARN, "%s", "Enemy approaching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_ERROR, "%s", "Enemy approaching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_FATAL, "%s", "Enemy approaching from X=108,Y=877"); } ``` diff --git a/docs/docs/logging_with_logaxlogger.md b/docs/docs/logging_with_logaxlogger.md index ae52238..b63a57f 100644 --- a/docs/docs/logging_with_logaxlogger.md +++ b/docs/docs/logging_with_logaxlogger.md @@ -3,9 +3,9 @@ In a situation where callback is needed, no FILE* ability on the platform or the flags/options want to be shared across the log, the `LogaxLogger` struct can be used. No memory allocation is required when initaili -## Initialize LogaxLogger +## Iinitialized LogaxLogger -To initialize the LogaxLogger the function `logax_init_logger` can be used, it not neccessary to call the logax_init_logger function, all it does is set the LogaxLogger flags to default value, output_stream to stdout and fill the empty callbacks with NULL, these can be self-managed. +To iinitialized the LogaxLogger the function `logax_init_logger` can be used, it not necessary to call the logax_init_logger function, all it does is set the LogaxLogger flags to default value, output_stream to stdout and fill the empty callbacks with NULL, these can be self-managed. ```c #include @@ -27,7 +27,7 @@ For each of the logging level in logax a function is provider that accepts `Loga - logax_logger_error - logax_logger_fatal -Each of the function above invoke the coresponding `logax_write_*_format_to_stream` respectively, the default formatter when LogaxLogger is nitialize with the function logax_init_logger is `LOGAX_FORMATTER_TEXT`, the output format can be changed using the function `logax_set_formatter`. +Each of the function above invoke the corresponding `logax_write_*_format_to_stream` respectively, the default formatter when LogaxLogger is initialized with the function logax_init_logger is `LOGAX_FORMATTER_TEXT`, the output format can be changed using the function `logax_set_formatter`. ```c #include diff --git a/docs/docs/logging_without_logaxlogger.md b/docs/docs/logging_without_logaxlogger.md index df33033..226407c 100644 --- a/docs/docs/logging_without_logaxlogger.md +++ b/docs/docs/logging_without_logaxlogger.md @@ -1,45 +1,45 @@ # Logging without LogaxLogger -The library can be used to output log without need to setup the `LogaxLogger` struct, this will require the platform to have output stream or can write to file. If the macro LOGAX_NO_LOGGER is defined before including the logax.h geader file, the LogaxLogger struct and all related functions will not be compiled. The following functions provides the API to write to output stream in the supported formats +The library can be used to output log without need to setup the `LogaxLogger` struct, this will require the platform to have output stream or can write to file. If the macro LOGAX_NO_LOGGER is defined before including the logax.h header file, the LogaxLogger struct and all related functions will not be compiled. The following functions provides the API to write to output stream in the supported formats - logax_write_text_format_to_stream - logax_write_key_value_format_to_stream - logax_write_json_format_to_stream -`logax_write_text_format_to_stream` write the output in plain text format, the first paramater is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. +`logax_write_text_format_to_stream` write the output in plain text format, the first parameter is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. ```c #include int main(int argc, char **argv) { - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } // output // 2021-11-21 06:34:07 TRACE crash_test.c:13 Logging the test for TRACE ``` -`logax_write_key_value_format_to_stream` write the output in a key-value format coloring is ignored in this format, the first paramater is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. +`logax_write_key_value_format_to_stream` write the output in a key-value format coloring is ignored in this format, the first parameter is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. ```c #include int main(int argc, char **argv) { - logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } // output // date="2021-11-21" time="06:41:34" level="TRACE" file="crash_test.c" line_number=8 function="main" message="This is a trace output" ``` -`logax_write_json_format_to_stream` write the output in a json format, the first paramater is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. +`logax_write_json_format_to_stream` write the output in a json format, the first parameter is the stream, followed by the options, the options is the combinations of any of the LOGAX_OPTION_*, LOGAX_LEVEL_* and LOGAX_FORMATTER_* macros. ```c #include int main(int argc, char **argv) { - logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } // output diff --git a/docs/docs/modularity.md b/docs/docs/modularity.md index 9b55343..6f617d9 100644 --- a/docs/docs/modularity.md +++ b/docs/docs/modularity.md @@ -12,7 +12,7 @@ liblogax is big on modularity, each component of the library can be excluded at ## LOGAX_USE_OLD_CONSOLE_MODE -If this macro is define the library will use the Windows API to color the log outputs, this macro is only effective on Windows system. This macro is most useful for old windows platform which the console cannot procecess the ANSI Color Codes. +If this macro is define the library will use the Windows API to color the log outputs, this macro is only effective on Windows system. This macro is most useful for old windows platform which the console cannot process the ANSI Color Codes. ``` #define LOGAX_USE_OLD_CONSOLE_MODE @@ -58,7 +58,7 @@ Define this macro to exclude the callback and hook feature of the library, this ## LOGAX_NO_COLORING -If this macro is define the library will not be compiled with preety print capability. The flag `LOGAX_OPTION_COLORED` will also not be available for use to customize the output. +If this macro is define the library will not be compiled with pretty print capability. The flag `LOGAX_OPTION_COLORED` will also not be available for use to customize the output. ```c #define LOGAX_NO_COLORING @@ -69,7 +69,7 @@ If this macro is define the library will not be compiled with preety print capab ## LOGAX_NO_TIME -On a system that does not have floating point capability or the time headers are anot available this macro can be defined to exclude adding data and time capability to the logging. Defining this macro will make the following macros unavailable `LOGAX_OPTION_DATE`, `LOGAX_OPTION_TIME`, `LOGAX_OPTION_DATE_TIME`. +On a system that does not have floating point capability or the time headers are not available this macro can be defined to exclude adding data and time capability to the logging. Defining this macro will make the following macros unavailable `LOGAX_OPTION_DATE`, `LOGAX_OPTION_TIME`, `LOGAX_OPTION_DATE_TIME`. ```c #define LOGAX_NO_TIME diff --git a/docs/docs/options.md b/docs/docs/options.md index 8f89392..37e5884 100644 --- a/docs/docs/options.md +++ b/docs/docs/options.md @@ -7,7 +7,7 @@ liblogax uses the bitwise arithmetic to manage the options and flags, the flag v This enum is used to declare the basic options for the library, the bit size from (1 << 1) to (1 << 9) and (1 << 15) are used, (1 << 10) to (1 << 14) are reserved in case a new option is needed to be added. The following options are declared in the LogaxOption enum: -- LOGAX_OPTION_QUITE +- LOGAX_OPTION_QUIET - LOGAX_OPTION_DATE - LOGAX_OPTION_TIME - LOGAX_OPTION_DATE_TIME @@ -18,7 +18,7 @@ This enum is used to declare the basic options for the library, the bit size fro - LOGAX_OPTION_FUNCTION - LOGAX_OPTION_ALL -# LOGAX_OPTION_QUITE +# LOGAX_OPTION_QUIET This option disable writing the log to the output stream even if the program is compiled with write to output stream functionality. Bit value is `1 << 1`. diff --git a/docs/docs/output_formats.md b/docs/docs/output_formats.md index 9dd9883..a70fbd4 100644 --- a/docs/docs/output_formats.md +++ b/docs/docs/output_formats.md @@ -15,11 +15,11 @@ Output as text using `logax_write_text_format_to_stream` #include int main(int argc, char **argv) { - logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_text_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -2021-11-21 08:41:19 TRACE crash_test.c:6 --- [main ] Enemy approching from X=108,Y=877 +2021-11-21 08:41:19 TRACE crash_test.c:6 --- [main ] Enemy approaching from X=108,Y=877 ``` Output as text using the `LOGAX_FORMATTER_TEXT` option with LogaxLogger. @@ -32,11 +32,11 @@ int main(int argc, char **argv) { logax_init_logger(&logax_logger); logax_set_formatter(&logax_logger, LOGAX_FORMATTER_TEXT); - logax_logger_trace(&logax_logger, "%s", "Enemy approching from X=108,Y=877"); + logax_logger_trace(&logax_logger, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -2021-11-21 08:38:38 TRACE crash_test.c:10 Enemy approching from X=108,Y=877 +2021-11-21 08:38:38 TRACE crash_test.c:10 Enemy approaching from X=108,Y=877 ``` ## Key Value @@ -47,11 +47,11 @@ Output as key value using `logax_write_key_value_format_to_stream` #include int main(int argc, char **argv) { - logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_key_value_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -date="2021-11-21" time="08:43:59" level="TRACE" file="crash_test.c" line_number=6 function="main" message="Enemy approching from X=108,Y=877" +date="2021-11-21" time="08:43:59" level="TRACE" file="crash_test.c" line_number=6 function="main" message="Enemy approaching from X=108,Y=877" ``` Output as key value using the `LOGAX_FORMATTER_KEY_VALUE` option with LogaxLogger. @@ -64,11 +64,11 @@ int main(int argc, char **argv) { logax_init_logger(&logax_logger); logax_set_formatter(&logax_logger, LOGAX_FORMATTER_KEY_VALUE); - logax_logger_trace(&logax_logger, "%s", "Enemy approching from X=108,Y=877"); + logax_logger_trace(&logax_logger, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -date="2021-11-21" time="08:46:00" level="TRACE" file="crash_test.c" line_number=10 message="Enemy approching from X=108,Y=877" +date="2021-11-21" time="08:46:00" level="TRACE" file="crash_test.c" line_number=10 message="Enemy approaching from X=108,Y=877" ``` ## JSON @@ -79,11 +79,11 @@ Output as json using `logax_write_json_format_to_stream` #include int main(int argc, char **argv) { - logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approching from X=108,Y=877"); + logax_write_json_format_to_stream(stdout, LOGAX_OPTION_ALL | LOGAX_LEVEL_TRACE, "%s", "Enemy approaching from X=108,Y=877"); } ``` ```json -{"date":"2021-11-21","time":"08:44:58","level":"TRACE","file":"crash_test.c","line_number":6,"function":"main","message":"Enemy approching from X=108,Y=877"}, +{"date":"2021-11-21","time":"08:44:58","level":"TRACE","file":"crash_test.c","line_number":6,"function":"main","message":"Enemy approaching from X=108,Y=877"}, ``` Output as json using the `LOGAX_FORMATTER_JSON` option with LogaxLogger. @@ -96,10 +96,10 @@ int main(int argc, char **argv) { logax_init_logger(&logax_logger); logax_set_formatter(&logax_logger, LOGAX_FORMATTER_JSON); - logax_logger_trace(&logax_logger, "%s", "Enemy approching from X=108,Y=877"); + logax_logger_trace(&logax_logger, "%s", "Enemy approaching from X=108,Y=877"); } ``` ``` -{"date":"2021-11-21","time":"08:45:36","level":"TRACE","file":"crash_test.c","line_number":10,"message":"Enemy approching from X=108,Y=877"}, +{"date":"2021-11-21","time":"08:45:36","level":"TRACE","file":"crash_test.c","line_number":10,"message":"Enemy approaching from X=108,Y=877"}, ``` diff --git a/docs/how_it_works/index.md b/docs/how_it_works/index.md index 3eb36f3..4881271 100644 --- a/docs/how_it_works/index.md +++ b/docs/how_it_works/index.md @@ -6,9 +6,9 @@ These three internal functions are responsible for the actual logging to output - logax_write_key_value_format_to_stream - logax_write_json_format_to_stream -The functions accept variadic parameters, the first 3 parameters are culmpulsory and the followed X parameters are for the vfprintf function for formating. The first parameter is the output stream `FILE *`, the second parameters is the flags to customize the outputs, the third parameter is the fmt to processes the variadic values. +The functions accept variadic parameters, the first 3 parameters are compulsory and the followed X parameters are for the vfprintf function for formatting. The first parameter is the output stream `FILE *`, the second parameters is the flags to customize the outputs, the third parameter is the fmt to processes the variadic values. -`LogaxLogger` struct allows logging properties and output stream to be shared across function calls, it internally uses the 3 functions above to otput the log. The special feature of LogaxLogger is the callback. On new log entry all the registered callbacks are invoked with the log event. +`LogaxLogger` struct allows logging properties and output stream to be shared across function calls, it internally uses the 3 functions above to output the log. The special feature of LogaxLogger is the callback. On new log entry all the registered callbacks are invoked with the log event. See the pages at [how it works](https://exoticlibraries.github.io/liblogax/how_it_works/index.html) for more explanation. diff --git a/docs/index.md b/docs/index.md index df0d9cc..14d9c72 100644 --- a/docs/index.md +++ b/docs/index.md @@ -44,13 +44,13 @@ int main(int argc, char **argv) { - Speed. logax was developed with speed and zero performance intrusion in mind. - Modular, excluded un-used features from your test, [modularity](https://exoticlibraries.github.io/liblogax/docs/modularity.html). - Zero allocation, No memory allocation. -- Levelled logging to customize and differenciate the outputs. +- Levelled logging to customize and differentiate the outputs. - Support for callbacks and hooks. -- Very portable, compatiple with ANSI C and C++98 without any trade off in functionalities. +- Very portable, compatible with ANSI C and C++98 without any trade off in functionalities. - Output log in text, key-value and JSON encoding formats. - Pretty logging for all supported output formats. -- Simple method to achive options in the logging system using bitwise operations. -- Detail docuentation with examples and API references. +- Simple method to achieve options in the logging system using bitwise operations. +- Detail documentation with examples and API references. ## Installation @@ -58,7 +58,7 @@ If you install the library file `logax.h` using any of the commands below, it ca ### Windows -Install the library using powershell. It auto detect your insalled C and C++ compilers include directory and install liblogax into the include folder. Execute the command in powershell as admin. +Install the library using powershell. It auto detect your installed C and C++ compilers include directory and install liblogax into the include folder. Execute the command in powershell as admin. ```powershell & $([scriptblock]::Create((New-Object Net.WebClient).DownloadString("https://exoticlibraries.github.io/magic/install.ps1"))) liblogax diff --git a/include/exotic/logax.h b/include/exotic/logax.h index aa57be0..2cb2d69 100644 --- a/include/exotic/logax.h +++ b/include/exotic/logax.h @@ -97,7 +97,7 @@ typedef void (*logax_callback)(const char *date, const char *time, const int lev backward compatibility */ enum LogaxOption { - LOGAX_OPTION_QUITE = 1 << 1, /**< the option to disable writing to output stream */ + LOGAX_OPTION_QUIET = 1 << 1, /**< the option to disable writing to output stream */ #ifndef LOGAX_NO_TIME LOGAX_OPTION_DATE = 1 << 2, /**< option to write/set the date of the log event */ LOGAX_OPTION_TIME = 1 << 3, /**< option to set the time of the log event */ @@ -107,12 +107,17 @@ enum LogaxOption { LOGAX_OPTION_FILE_NAME_ONLY = 1 << 6, /**< option to set only the name of the file where the log event was sent from */ LOGAX_OPTION_LINE_NUMBER = 1 << 7, /**< option to set the line number where the log even was sent */ #ifndef LOGAX_NO_COLORING - LOGAX_OPTION_COLORED = 1 << 8, /**< this option is used to enable preety print and colored outputs */ + LOGAX_OPTION_COLORED = 1 << 8, /**< this option is used to enable pretty print and colored outputs */ #endif LOGAX_OPTION_FUNCTION = 1 << 9, /**< option to write/set the name of the function where the log was set from */ - LOGAX_OPTION_ALL = 1 << 15 /**< this option enables all the other options above apart from LOGAX_OPTION_QUITE */ + LOGAX_OPTION_ALL = 1 << 15 /**< this option enables all the other options above apart from LOGAX_OPTION_QUIET */ }; +/* + +*/ +#define LOGAX_OPTION_QUITE LOGAX_OPTION_QUIET + /** The options to classify the log event by level */ @@ -260,11 +265,16 @@ static unsigned logax_logger_add_callback(LogaxLogger *logax_logger, logax_callb /** */ -#define logax_set_quite(logax_logger, make_quite) {\ - if (!make_quite && ((logax_logger)->flags & LOGAX_OPTION_QUITE)) { logax_remove_flag((logax_logger)->flags, LOGAX_OPTION_QUITE); }\ - else if (make_quite && !((logax_logger)->flags & LOGAX_OPTION_QUITE)) { logax_add_flag((logax_logger)->flags, LOGAX_OPTION_QUITE); }\ +#define logax_set_quiet(logax_logger, make_quiet) {\ + if (!make_quiet && ((logax_logger)->flags & LOGAX_OPTION_QUIET)) { logax_remove_flag((logax_logger)->flags, LOGAX_OPTION_QUIET); }\ + else if (make_quiet && !((logax_logger)->flags & LOGAX_OPTION_QUIET)) { logax_add_flag((logax_logger)->flags, LOGAX_OPTION_QUIET); }\ } +/** + Alias for logax_set_quiet, for backward compatibility +*/ +#define logax_set_quite logax_set_quiet + #ifndef LOGAX_NO_OUTPUT_STREAM /* @@ -319,7 +329,7 @@ HANDLE logax_hConsole; /** */ -#define LOGAX_INITIALIZE_HCONSOLE() if (!initialized_h_console) {\ +#define LOGAX_Iinitialized_HCONSOLE() if (!initialized_h_console) {\ CONSOLE_SCREEN_BUFFER_INFO info;\ if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info)) {\ logax_default_color = info.wAttributes;\ @@ -356,7 +366,7 @@ HANDLE logax_hConsole; } #else -#define LOGAX_INITIALIZE_HCONSOLE() +#define LOGAX_Iinitialized_HCONSOLE() #ifndef LOGAX_NO_COLORING #define LOGAX_DELEGATE_FPRINT_STR(foreground, text) if (is_colored) { fprintf(stream, "%s%s%s", foreground, text, LOGAX_RESET_TERMINAL); } else { fprintf(stream, "%s", text); } @@ -387,8 +397,8 @@ HANDLE logax_hConsole; */ static void logax_write_text_format_to_stream_final__internal__(FILE *stream, int flags, const char *file_path, const size_t line_number, const char *function_name, const char *fmt, va_list va_args) { - if (flags & LOGAX_OPTION_QUITE) return; - LOGAX_INITIALIZE_HCONSOLE(); + if (flags & LOGAX_OPTION_QUIET) return; + LOGAX_Iinitialized_HCONSOLE(); #ifndef LOGAX_NO_COLORING unsigned is_colored = (flags & LOGAX_OPTION_COLORED || (flags & LOGAX_OPTION_ALL)); #else @@ -473,8 +483,8 @@ static void logax_write_text_format_to_stream__internal__(FILE *stream, int flag */ static void logax_write_key_value_format_to_stream_final__internal__(FILE *stream, int flags, const char *file_path, const size_t line_number, const char *function_name, const char *fmt, va_list va_args) { - if (flags & LOGAX_OPTION_QUITE) return; - LOGAX_INITIALIZE_HCONSOLE(); + if (flags & LOGAX_OPTION_QUIET) return; + LOGAX_Iinitialized_HCONSOLE(); unsigned is_colored = 0; unsigned print_comma = 0; unsigned has_any_level = (flags & LOGAX_LEVEL_TRACE) || (flags & LOGAX_LEVEL_DEBUG) || (flags & LOGAX_LEVEL_INFO) || @@ -569,8 +579,8 @@ static void logax_write_key_value_format_to_stream__internal__(FILE *stream, int */ static void logax_write_json_format_to_stream_final__internal__(FILE *stream, int flags, const char *file_path, const size_t line_number, const char *function_name, const char *fmt, va_list va_args) { - if (flags & LOGAX_OPTION_QUITE) return; - LOGAX_INITIALIZE_HCONSOLE(); + if (flags & LOGAX_OPTION_QUIET) return; + LOGAX_Iinitialized_HCONSOLE(); #ifndef LOGAX_NO_COLORING unsigned is_colored = (flags & LOGAX_OPTION_COLORED || (flags & LOGAX_OPTION_ALL)); #else diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8ef8542..c2f4de5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.17) project(libfio_tests VERSION 1.0) set(FILE_EXT "") -set(INCLUDE_PATHS -I${PWD}/../../include/ -I${PWD}/../include/ -I../../include/ -I../include/) -include_directories(${PWD}/../../include/ ${PWD}/../include/ ../../include/ ../include/) +set(INCLUDE_PATHS -I${PWD}/../../libcester/include/ -I${PWD}/../include/ -I../../libcester/include/ -I../include/) +include_directories(${PWD}/../../libcester/include/ ${PWD}/../include/ ../../libcester/include/ ../include/) add_executable(logax_test ./empty_c_file.c) set_target_properties(logax_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ./build/ ) diff --git a/test/test_basics.c b/test/test_basics.c index 7c7b02e..203f8a7 100644 --- a/test/test_basics.c +++ b/test/test_basics.c @@ -49,7 +49,7 @@ CESTER_TEST(logax_callback, test_inst, { LogaxLogger logax_logger; logax_init_logger(&logax_logger); - logax_set_quite(&logax_logger, 1); + logax_set_quiet(&logax_logger, 1); logax_logger_add_callback(&logax_logger, on_new_log_callback); logax_logger_add_callback(&logax_logger, on_new_log_callback2); diff --git a/test/test_no_callback.c b/test/test_no_callback.c index c7af751..b511107 100644 --- a/test/test_no_callback.c +++ b/test/test_no_callback.c @@ -28,7 +28,7 @@ CESTER_TEST(logax_no_callback, test_inst, { LogaxLogger logax_logger; logax_init_logger(&logax_logger); - logax_set_quite(&logax_logger, 1); + logax_set_quiet(&logax_logger, 1); logax_logger_add_callback(&logax_logger, on_new_log_callback); logax_logger_add_callback(&logax_logger, on_new_log_callback2);