|
libmemalloc
v3.5.00
Modern Memory Allocator
|
Files | |
| file | logs.h |
| Logging macros and configuration for libmemalloc. | |
Macros | |
| #define | LOG_LEVEL LOG_LEVEL_DEBUG |
| Logging verbosity threshold for this module. | |
| #define | LOG_PRINTF(...) fprintf(__VA_ARGS__) |
| Compiler-specific printf abstraction (variadic). | |
| #define | LOG_VPRINTF(...) vfprintf(__VA_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) |
| Macro to apply printf-style format checking on custom functions when supported by the compiler. | |
| #define | LOG_ERROR(...) |
| Logs an error message (red). | |
| #define | LOG_WARNING(...) |
| Logs a warning message (yellow). | |
| #define | LOG_INFO(...) |
| Logs an info message (blue). | |
| #define | LOG_DEBUG(...) |
| 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,...) |
| Internal logging implementation: thread‐safe, prints timestamp, optional ANSI color, severity prefix, formatted message, and source location. | |
| #define ATTR_PRINTF | ( | fmt_idx, | |
| var_idx | |||
| ) |
Macro to apply printf-style format checking on custom functions when supported by the compiler.
Expands to GCC/Clang's attribute((format(printf, ...))) when available, otherwise to nothing.
| #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 | ( | ... | ) |
Logs a debug message (green).
| #define LOG_ERROR | ( | ... | ) |
Logs an error message (red).
Usage: LOG_ERROR("Message\n"); LOG_ERROR("Message: %d\n", code);
| #define LOG_INFO | ( | ... | ) |
Logs an info message (blue).
| #define LOG_LEVEL LOG_LEVEL_DEBUG |
Logging verbosity threshold for this module.
Sets the minimum severity of log messages that will be compiled into this translation unit. Only log calls at or below the specified level are enabled:
Default log level if not defined.
| #define LOG_PRINTF | ( | ... | ) | fprintf(__VA_ARGS__) |
Compiler-specific printf abstraction (variadic).
Uses __builtin_fprintf when available; falls back to fprintf otherwise. Intended usage matches fprintf:
LOG_PRINTF(stream, "fmt %d\n", value);
| #define LOG_VPRINTF | ( | ... | ) | vfprintf(__VA_ARGS__) |
Compiler-specific vprintf abstraction.
Uses __builtin_vfprintf when available; falls back to vfprintf otherwise. Intended usage matches vfprintf:
LOG_VPRINTF(stream, "fmt %d\n", args);
| #define LOG_WARNING | ( | ... | ) |
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. |