18#ifdef WITH_CLOG_PTHREADS
24#if defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
32# include <VersionHelpers.h>
34# if !defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
35# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
40#define __STDC_FORMAT_MACROS
50#define STREQ(a, b) (strcmp(a, b) == 0)
51#define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
54# define PATHSEP_CHAR '\\'
56# define PATHSEP_CHAR '/'
74#ifdef WITH_CLOG_PTHREADS
75 pthread_mutex_t types_lock;
111#define CLOG_BUF_LEN_INIT 512
122 cstr->
data = buf_stack;
160 char *str_dst = cstr->
data + cstr->
len;
161 memcpy(str_dst,
str,
len);
165 cstr->
len = len_next;
177 const uint len_max = 65535;
178 uint len_avail = cstr->len_alloc - cstr->len;
181 va_copy(args_cpy, args);
182 int retval = vsnprintf(cstr->data + cstr->len, len_avail,
format, args_cpy);
191 if ((
uint)retval <= len_avail) {
193 cstr->len += (
uint)retval;
206 len_avail = cstr->len_alloc - cstr->len;
224#define COLOR_LEN (COLOR_RESET + 1)
228static DWORD clg_previous_console_mode = 0;
259 return "INVALID_SEVERITY";
300 const size_t identifier_len = strlen(identifier);
303 while (flt != NULL) {
304 const size_t len = strlen(flt->
match);
310 memcpy(match, flt->
match + 1,
len - 2);
311 const bool success = (strstr(identifier, match) != NULL);
337 if (
STREQ(identifier, ty->identifier)) {
389 tick = GetTickCount64();
392 gettimeofday(&tv, NULL);
393 tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
406 char timestamp_str[64];
408 const uint timestamp_len = snprintf(timestamp_str,
409 sizeof(timestamp_str),
412 (
uint)(timestamp % 1000));
438 const char *file_line,
440 const bool use_basename)
442 uint file_line_len = strlen(file_line);
444 uint file_line_offset = file_line_len;
445 while (file_line_offset-- > 0) {
451 file_line += file_line_offset;
452 file_line_len -= file_line_offset;
463 const char *file_line,
469 clg_str_init(&cstr, cstr_stack_buf,
sizeof(cstr_stack_buf));
501 const char *file_line,
508 clg_str_init(&cstr, cstr_stack_buf,
sizeof(cstr_stack_buf));
556#if defined(__unix__) || defined(__APPLE__)
566 GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &clg_previous_console_mode);
569 if (IsWindows10OrGreater() && isatty(ctx->
output)) {
570 DWORD mode = clg_previous_console_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
571 if (SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode)) {
609 const char *type_match,
612 if (type_match_len == 0) {
616 flt->
next = *flt_list;
618 memcpy(flt->
match, type_match, type_match_len);
623 const char *type_match,
630 const char *type_match,
647#ifdef WITH_CLOG_PTHREADS
648 pthread_mutex_init(&ctx->types_lock, NULL);
659 SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), clg_previous_console_mode);
661 while (ctx->
types != NULL) {
667 while (ctx->
refs != NULL) {
680#ifdef WITH_CLOG_PTHREADS
681 pthread_mutex_destroy(&ctx->types_lock);
764#ifdef WITH_CLOG_PTHREADS
766 pthread_mutex_lock(&
g_ctx->types_lock);
768 if (clg_ref->
type == NULL) {
771 g_ctx->refs = clg_ref;
774 if (clg_ty == NULL) {
777#ifdef WITH_CLOG_PTHREADS
780 clg_ref->
type = clg_ty;
783#ifdef WITH_CLOG_PTHREADS
784 pthread_mutex_unlock(&
g_ctx->types_lock);
790 if (clg_ref->
type == NULL) {
#define ATTR_PRINTF_FORMAT(format_param, dots_param)
#define STREQLEN(a, b, n)
Read Guarded memory(de)allocation.
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE void * atomic_cas_ptr(void **v, void *old, void *_new)
BMesh const char void * data
unsigned long long int uint64_t
static void CLG_ctx_output_set(CLogContext *ctx, void *file_handle)
static void write_type(CLogStringBuf *cstr, const CLG_LogType *lg)
void CLG_logf(const CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *format,...)
void CLG_type_filter_exclude(const char *type_match, int type_match_len)
static void clg_str_vappendf(CLogStringBuf *cstr, const char *format, va_list args)
static void clg_ctx_fatal_action(CLogContext *ctx)
void CLG_output_set(void *file_handle)
static void CLG_ctx_free(CLogContext *ctx)
void CLG_output_use_basename_set(int value)
void CLG_log_str(const CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *message)
void CLG_error_fn_set(void(*error_fn)(void *file_handle))
static void clg_ctx_error_action(CLogContext *ctx)
static CLG_LogType * clg_ctx_type_find_by_name(CLogContext *ctx, const char *identifier)
void CLG_backtrace_fn_set(void(*fatal_fn)(void *file_handle))
static void CLG_ctx_output_use_timestamp_set(CLogContext *ctx, int value)
static uint64_t clg_timestamp_ticks_get(void)
static void clg_str_append_with_len(CLogStringBuf *cstr, const char *str, const uint len)
static void write_timestamp(CLogStringBuf *cstr, const uint64_t timestamp_tick_start)
#define CLOG_BUF_LEN_INIT
#define STREQLEN(a, b, n)
void CLG_fatal_fn_set(void(*fatal_fn)(void *file_handle))
static void clg_str_append(CLogStringBuf *cstr, const char *str)
static const char * clg_color_table[COLOR_LEN]
static void CLG_ctx_fatal_fn_set(CLogContext *ctx, void(*fatal_fn)(void *file_handle))
void CLG_type_filter_include(const char *type_match, int type_match_len)
void CLG_logref_init(CLG_LogRef *clg_ref)
static void clg_ctx_type_filter_append(CLG_IDFilter **flt_list, const char *type_match, int type_match_len)
void CLG_level_set(int level)
static struct CLogContext * g_ctx
static CLogContext * CLG_ctx_init(void)
static void clg_str_free(CLogStringBuf *cstr)
void CLG_output_use_timestamp_set(int value)
static void CLG_ctx_output_use_basename_set(CLogContext *ctx, int value)
static CLG_LogType * clg_ctx_type_register(CLogContext *ctx, const char *identifier)
static void clg_str_init(CLogStringBuf *cstr, char *buf_stack, uint buf_stack_len)
static void clg_ctx_backtrace(CLogContext *ctx)
static void CLG_ctx_backtrace_fn_set(CLogContext *ctx, void(*backtrace_fn)(void *file_handle))
static const char * clg_severity_str[CLG_SEVERITY_LEN]
static void clg_str_reserve(CLogStringBuf *cstr, const uint len)
static void CLG_ctx_type_filter_exclude(CLogContext *ctx, const char *type_match, int type_match_len)
static const char * clg_severity_as_text(enum CLG_Severity severity)
static void clg_color_table_init(bool use_color)
static void CLG_ctx_level_set(CLogContext *ctx, int level)
int CLG_color_support_get(CLG_LogRef *clg_ref)
static bool clg_ctx_filter_check(CLogContext *ctx, const char *identifier)
static void CLG_ctx_type_filter_include(CLogContext *ctx, const char *type_match, int type_match_len)
static enum eCLogColor clg_severity_to_color(enum CLG_Severity severity)
static void write_severity(CLogStringBuf *cstr, enum CLG_Severity severity, bool use_color)
static void CLT_ctx_error_fn_set(CLogContext *ctx, void(*error_fn)(void *file_handle))
static void write_file_line_fn(CLogStringBuf *cstr, const char *file_line, const char *fn, const bool use_basename)
#define assert(assertion)
#define MEM_reallocN(vmemh, len)
void * MEM_mallocN(size_t len, const char *str)
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
struct CLG_IDFilter * next
struct CLG_LogType * next
struct CLogContext::@246224340010331323005236212212211341376223242052 callbacks
struct CLogContext::@334264147007374306314202062007155123333325067225 default_type
void(* fatal_fn)(void *file_handle)
void(* error_fn)(void *file_handle)
uint64_t timestamp_tick_start
void(* backtrace_fn)(void *file_handle)
CLG_IDFilter * filters[2]