libmemalloc
v4.0.00
Modern Memory Allocator
|
Files | |
file | logs.h |
Logging macros and configuration for libmemalloc. | |
Macros | |
#define | LOG_LEVEL LOG_LEVEL_DEBUG |
Default log level if not defined. | |
#define | _POSIX_C_SOURCE 200809UL |
Expose POSIX extensions for clock_gettime and pthread mutex initializer. | |
#define | LOG_PRINTF(file, ...) fprintf(file, __VA_ARGS__) |
Compiler-specific printf abstraction. | |
#define | LOG_VPRINTF(file, fmt, args) vfprintf(file, fmt, args) |
Compiler-specific vprintf abstraction. | |
#define | PREFIX_ERROR "[ERROR]" |
#define | PREFIX_WARNING "[WARNING]" |
#define | PREFIX_INFO "[INFO]" |
#define | PREFIX_DEBUG "[DEBUG]" |
#define | COLOR_RED "\033[0;31m" |
#define | COLOR_YELLOW "\033[0;33m" |
#define | COLOR_BLUE "\033[0;34m" |
#define | COLOR_GREEN "\033[0;32m" |
#define | COLOR_RESET "\033[0m" |
#define | ATTR_PRINTF(fmt_idx, var_idx) __attribute__((format(printf, fmt_idx, var_idx))) |
Macro to apply GCC printf-style format checking on custom functions. | |
#define | LOG_ERROR(fmt, ...) |
Logs an error message (red). | |
#define | LOG_WARNING(fmt, ...) |
Logs a warning message (yellow). | |
#define | LOG_INFO(fmt, ...) |
Logs an info message (blue). | |
#define | LOG_DEBUG(fmt, ...) |
Logs a debug message (green). | |
Enumerations | |
enum | log_level_t { LOG_LEVEL_NONE = (uint8_t)(0u) , LOG_LEVEL_ERROR = (uint8_t)(1u) , LOG_LEVEL_WARNING = (uint8_t)(2u) , LOG_LEVEL_INFO = (uint8_t)(3u) , LOG_LEVEL_DEBUG = (uint8_t)(4u) } |
Defines log levels for the logging system. More... | |
Functions | |
static int | LOG_output (log_level_t level, const char *color, const char *prefix, const char *file, const char *func, int line, const char *fmt,...) __attribute__((format(printf |
Internal logging implementation: thread‐safe, prints timestamp, optional ANSI color, severity prefix, formatted message, and source location. | |
#define _POSIX_C_SOURCE 200809UL |
Expose POSIX extensions for clock_gettime and pthread mutex initializer.
#define ATTR_PRINTF | ( | fmt_idx, | |
var_idx | |||
) | __attribute__((format(printf, fmt_idx, var_idx))) |
Macro to apply GCC printf-style format checking on custom functions.
#define COLOR_BLUE "\033[0;34m" |
#define COLOR_GREEN "\033[0;32m" |
#define COLOR_RED "\033[0;31m" |
#define COLOR_RESET "\033[0m" |
#define COLOR_YELLOW "\033[0;33m" |
#define LOG_DEBUG | ( | fmt, | |
... | |||
) |
Logs a debug message (green).
#define LOG_ERROR | ( | fmt, | |
... | |||
) |
Logs an error message (red).
#define LOG_INFO | ( | fmt, | |
... | |||
) |
Logs an info message (blue).
#define LOG_LEVEL LOG_LEVEL_DEBUG |
Default log level if not defined.
#define LOG_PRINTF | ( | file, | |
... | |||
) | fprintf(file, __VA_ARGS__) |
Compiler-specific printf abstraction.
#define LOG_VPRINTF | ( | file, | |
fmt, | |||
args | |||
) | vfprintf(file, fmt, args) |
Compiler-specific vprintf abstraction.
#define LOG_WARNING | ( | fmt, | |
... | |||
) |
Logs a warning message (yellow).
#define PREFIX_DEBUG "[DEBUG]" |
#define PREFIX_ERROR "[ERROR]" |
#define PREFIX_INFO "[INFO]" |
#define PREFIX_WARNING "[WARNING]" |
enum log_level_t |
Defines log levels for the logging system.
Enumerator | |
---|---|
LOG_LEVEL_NONE | Disables all logs |
LOG_LEVEL_ERROR | Enables error logs |
LOG_LEVEL_WARNING | Enables warning logs |
LOG_LEVEL_INFO | Enables info logs |
LOG_LEVEL_DEBUG | Enables all logs |
|
inlinestatic |
Internal logging implementation: thread‐safe, prints timestamp, optional ANSI color, severity prefix, formatted message, and source location.
This function:
level
is within the configured LOG_LEVEL. Returns -EIO if the level is too verbose.[HH:MM:SS.mmm]
.color
codes around the prefix
; otherwise emits only the prefix text.fmt
and variadic arguments.(at file:line:func())
.[in] | level | Log severity (ERROR, WARNING, INFO, DEBUG). |
[in] | color | ANSI color sequence for interactive terminals. |
[in] | prefix | Text prefix for the log level (e.g. "[ERROR]"). |
[in] | file | Source file name (FILE) of the call. |
[in] | func | Function name (func) of the call. |
[in] | line | Line number (LINE) of the call. |
[in] | fmt | printf-style format string for the log message. |
[in] | ... | Arguments corresponding to fmt . |
EXIT_SUCCESS | Message was successfully logged. |
-EIO | The specified level is more verbose than LOG_LEVEL. |