Workbench Library
0.1b
|
A logging utility for C programs with configurable verbosity levels and optional context information. More...
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Go to the source code of this file.
Macros | |||||
#define | log_format(file, tag, message, ...) | ||||
Formats and logs a message to a specified file with a tag and optional arguments. More... | |||||
Config | |||||
#define | LOG_LEVEL 4 | ||||
Default log level if not defined elsewhere. More... | |||||
#define | PRINT_FUNC (LOG_LEVEL > 3) | ||||
Controls whether to include the function name in log messages. | |||||
#define | PRINT_FILE (LOG_LEVEL > 2) | ||||
Controls whether to include the file name and line number in log messages. | |||||
Color function-like macros | |||||
#define | COLOR(text, color, style) "\033[" #style ";" #color "m" text "\033[0m" | ||||
Adds ANSI color and style codes to a text string. More... | |||||
#define | RED(text) COLOR(text, 31, 0) | ||||
Colors the text red. | |||||
#define | GRN(text) COLOR(text, 32, 0) | ||||
Colors the text green. | |||||
#define | YLW(text) COLOR(text, 33, 0) | ||||
Colors the text yellow. | |||||
#define | PRL(text) COLOR(text, 35, 0) | ||||
Colors the text purple. | |||||
#define | CYN(text) COLOR(text, 36, 0) | ||||
Colors the text cyan. | |||||
Logging function-like macros | |||||
| |||||
#define | log_d(message, ...) | ||||
Logs a debug message. More... | |||||
#define | log_i(message, ...) | ||||
Logs an info message. More... | |||||
#define | log_w(message, ...) | ||||
Logs a warning message. More... | |||||
#define | log_e(message, ...) | ||||
Logs an error message. More... | |||||
A logging utility for C programs with configurable verbosity levels and optional context information.
This header file provides macros for logging messages with different severity levels (debug, info, warning, error). The log messages can include additional context information such as the function name, file name, and line number. The verbosity of the logging can be controlled through the LOG_LEVEL
macro.
Features:
Example usage:
#define COLOR | ( | text, | |
color, | |||
style | |||
) | "\033[" #style ";" #color "m" text "\033[0m" |
Adds ANSI color and style codes to a text string.
This macro wraps a text string with ANSI color and style codes to display the text in a specific color and style in the terminal. Common style codes include:
Common color codes include:
text | The text to be colored and styled. |
color | The ANSI color code. |
style | The ANSI style code. |
#define log_d | ( | message, | |
... | |||
) |
Logs a debug message.
#define log_e | ( | message, | |
... | |||
) |
Logs an error message.
#define log_format | ( | file, | |
tag, | |||
message, | |||
... | |||
) |
Formats and logs a message to a specified file with a tag and optional arguments.
This macro writes a formatted log message to the provided file. The log message includes a tag and can incorporate additional formatted arguments similar to printf
.
The macro supports optional arguments which are included in the formatted message if provided.
file | The file stream to write the log message to (e.g., stderr, stdout, or a file pointer). |
tag | A string tag to categorize or label the log message (e.g., "INFO", "ERROR"). |
message | The main message string to be logged. This can include format specifiers like printf. |
... | Optional additional arguments that correspond to the format specifiers in the message. |
Example usage:
#define log_i | ( | message, | |
... | |||
) |
Logs an info message.
#define LOG_LEVEL 4 |
Default log level if not defined elsewhere.
LOG_LEVEL determines the verbosity of the logging. The higher the value, the more verbose the logging:
#define log_w | ( | message, | |
... | |||
) |
Logs a warning message.