Blender V5.3
clog.cc File Reference
#include <cassert>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <mutex>
#include <set>
#include <cinttypes>
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "CLG_log.h"

Go to the source code of this file.

Classes

struct  CLG_IDFilter
struct  CLogContext
struct  CLogStringBuf

Macros

#define __STDC_FORMAT_MACROS
#define STREQ(a, b)
#define STREQLEN(a, b, n)
#define PATHSEP_CHAR   '/'

Functions

Global LogRef Single Linked List
static CLG_LogRef ** clg_all_refs_p ()
Context Type Access
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 CLG_LogType * clg_ctx_type_register (CLogContext *ctx, const char *identifier)
static void clg_ctx_error_action (CLogContext *ctx)
static void clg_ctx_fatal_action (CLogContext *ctx)
static void clg_ctx_backtrace (CLogContext *ctx)
static uint64_t clg_timestamp_ticks_get ()
Logging API
static void write_timestamp (CLogStringBuf *cstr, const uint64_t timestamp_tick_start)
static void write_memory (CLogStringBuf *cstr)
static void write_level (CLogStringBuf *cstr, enum CLG_Level level, bool use_color)
static void write_type (CLogStringBuf *cstr, const CLG_LogType *lg)
static void write_file_line_fn (CLogStringBuf *cstr, const char *file_line, const char *fn, const bool use_basename, const bool use_color)
void CLG_log_str (const CLG_LogType *lg, enum CLG_Level level, const char *file_line, const char *fn, const char *message)
void CLG_logf (const CLG_LogType *lg, enum CLG_Level level, const char *file_line, const char *fn, const char *format,...)
void CLG_log_raw (const CLG_LogType *lg, const char *message)
Logging Context API
static void CLG_ctx_output_set (CLogContext *ctx, void *file_handle)
static void CLG_ctx_output_use_source_set (CLogContext *ctx, int value)
static void CLG_ctx_output_use_basename_set (CLogContext *ctx, int value)
static void CLG_ctx_output_use_timestamp_set (CLogContext *ctx, int value)
static void CLG_ctx_output_use_memory_set (CLogContext *ctx, int value)
static void CLT_ctx_error_fn_set (CLogContext *ctx, void(*error_fn)(void *file_handle))
static void CLG_ctx_fatal_fn_set (CLogContext *ctx, void(*fatal_fn)(void *file_handle))
static void CLG_ctx_backtrace_fn_set (CLogContext *ctx, void(*backtrace_fn)(void *file_handle))
static void clg_ctx_type_filter_append (CLG_IDFilter **flt_list, const char *type_match, int type_match_len)
static void CLG_ctx_type_filter_exclude (CLogContext *ctx, const char *type_match, int type_match_len)
static void CLG_ctx_type_filter_include (CLogContext *ctx, const char *type_match, int type_match_len)
static void CLG_ctx_level_set (CLogContext *ctx, CLG_Level level)
static CLogContext * CLG_ctx_init ()
static void CLG_ctx_free (CLogContext *ctx)
Logging Reference API

Use to avoid look-ups each time.

void CLG_logref_register (CLG_LogRef *clg_ref)
void CLG_logref_list_all (void(*callback)(const char *identifier, void *user_data), void *user_data)
void CLG_logref_init (CLG_LogRef *clg_ref)
int CLG_color_support_get (CLG_LogRef *clg_ref)

Variables

Internal Types
static std::mutex LOG_MUTEX

Mini Buffer Functionality

Use so we can do a single call to write.

#define CLOG_BUF_LEN_INIT   512
static void clg_str_init (CLogStringBuf *cstr, char *buf_stack, uint buf_stack_len)
static void clg_str_free (CLogStringBuf *cstr)
static void clg_str_reserve (CLogStringBuf *cstr, const uint len)
static void clg_str_append_with_len (CLogStringBuf *cstr, const char *str, const uint len)
static void clg_str_append (CLogStringBuf *cstr, const char *str)
static void clg_str_append_char (CLogStringBuf *cstr, const char c, const uint len)
static void clg_str_vappendf (CLogStringBuf *cstr, const char *format, va_list args)
static void clg_str_indent_multiline (CLogStringBuf *cstr, const uint indent_len)

