Changeset View
Changeset View
Standalone View
Standalone View
intern/clog/clog.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | #endif | ||||
| uint64_t timestamp_tick_start; | uint64_t timestamp_tick_start; | ||||
| /** For new types. */ | /** For new types. */ | ||||
| struct { | struct { | ||||
| int level; | int level; | ||||
| } default_type; | } default_type; | ||||
| struct { | struct { | ||||
| void (*error_fn)(void *file_handle); | |||||
| void (*fatal_fn)(void *file_handle); | void (*fatal_fn)(void *file_handle); | ||||
| void (*backtrace_fn)(void *file_handle); | void (*backtrace_fn)(void *file_handle); | ||||
| } callbacks; | } callbacks; | ||||
| } CLogContext; | } CLogContext; | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | static CLG_LogType *clg_ctx_type_register(CLogContext *ctx, const char *identifier) | ||||
| ty->level = ctx->default_type.level; | ty->level = ctx->default_type.level; | ||||
| if (clg_ctx_filter_check(ctx, ty->identifier)) { | if (clg_ctx_filter_check(ctx, ty->identifier)) { | ||||
| ty->flag |= CLG_FLAG_USE; | ty->flag |= CLG_FLAG_USE; | ||||
| } | } | ||||
| return ty; | return ty; | ||||
| } | } | ||||
| static void clg_ctx_error_action(CLogContext *ctx) | |||||
| { | |||||
| if (ctx->callbacks.error_fn != NULL) { | |||||
| ctx->callbacks.error_fn(ctx->output_file); | |||||
| } | |||||
| } | |||||
| static void clg_ctx_fatal_action(CLogContext *ctx) | static void clg_ctx_fatal_action(CLogContext *ctx) | ||||
| { | { | ||||
| if (ctx->callbacks.fatal_fn != NULL) { | if (ctx->callbacks.fatal_fn != NULL) { | ||||
| ctx->callbacks.fatal_fn(ctx->output_file); | ctx->callbacks.fatal_fn(ctx->output_file); | ||||
| } | } | ||||
| fflush(ctx->output_file); | fflush(ctx->output_file); | ||||
| abort(); | abort(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | void CLG_logf(CLG_LogType *lg, | ||||
| (void)bytes_written; | (void)bytes_written; | ||||
| clg_str_free(&cstr); | clg_str_free(&cstr); | ||||
| if (lg->ctx->callbacks.backtrace_fn) { | if (lg->ctx->callbacks.backtrace_fn) { | ||||
| clg_ctx_backtrace(lg->ctx); | clg_ctx_backtrace(lg->ctx); | ||||
| } | } | ||||
| if (severity == CLG_SEVERITY_ERROR) { | |||||
| clg_ctx_error_action(lg->ctx); | |||||
| } | |||||
| if (severity == CLG_SEVERITY_FATAL) { | if (severity == CLG_SEVERITY_FATAL) { | ||||
| clg_ctx_fatal_action(lg->ctx); | clg_ctx_fatal_action(lg->ctx); | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| Show All 17 Lines | |||||
| static void CLG_ctx_output_use_timestamp_set(CLogContext *ctx, int value) | static void CLG_ctx_output_use_timestamp_set(CLogContext *ctx, int value) | ||||
| { | { | ||||
| ctx->use_timestamp = (bool)value; | ctx->use_timestamp = (bool)value; | ||||
| if (ctx->use_timestamp) { | if (ctx->use_timestamp) { | ||||
| ctx->timestamp_tick_start = clg_timestamp_ticks_get(); | ctx->timestamp_tick_start = clg_timestamp_ticks_get(); | ||||
| } | } | ||||
| } | } | ||||
| /** Action on error severity. */ | |||||
| static void CLT_ctx_error_fn_set(CLogContext *ctx, void (*error_fn)(void *file_handle)) | |||||
| { | |||||
| ctx->callbacks.error_fn = error_fn; | |||||
| } | |||||
| /** Action on fatal severity. */ | /** Action on fatal severity. */ | ||||
| static void CLG_ctx_fatal_fn_set(CLogContext *ctx, void (*fatal_fn)(void *file_handle)) | static void CLG_ctx_fatal_fn_set(CLogContext *ctx, void (*fatal_fn)(void *file_handle)) | ||||
| { | { | ||||
| ctx->callbacks.fatal_fn = fatal_fn; | ctx->callbacks.fatal_fn = fatal_fn; | ||||
| } | } | ||||
| static void CLG_ctx_backtrace_fn_set(CLogContext *ctx, void (*backtrace_fn)(void *file_handle)) | static void CLG_ctx_backtrace_fn_set(CLogContext *ctx, void (*backtrace_fn)(void *file_handle)) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | void CLG_output_use_basename_set(int value) | ||||
| CLG_ctx_output_use_basename_set(g_ctx, value); | CLG_ctx_output_use_basename_set(g_ctx, value); | ||||
| } | } | ||||
| void CLG_output_use_timestamp_set(int value) | void CLG_output_use_timestamp_set(int value) | ||||
| { | { | ||||
| CLG_ctx_output_use_timestamp_set(g_ctx, value); | CLG_ctx_output_use_timestamp_set(g_ctx, value); | ||||
| } | } | ||||
| void CLG_error_fn_set(void (*error_fn)(void *file_handle)) | |||||
| { | |||||
| CLT_ctx_error_fn_set(g_ctx, error_fn); | |||||
| } | |||||
| void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle)) | void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle)) | ||||
| { | { | ||||
| CLG_ctx_fatal_fn_set(g_ctx, fatal_fn); | CLG_ctx_fatal_fn_set(g_ctx, fatal_fn); | ||||
| } | } | ||||
| void CLG_backtrace_fn_set(void (*fatal_fn)(void *file_handle)) | void CLG_backtrace_fn_set(void (*fatal_fn)(void *file_handle)) | ||||
| { | { | ||||
| CLG_ctx_backtrace_fn_set(g_ctx, fatal_fn); | CLG_ctx_backtrace_fn_set(g_ctx, fatal_fn); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines | |||||