Skip to content

Commit

Permalink
Merge pull request #4 from exoticlibraries/dev
Browse files Browse the repository at this point in the history
fix type as sugested by Michael Litwak
  • Loading branch information
Thecarisma authored May 13, 2022
2 parents 2228088 + 36820ce commit 6d6355c
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
os: [macos-latest, ubuntu-latest]
platform: [x86, x64]
compiler: [gcc, clang, tcc]

Expand Down
79 changes: 39 additions & 40 deletions README.md

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

import themata
import themata.fandango

project = 'liblogax'
copyright = '2021, Exotic Libraries - MIT License'
author = 'Adewale Azeez and Other Contributors'

html_theme_path = [themata.get_html_theme_path()]
html_theme = 'fandango'
master_doc = 'index'
html_favicon = 'liblogax.png'
Expand Down Expand Up @@ -33,6 +32,10 @@
#'has_left_sidebar': True,
'has_right_sidebar': True,
'show_navigators': True,
'syntax_highlighter': 'highlightjs',
'code_block_editable': False,
'syntax_highlighter_theme': 'a11y-dark',
'syntax_highlighter_iframe_embed': False,
'social_icons': [
('fab fa-twitter', 'https://twitter.com/exoticlibs'),
('fab fa-github', 'https://github.com/exoticlibraries/liblogax/')
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/callbacks.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

# 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

```c
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 <exotic/logax.h>
Expand All @@ -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");
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/logging_levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ Trace is a verbose basic logging level and the default logging level, the color
#include <exotic/logax.h>

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");
}
```
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/logging_with_logaxlogger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exotic/logax.h>
Expand All @@ -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 <exotic/logax.h>
Expand Down
14 changes: 7 additions & 7 deletions docs/docs/logging_without_logaxlogger.md
Original file line number Diff line number Diff line change
@@ -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 <exotic/logax.h>

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 <exotic/logax.h>
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 <exotic/logax.h>

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
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/modularity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.

Expand Down
24 changes: 12 additions & 12 deletions docs/docs/output_formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Output as text using `logax_write_text_format_to_stream`
#include <exotic/logax.h>

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.
Expand All @@ -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
Expand All @@ -47,11 +47,11 @@ Output as key value using `logax_write_key_value_format_to_stream`
#include <exotic/logax.h>

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.
Expand All @@ -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
Expand All @@ -79,11 +79,11 @@ Output as json using `logax_write_json_format_to_stream`
#include <exotic/logax.h>

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.
Expand All @@ -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"},
```
4 changes: 2 additions & 2 deletions docs/how_it_works/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ 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
If you install the library file `logax.h` using any of the commands below, it can be included in your test like `<exotic/logax.h>`.
### 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
Expand Down
Loading

0 comments on commit 6d6355c

Please sign in to comment.