Some changes do log.h and adding its documentation

This commit is contained in:
Leonardo committed 2020-04-09 22:04:19 -03:00
1 parent da6f5ea05c
commit aa214d179e
36 files changed
+1156 -68

No files matched your search

@@ -1 +0,0 @@
# Collections Overview
+3
View File
@@ -19,6 +19,9 @@
- [Generic Assertions](./utl/assert.h/generic_assertions.md)
- [foreach.h](./utl/foreach.h/index.md)
- [log.h](./utl/log.h/index.md)
- [Log Functions](./utl/log.h/log_functions.md)
- [Configuration](./utl/log.h/configuration.md)
- [Meanings](./utl/log.h/meanings.md)
- [test.h](./utl/test.h/index.md)
- [timer.h](./utl/timer.h/index.md)
- [Examples](./Examples/examples.md)
+62
View File
@@ -0,0 +1,62 @@
# Configuration
## cmc_log_config
This is an anonymous static `struct` that can be directly modified to change logging levels, enable or disable output or change file output.
```c
static struct
{
enum cmc_log_type tlevel;
enum cmc_log_type flevel;
bool tenabled;
bool fenabled;
bool enabled;
FILE * file;
} cmc_log_config = { 0, 0, true, true, true, NULL };
```
__Members__
* `tlevel` - Terminal log level (`stderr`)
* `flevel` - File log level
* `tenabled` - Terminal logging enabled if `true`
* `fenabled` - File logging enabled if `true`
* `enabled` - Enables or disables all logs
* `FILE *file` - File for output
This configuration is global to every log. The `FILE` pointer is not handled by the API and needs to be able to write to the file.
## Log Level
By tuning `tlevel` and `flevel` (both accessed from `cmc_log_config`) you can filter which log messages are printed or not.
* If the log level is `0`, all logs are enabled
* If the log level `X` is positive:
* All levels less than `X` will be disabled
* If `X` is greater than the level of `FATAL`, all logs are disabled
* If the log level `X` is negative:
* All levels greater than `abs(X)` are enabled
* If `abs(X)` is greater than the level of `FATAL`, all logs are enabled
__Examples__
If you want to output only `TRACE` logs to a file and the rest to `stderr`:
* `cmc_log_config.tlevel = CMC_LOG_DEBUG`
* `cmc_log_config.flevel = -CMC_LOG_TRACE`
If you want to output only `FATAL` to `stderr` and the rest to a file:
* `cmc_log_config.tlevel = CMC_LOG_FATAL`
* `cmc_log_config.flevel = -CMC_LOG_ERROR`
If you want to output only `FATAL` and `ERROR` to a file an nothing to `stderr`:
* `cmc_log_config.tlevel = CMC_LOG_FATAL + 1`
* `cmc_log_config.flevel = CMC_LOG_ERROR`
__Summary__
* Log Level > 0: "Allow all log levels that are greater than this, including it"
* Log Level < 0: "Allow all log levels that are smaller than this, including it"
+21 -1
View File
@@ -1,3 +1,23 @@
# log.h
Logging utility.
Simple and customizable logging macros. Messages can have a custom logging level and a custom file output. This customization can be done via the global variable [`cmc_log_config`](configuration.html#cmc_log_config). Logs are outputted to `stderr`.
## cmc_log_type
Defines the possible Log Levels. These are used to categorize log messages. The higher the number, the more severe or important that message is. Check out [here](meanings.html)
```c
enum cmc_log_type
{
CMC_LOG_TRACE = 1,
CMC_LOG_DEBUG = 2,
CMC_LOG_INFO = 3,
CMC_LOG_WARN = 4,
CMC_LOG_ERROR = 5,
CMC_LOG_FATAL = 6
};
```
## CMC_LOG_COLOR
If this macro is defined, logging will be outputted with [ANSI color escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors). If you are logging into a file, these escape codes are not printed.
+67
View File
@@ -0,0 +1,67 @@
# Log Functions
## cmc_log_trace
Defines a message with a Log Level of `CMC_LOG_TRACE`.
```c
#define cmc_log_trace(fmt, ...)
```
* `fmt` - A string that contains a text to be written that may contain format specifiers
* `...` - Optional. Values to be formatted into the string that will be printed
## cmc_log_debug
Defines a message with a Log Level of `CMC_LOG_DEBUG`.
```c
#define cmc_log_debug(fmt, ...)
```
* `fmt` - A string that contains a text to be written that may contain format specifiers
* `...` - Optional. Values to be formatted into the string that will be printed
## cmc_log_info
Defines a message with a Log Level of `CMC_LOG_INFO`.
```c
#define cmc_log_info(fmt, ...)
```
* `fmt` - A string that contains a text to be written that may contain format specifiers
* `...` - Optional. Values to be formatted into the string that will be printed
## cmc_log_warn
Defines a message with a Log Level of `CMC_LOG_WARN`.
```c
#define cmc_log_warn(fmt, ...)
```
* `fmt` - A string that contains a text to be written that may contain format specifiers
* `...` - Optional. Values to be formatted into the string that will be printed
## cmc_log_error
Defines a message with a Log Level of `CMC_LOG_ERROR`.
```c
#define cmc_log_error(fmt, ...)
```
* `fmt` - A string that contains a text to be written that may contain format specifiers
* `...` - Optional. Values to be formatted into the string that will be printed
## cmc_log_fatal
Defines a message with a Log Level of `CMC_LOG_FATAL`.
```c
#define cmc_log_fatal(fmt, ...)
```
* `fmt` - A string that contains a text to be written that may contain format specifiers
* `...` - Optional. Values to be formatted into the string that will be printed
+10
View File
@@ -0,0 +1,10 @@
# Meanings
What does each Log Level means? It depends on the application. In here you will read more about how the C Macro Collections library uses each of these Log Levels, but this does not mean you should use them like described.
* __TRACE__ - Trace is used to describe the inner workings of a function or an algorithm. These messages can be used extensively, meaning that their content is probably not very useful, even for debugging.
* __DEBUG__ - Mainly used for debugging, tracking certain variables, checking if pointers were deallocated or anything useful to help visualizing what your program is doing in general.
* __INFO__ - Info can be used as a heads up. Something that is important to note, but is not quite a warning or an error.
* __WARN__ - Warnings are attributed to all cases where the function can recover from and usually treated by it. In most cases the user can treat these warnings himself.
* __ERROR__ - Something really bad happened. Your program will not crash yet but depending on what comes next, it will. This might be attributed to pointers that shouldn't be null because later functions might use it.
* __FATAL__ - This will probably be the last logging message before your program crashes or goes into madness. Fatal errors are commonly attributed to dereferencing NULL pointers.