Internal Utilities

#define COLOR_LEN   (COLOR_RESET + 1)
enum  eCLogColor {
  COLOR_DEFAULT , COLOR_RED , COLOR_GREEN , COLOR_YELLOW ,
  COLOR_DIM , COLOR_RESET
}
static const char * clg_color_table [COLOR_LEN] = {nullptr}
static void clg_color_table_init (bool use_color)
static const char * clg_level_as_text (enum CLG_Level level)
static enum eCLogColor clg_level_to_color (enum CLG_Level level)

Public Logging API

Currently uses global context.

static struct CLogContext * g_ctx = nullptr
static bool g_quiet = false
void CLG_init ()
void CLG_exit ()
void CLG_output_set (void *file_handle)
void CLG_output_use_source_set (int value)
void CLG_output_use_basename_set (int value)
void CLG_output_use_timestamp_set (int value)
void CLG_output_use_memory_set (int value)
void CLG_error_fn_set (void(*error_fn)(void *file_handle))
void CLG_fatal_fn_set (void(*fatal_fn)(void *file_handle))
void CLG_backtrace_fn_set (void(*fatal_fn)(void *file_handle))
void CLG_type_filter_exclude (const char *type_match, int type_match_len)
void CLG_type_filter_include (const char *type_match, int type_match_len)
void CLG_level_set (CLG_Level level)
void CLG_quiet_set (bool quiet)
bool CLG_quiet_get ()

Macro Definition Documentation

◆ __STDC_FORMAT_MACROS

#define __STDC_FORMAT_MACROS

Definition at line 43 of file clog.cc.

◆ CLOG_BUF_LEN_INIT

#define CLOG_BUF_LEN_INIT   512

Definition at line 132 of file clog.cc.

Referenced by CLG_log_str(), and CLG_logf().

◆ COLOR_LEN

#define COLOR_LEN   (COLOR_RESET + 1)

Definition at line 296 of file clog.cc.

Referenced by clg_color_table_init().

◆ PATHSEP_CHAR

#define PATHSEP_CHAR   '/'

Definition at line 61 of file clog.cc.

◆ STREQ

#define STREQ ( a,
b )
Value:
(strcmp(a, b) == 0)

Definition at line 55 of file clog.cc.

◆ STREQLEN

#define STREQLEN ( a,
b,
n )
Value:
(strncmp(a, b, n) == 0)

Definition at line 56 of file clog.cc.

Enumeration Type Documentation

◆ eCLogColor

enum eCLogColor
Enumerator
COLOR_DEFAULT 
COLOR_RED 
COLOR_GREEN 
COLOR_YELLOW 
COLOR_DIM 
COLOR_RESET 

Definition at line 287 of file clog.cc.

Function Documentation

◆ clg_all_refs_p()

CLG_LogRef ** clg_all_refs_p ( )
static

Definition at line 116 of file clog.cc.

References clg_all_refs_p().

Referenced by clg_all_refs_p(), CLG_ctx_free(), CLG_logref_list_all(), and CLG_logref_register().

◆ CLG_backtrace_fn_set()

void CLG_backtrace_fn_set ( void(* fatal_fn )(void *file_handle))

◆ CLG_color_support_get()

◆ clg_color_table_init()

void clg_color_table_init ( bool use_color)
static

◆ clg_ctx_backtrace()

void clg_ctx_backtrace ( CLogContext * ctx)
static

◆ CLG_ctx_backtrace_fn_set()

void CLG_ctx_backtrace_fn_set ( CLogContext * ctx,
void(* backtrace_fn )(void *file_handle) )
static

Definition at line 771 of file clog.cc.

References CLogContext::callbacks, and CLG_ctx_backtrace_fn_set().

Referenced by CLG_backtrace_fn_set(), and CLG_ctx_backtrace_fn_set().

◆ clg_ctx_error_action()

void clg_ctx_error_action ( CLogContext * ctx)
static

Definition at line 444 of file clog.cc.

References CLogContext::callbacks, clg_ctx_error_action(), and CLogContext::output_file.

