4#define _POSIX_C_SOURCE 200809L
14static const char *level_strings[] = {
"DEBUG",
"INFO",
"WARN",
"ERROR"};
15static const char *level_colors[] = {
"\033[36m",
"\033[32m",
"\033[33m",
"\033[31m"};
16static const char *color_reset =
"\033[0m";
34 if (!log)
return NULL;
59 if (log) log->
level = level;
80 FILE *out = level_file(level);
102 level_strings[level], log->
name);
107 if (prefix < 0 || body < 0)
return;
108 size_t len = (
size_t)prefix + (
size_t)body + 1;
116 line[len - 1] =
'\n';
146 logger_vlog(log, level,
fmt,
args);
Memory allocation wrappers backed by libttak.
void cwist_free(void *ptr)
Free memory obtained via cwist_alloc/cwist_strdup/etc.
char * cwist_strdup(const char *src)
Duplicate a string using libttak-backed storage.
void * cwist_alloc(size_t size)
Allocate zeroed memory tracked by libttak.
#define CWIST_LOG_ERROR(fmt,...)
#define CWIST_LOG_INFO(fmt,...)
#define CWIST_LOG_WARN(fmt,...)
#define CWIST_LOG_DEBUG(fmt,...)
bool cwist_log_async_submit(int fd, const char *line, size_t len)
Queue one complete line for fd (STDOUT_FILENO or STDERR_FILENO).
Internal hook from the log call sites into the async log writer.
void cwist_logger_warn(cwist_logger *log, const char *fmt,...)
Logs a formatted message at WARN level on stderr.
cwist_logger * cwist_logger_create(const char *name)
Creates a logger instance.
void cwist_logger_error(cwist_logger *log, const char *fmt,...)
Logs a formatted message at ERROR level on stderr.
void cwist_logger_log(cwist_logger *log, cwist_log_level_t level, const char *fmt,...)
Logs a formatted message at the given level.
void cwist_logger_set_colors(cwist_logger *log, bool enabled)
Enables or disables ANSI color output in log lines.
void cwist_logger_info(cwist_logger *log, const char *fmt,...)
Logs a formatted message at INFO level on stdout.
void cwist_logger_set_level(cwist_logger *log, cwist_log_level_t level)
Sets the minimum log level that will be emitted.
void cwist_logger_destroy(cwist_logger *log)
Destroys a logger instance and frees its name.
void cwist_logger_debug(cwist_logger *log, const char *fmt,...)
Logs a formatted message at DEBUG level on stdout.
Application-level structured logging.