30 #ifdef WITH_CLOG_PTHREADS
36 #if defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
37 # include <sys/time.h>
44 # include <VersionHelpers.h>
46 # if !defined(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
47 # define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
52 #define __STDC_FORMAT_MACROS
62 #define STREQ(a, b) (strcmp(a, b) == 0)
63 #define STREQLEN(a, b, n) (strncmp(a, b, n) == 0)
66 # define PATHSEP_CHAR '\\'
68 # define PATHSEP_CHAR '/'
86 #ifdef WITH_CLOG_PTHREADS
87 pthread_mutex_t types_lock;
123 #define CLOG_BUF_LEN_INIT 512
134 cstr->
data = buf_stack;
172 char *str_dst = cstr->
data + cstr->
len;
173 memcpy(str_dst,
str,
len);
177 cstr->
len = len_next;
189 const uint len_max = 65535;
191 uint len_avail = cstr->len_alloc - cstr->len;
195 int retval = vsnprintf(cstr->data + cstr->len, len_avail, fmt, args_cpy);
203 else if ((
uint)retval <= len_avail) {
205 cstr->len += (
uint)retval;
217 len_avail = cstr->len_alloc - cstr->len;
236 #define COLOR_LEN (COLOR_RESET + 1)
240 static DWORD clg_previous_console_mode = 0;
272 return "INVALID_SEVERITY";
314 const size_t identifier_len = strlen(identifier);
315 for (
uint i = 0; i < 2; i++) {
317 while (flt !=
NULL) {
318 const size_t len = strlen(flt->
match);
324 memcpy(match, flt->
match + 1,
len - 2);
325 if (strstr(identifier, match) !=
NULL) {
348 if (
STREQ(identifier, ty->identifier)) {
399 #if defined(_MSC_VER)
400 tick = GetTickCount64();
403 gettimeofday(&tv,
NULL);
404 tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
417 char timestamp_str[64];
420 sizeof(timestamp_str),
423 (
uint)(timestamp % 1000));
449 const char *file_line,
451 const bool use_basename)
453 uint file_line_len = strlen(file_line);
455 uint file_line_offset = file_line_len;
456 while (file_line_offset-- > 0) {
462 file_line += file_line_offset;
463 file_line_len -= file_line_offset;
474 const char *file_line,
480 clg_str_init(&cstr, cstr_stack_buf,
sizeof(cstr_stack_buf));
512 const char *file_line,
519 clg_str_init(&cstr, cstr_stack_buf,
sizeof(cstr_stack_buf));
567 #if defined(__unix__) || defined(__APPLE__)
577 GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &clg_previous_console_mode);
580 if (IsWindows10OrGreater() && isatty(ctx->
output)) {
581 DWORD mode = clg_previous_console_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
582 if (SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode)) {
620 const char *type_match,
623 if (type_match_len == 0) {
627 flt->
next = *flt_list;
629 memcpy(flt->
match, type_match, type_match_len);
634 const char *type_match,
641 const char *type_match,
658 #ifdef WITH_CLOG_PTHREADS
659 pthread_mutex_init(&ctx->types_lock,
NULL);
670 SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), clg_previous_console_mode);
684 for (
uint i = 0; i < 2; i++) {
691 #ifdef WITH_CLOG_PTHREADS
692 pthread_mutex_destroy(&ctx->types_lock);
775 #ifdef WITH_CLOG_PTHREADS
777 pthread_mutex_lock(&
g_ctx->types_lock);
785 if (clg_ty ==
NULL) {
788 #ifdef WITH_CLOG_PTHREADS
791 clg_ref->
type = clg_ty;
794 #ifdef WITH_CLOG_PTHREADS
795 pthread_mutex_unlock(&
g_ctx->types_lock);
size_t ATTR_PRINTF_FORMAT(3, 4)
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
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)
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
void(* fatal_fn)(void *file_handle)
void(* error_fn)(void *file_handle)
struct CLogContext::@1185 callbacks
uint64_t timestamp_tick_start
struct CLogContext::@1184 default_type
void(* backtrace_fn)(void *file_handle)
CLG_IDFilter * filters[2]