Referenced by clg_ctx_error_action(), and CLG_logf().

◆ clg_ctx_fatal_action()

void clg_ctx_fatal_action ( CLogContext * ctx)
static

◆ CLG_ctx_fatal_fn_set()

void CLG_ctx_fatal_fn_set ( CLogContext * ctx,
void(* fatal_fn )(void *file_handle) )
static

Action on fatal level.

Definition at line 766 of file clog.cc.

References CLogContext::callbacks, and CLG_ctx_fatal_fn_set().

Referenced by CLG_ctx_fatal_fn_set(), and CLG_fatal_fn_set().

◆ clg_ctx_filter_check()

bool clg_ctx_filter_check ( CLogContext * ctx,
const char * identifier )
static

Filter the identifier based on very basic globbing.

  • foo matches everything starting with foo.
  • *bar* match for foo.bar & baz.bar & foo.barbaz
  • * matches everything.

Definition at line 368 of file clog.cc.

References clg_ctx_filter_check(), CLG_LEVEL_INFO, CLogContext::default_type, CLogContext::filters, len(), CLG_IDFilter::match, MEM_new_array_zeroed(), CLG_IDFilter::next, STREQ, and STREQLEN.

Referenced by clg_ctx_filter_check(), and clg_ctx_type_register().

◆ CLG_ctx_free()

void CLG_ctx_free ( CLogContext * ctx)
static

◆ CLG_ctx_init()

CLogContext * CLG_ctx_init ( )
static

◆ CLG_ctx_level_set()

void CLG_ctx_level_set ( CLogContext * ctx,
CLG_Level level )
static

◆ CLG_ctx_output_set()

void CLG_ctx_output_set ( CLogContext * ctx,
void * file_handle )
static

◆ CLG_ctx_output_use_basename_set()

void CLG_ctx_output_use_basename_set ( CLogContext * ctx,
int value )
static

◆ CLG_ctx_output_use_memory_set()

void CLG_ctx_output_use_memory_set ( CLogContext * ctx,
int value )
static

◆ CLG_ctx_output_use_source_set()

void CLG_ctx_output_use_source_set ( CLogContext * ctx,
int value )
static

◆ CLG_ctx_output_use_timestamp_set()

void CLG_ctx_output_use_timestamp_set ( CLogContext * ctx,
int value )
static

◆ clg_ctx_type_filter_append()

void clg_ctx_type_filter_append ( CLG_IDFilter ** flt_list,
const char * type_match,
int type_match_len )
static

◆ CLG_ctx_type_filter_exclude()

void CLG_ctx_type_filter_exclude ( CLogContext * ctx,
const char * type_match,
int type_match_len )
static

◆ CLG_ctx_type_filter_include()

void CLG_ctx_type_filter_include ( CLogContext * ctx,
const char * type_match,
int type_match_len )
static

◆ clg_ctx_type_find_by_name()

CLG_LogType * clg_ctx_type_find_by_name ( CLogContext * ctx,
const char * identifier )
static
Note
This should never be called per logging call. Searching is only to get an initial handle.

Definition at line 415 of file clog.cc.

References clg_ctx_type_find_by_name(), CLG_LogType::next, STREQ, and CLogContext::types.

Referenced by clg_ctx_type_find_by_name(), clg_ctx_type_register(), and CLG_logref_init().

◆ clg_ctx_type_register()

◆ CLG_error_fn_set()

void CLG_error_fn_set ( void(* error_fn )(void *file_handle))

◆ CLG_exit()

◆ CLG_fatal_fn_set()

void CLG_fatal_fn_set ( void(* fatal_fn )(void *file_handle))

Definition at line 912 of file clog.cc.

References CLG_ctx_fatal_fn_set(), CLG_fatal_fn_set(), and g_ctx.

Referenced by _CLOG_ATTR_PRINTF_FORMAT(), CLG_fatal_fn_set(), and main().

◆ CLG_init()

◆ clg_level_as_text()

const char * clg_level_as_text ( enum CLG_Level level)
static

◆ CLG_level_set()

void CLG_level_set ( CLG_Level level)

