16 #ifdef WITH_CLOG_PTHREADS
22 #if defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
23 # include <sys/time.h>
30 # include <VersionHelpers.h>
32 # if !defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
33 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
38 #define __STDC_FORMAT_MACROS
48 #define STREQ(a, b) (strcmp(a, b) == 0)
49 #define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
52 # define PATHSEP_CHAR '\\'
54 # define PATHSEP_CHAR '/'
72 #ifdef WITH_CLOG_PTHREADS
73 pthread_mutex_t types_lock;
109 #define CLOG_BUF_LEN_INIT 512
120 cstr->
data = buf_stack;
158 char *str_dst = cstr->
data + cstr->
len;
159 memcpy(str_dst,
str,
len);
163 cstr->
len = len_next;
175 const uint len_max = 65535;
177 uint len_avail = cstr->len_alloc - cstr->len;
181 int retval = vsnprintf(cstr->data + cstr->len, len_avail, fmt, args_cpy);
189 else if ((
uint)retval <= len_avail) {
191 cstr->len += (
uint)retval;
203 len_avail = cstr->len_alloc - cstr->len;
222 #define COLOR_LEN (COLOR_RESET + 1)
226 static DWORD clg_previous_console_mode = 0;
258 return "INVALID_SEVERITY";
300 const size_t identifier_len = strlen(identifier);
301 for (
uint i = 0; i < 2; i++) {
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);
336 if (
STREQ(identifier, ty->identifier)) {
387 #if defined(_MSC_VER)
388 tick = GetTickCount64();
391 gettimeofday(&tv,
NULL);
392 tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
405 char timestamp_str[64];
408 sizeof(timestamp_str),
411 (
uint)(timestamp % 1000));
437 const char *file_line,
439 const bool use_basename)
441 uint file_line_len = strlen(file_line);
443 uint file_line_offset = file_line_len;
444 while (file_line_offset-- > 0) {
450 file_line += file_line_offset;
451 file_line_len -= file_line_offset;
462 const char *file_line,
468 clg_str_init(&cstr, cstr_stack_buf,
sizeof(cstr_stack_buf));
500 const char *file_line,
507 clg_str_init(&cstr, cstr_stack_buf,
sizeof(cstr_stack_buf));
555 #if defined(__unix__) || defined(__APPLE__)
565 GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &clg_previous_console_mode);
568 if (IsWindows10OrGreater() && isatty(ctx->
output)) {
569 DWORD mode = clg_previous_console_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
570 if (SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode)) {
608 const char *type_match,
611 if (type_match_len == 0) {
615 flt->
next = *flt_list;
617 memcpy(flt->
match, type_match, type_match_len);
622 const char *type_match,
629 const char *type_match,
646 #ifdef WITH_CLOG_PTHREADS
647 pthread_mutex_init(&ctx->types_lock,
NULL);
658 SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), clg_previous_console_mode);
672 for (
uint i = 0; i < 2; i++) {
679 #ifdef WITH_CLOG_PTHREADS
680 pthread_mutex_destroy(&ctx->types_lock);
763 #ifdef WITH_CLOG_PTHREADS
765 pthread_mutex_lock(&
g_ctx->types_lock);
773 if (clg_ty ==
NULL) {
776 #ifdef WITH_CLOG_PTHREADS
779 clg_ref->
type = clg_ty;
782 #ifdef WITH_CLOG_PTHREADS
783 pthread_mutex_unlock(&
g_ctx->types_lock);
size_t ATTR_PRINTF_FORMAT(3, 4)
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
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)
static void CLG_ctx_output_set(CLogContext *ctx, void *file_handle)
void CLG_type_filter_exclude(const char *type_match, int type_match_len)
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_error_fn_set(void(*error_fn)(void *file_handle))
struct CLG_IDFilter CLG_IDFilter
static void clg_ctx_error_action(CLogContext *ctx)
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)
struct CLogContext CLogContext
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 CLG_LogType * clg_ctx_type_register(CLogContext *ctx, const char *identifier)
static CLogContext * CLG_ctx_init(void)
struct CLogStringBuf CLogStringBuf
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 void clg_str_vappendf(CLogStringBuf *cstr, const char *fmt, va_list args)
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)
void CLG_logf(CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *fmt,...)
static void CLG_ctx_type_filter_exclude(CLogContext *ctx, const char *type_match, int type_match_len)
static void write_type(CLogStringBuf *cstr, CLG_LogType *lg)
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)
void CLG_log_str(CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *message)
static bool clg_ctx_filter_check(CLogContext *ctx, const char *identifier)
static CLG_LogType * clg_ctx_type_find_by_name(CLogContext *ctx, const char *identifier)
static void CLG_ctx_type_filter_include(CLogContext *ctx, const char *type_match, int type_match_len)
static const char * clg_severity_as_text(enum CLG_Severity severity)
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)
SyclQueue void void size_t num_bytes void
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
unsigned __int64 uint64_t
struct CLG_IDFilter * next
struct CLG_LogType * next
struct CLogContext::@1224 callbacks
void(* fatal_fn)(void *file_handle)
void(* error_fn)(void *file_handle)
uint64_t timestamp_tick_start
struct CLogContext::@1223 default_type
void(* backtrace_fn)(void *file_handle)
CLG_IDFilter * filters[2]