◆ clg_level_to_color()

◆ CLG_log_raw()

◆ CLG_log_str()

◆ CLG_logf()

◆ CLG_logref_init()

◆ CLG_logref_list_all()

void CLG_logref_list_all ( void(* callback )(const char *identifier, void *user_data),
void * user_data )

◆ CLG_logref_register()

void CLG_logref_register ( CLG_LogRef * clg_ref)

◆ CLG_output_set()

void CLG_output_set ( void * file_handle)

◆ CLG_output_use_basename_set()

void CLG_output_use_basename_set ( int value)

◆ CLG_output_use_memory_set()

void CLG_output_use_memory_set ( int value)

◆ CLG_output_use_source_set()

void CLG_output_use_source_set ( int value)

◆ CLG_output_use_timestamp_set()

void CLG_output_use_timestamp_set ( int value)

◆ CLG_quiet_get()

◆ CLG_quiet_set()

◆ clg_str_append()

void clg_str_append ( CLogStringBuf * cstr,
const char * str )
static

◆ clg_str_append_char()

void clg_str_append_char ( CLogStringBuf * cstr,
const char c,
const uint len )
static

◆ clg_str_append_with_len()

void clg_str_append_with_len ( CLogStringBuf * cstr,
const char * str,
const uint len )
static

◆ clg_str_free()

void clg_str_free ( CLogStringBuf * cstr)
static

Definition at line 149 of file clog.cc.

References clg_str_free(), CLogStringBuf::data, and CLogStringBuf::is_alloc.

Referenced by CLG_log_str(), CLG_logf(), and clg_str_free().

◆ clg_str_indent_multiline()

void clg_str_indent_multiline ( CLogStringBuf * cstr,
const uint indent_len )
static

◆ clg_str_init()

void clg_str_init ( CLogStringBuf * cstr,
char * buf_stack,
uint buf_stack_len )
static

◆ clg_str_reserve()

◆ clg_str_vappendf()

void clg_str_vappendf ( CLogStringBuf * cstr,
const char * format,
va_list args )
static

Definition at line 205 of file clog.cc.

References clg_str_reserve(), and clg_str_vappendf().

Referenced by CLG_logf(), and clg_str_vappendf().

◆ clg_timestamp_ticks_get()

uint64_t clg_timestamp_ticks_get ( )
static

◆ CLG_type_filter_exclude()

void CLG_type_filter_exclude ( const char * type_match,
int type_match_len )

◆ CLG_type_filter_include()

◆ CLT_ctx_error_fn_set()

void CLT_ctx_error_fn_set ( CLogContext * ctx,
void(* error_fn )(void *file_handle) )
static

Action on error level.

Definition at line 760 of file clog.cc.

References CLogContext::callbacks, and CLT_ctx_error_fn_set().

Referenced by CLG_error_fn_set(), and CLT_ctx_error_fn_set().

◆ write_file_line_fn()

void write_file_line_fn ( CLogStringBuf * cstr,
const char * file_line,
const char * fn,
const bool use_basename,
const bool use_color )
static

◆ write_level()

void write_level ( CLogStringBuf * cstr,
enum CLG_Level level,
bool use_color )
static

◆ write_memory()

void write_memory ( CLogStringBuf * cstr)
static

◆ write_timestamp()

void write_timestamp ( CLogStringBuf * cstr,
const uint64_t timestamp_tick_start )
static

◆ write_type()

void write_type ( CLogStringBuf * cstr,
const CLG_LogType * lg )
static

Variable Documentation

◆ clg_color_table

const char* clg_color_table[COLOR_LEN] = {nullptr}
static

Definition at line 298 of file clog.cc.

Referenced by clg_color_table_init(), write_file_line_fn(), and write_level().

◆ g_ctx

◆ g_quiet

bool g_quiet = false
static

Definition at line 868 of file clog.cc.

Referenced by CLG_quiet_get(), and CLG_quiet_set().

◆ LOG_MUTEX

std::mutex LOG_MUTEX
static

Definition at line 68 of file clog.cc.

Referenced by CLG_log_str(), and CLG_logf().