Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
log.h File Reference

Logging addon. More...

Go to the source code of this file.

Macros

#define ecs_print(level, ...)    ecs_print_(level, __FILE__, __LINE__, __VA_ARGS__)
 
#define ecs_printv(level, fmt, args)    ecs_printv_(level, __FILE__, __LINE__, fmt, args)
 
#define ecs_log(level, ...)    ecs_log_(level, __FILE__, __LINE__, __VA_ARGS__)
 
#define ecs_logv(level, fmt, args)    ecs_logv_(level, __FILE__, __LINE__, fmt, args)
 
#define ecs_trace_(file, line, ...)   ecs_log_(0, file, line, __VA_ARGS__)
 
#define ecs_trace(...)   ecs_trace_(__FILE__, __LINE__, __VA_ARGS__)
 
#define ecs_warn_(file, line, ...)   ecs_log_(-2, file, line, __VA_ARGS__)
 
#define ecs_warn(...)   ecs_warn_(__FILE__, __LINE__, __VA_ARGS__)
 
#define ecs_err_(file, line, ...)   ecs_log_(-3, file, line, __VA_ARGS__)
 
#define ecs_err(...)   ecs_err_(__FILE__, __LINE__, __VA_ARGS__)
 
#define ecs_fatal_(file, line, ...)   ecs_log_(-4, file, line, __VA_ARGS__)
 
#define ecs_fatal(...)   ecs_fatal_(__FILE__, __LINE__, __VA_ARGS__)
 
#define ecs_deprecated(...)    ecs_deprecated_(__FILE__, __LINE__, __VA_ARGS__)
 
#define FLECS_LOG_3   /* Enable all tracing in debug mode. May slow things down */
 
#define ecs_dbg_1(...)   ecs_log(1, __VA_ARGS__);
 
#define ecs_dbg_2(...)   ecs_log(2, __VA_ARGS__);
 
#define ecs_dbg_3(...)   ecs_log(3, __VA_ARGS__);
 
#define ecs_log_push_1()   ecs_log_push_(1);
 
#define ecs_log_push_2()   ecs_log_push_(2);
 
#define ecs_log_push_3()   ecs_log_push_(3);
 
#define ecs_log_pop_1()   ecs_log_pop_(1);
 
#define ecs_log_pop_2()   ecs_log_pop_(2);
 
#define ecs_log_pop_3()   ecs_log_pop_(3);
 
#define ecs_should_log_1()   ecs_should_log(1)
 
#define ecs_should_log_2()   ecs_should_log(2)
 
#define ecs_should_log_3()   ecs_should_log(3)
 
#define FLECS_LOG_2
 
#define FLECS_LOG_1
 
#define FLECS_LOG_0
 
#define ecs_dbg   ecs_dbg_1
 
#define ecs_log_push()   ecs_log_push_(0)
 
#define ecs_log_pop()   ecs_log_pop_(0)
 
#define ecs_abort(error_code, ...)
 Abort.
 
#define ecs_assert(condition, error_code, ...)
 Assert.
 
#define ecs_assert_var(var, error_code, ...)
 
#define ecs_dbg_assert(condition, error_code, ...)   ecs_assert(condition, error_code, __VA_ARGS__)
 Debug assert.
 
#define ecs_san_assert(condition, error_code, ...)
 Sanitize assert.
 
#define ecs_dummy_check
 
#define ecs_check(condition, error_code, ...)
 Check.
 
#define ecs_throw(error_code, ...)
 Panic.
 
#define ecs_parser_error(name, expr, column, ...)    ecs_parser_error_(name, expr, column, __VA_ARGS__)
 Parser error.
 
#define ecs_parser_errorv(name, expr, column, fmt, args)    ecs_parser_errorv_(name, expr, column, fmt, args)
 
#define ECS_INVALID_OPERATION   (1)
 
#define ECS_INVALID_PARAMETER   (2)
 
#define ECS_CONSTRAINT_VIOLATED   (3)
 
#define ECS_OUT_OF_MEMORY   (4)
 
#define ECS_OUT_OF_RANGE   (5)
 
#define ECS_UNSUPPORTED   (6)
 
#define ECS_INTERNAL_ERROR   (7)
 
#define ECS_ALREADY_DEFINED   (8)
 
#define ECS_MISSING_OS_API   (9)
 
#define ECS_OPERATION_FAILED   (10)
 
#define ECS_INVALID_CONVERSION   (11)
 
#define ECS_ID_IN_USE   (12)
 
#define ECS_CYCLE_DETECTED   (13)
 
#define ECS_LEAK_DETECTED   (14)
 
#define ECS_DOUBLE_FREE   (15)
 
#define ECS_INCONSISTENT_NAME   (20)
 
#define ECS_NAME_IN_USE   (21)
 
#define ECS_NOT_A_COMPONENT   (22)
 
#define ECS_INVALID_COMPONENT_SIZE   (23)
 
#define ECS_INVALID_COMPONENT_ALIGNMENT   (24)
 
#define ECS_COMPONENT_NOT_REGISTERED   (25)
 
#define ECS_INCONSISTENT_COMPONENT_ID   (26)
 
#define ECS_INCONSISTENT_COMPONENT_ACTION   (27)
 
#define ECS_MODULE_UNDEFINED   (28)
 
#define ECS_MISSING_SYMBOL   (29)
 
#define ECS_ALREADY_IN_USE   (30)
 
#define ECS_ACCESS_VIOLATION   (40)
 
#define ECS_COLUMN_INDEX_OUT_OF_RANGE   (41)
 
#define ECS_COLUMN_IS_NOT_SHARED   (42)
 
#define ECS_COLUMN_IS_SHARED   (43)
 
#define ECS_COLUMN_TYPE_MISMATCH   (45)
 
#define ECS_INVALID_WHILE_READONLY   (70)
 
#define ECS_LOCKED_STORAGE   (71)
 
#define ECS_INVALID_FROM_WORKER   (72)
 
#define ECS_BLACK   "\033[1;30m"
 
#define ECS_RED   "\033[0;31m"
 
#define ECS_GREEN   "\033[0;32m"
 
#define ECS_YELLOW   "\033[0;33m"
 
#define ECS_BLUE   "\033[0;34m"
 
#define ECS_MAGENTA   "\033[0;35m"
 
#define ECS_CYAN   "\033[0;36m"
 
#define ECS_WHITE   "\033[1;37m"
 
#define ECS_GREY   "\033[0;37m"
 
#define ECS_NORMAL   "\033[0;49m"
 
#define ECS_BOLD   "\033[1;49m"
 

Functions

FLECS_API void ecs_deprecated_ (const char *file, int32_t line, const char *msg)
 
FLECS_API void ecs_log_push_ (int32_t level)
 Increase log stack.
 
FLECS_API void ecs_log_pop_ (int32_t level)
 Decrease log stack.
 
FLECS_API bool ecs_should_log (int32_t level)
 Should current level be logged.
 
FLECS_API const char * ecs_strerror (int32_t error_code)
 Get description for error code.
 
FLECS_API void ecs_print_ (int32_t level, const char *file, int32_t line, const char *fmt,...)
 
FLECS_API void ecs_printv_ (int level, const char *file, int32_t line, const char *fmt, va_list args)
 
FLECS_API void ecs_log_ (int32_t level, const char *file, int32_t line, const char *fmt,...)
 
FLECS_API void ecs_logv_ (int level, const char *file, int32_t line, const char *fmt, va_list args)
 
FLECS_API void ecs_abort_ (int32_t error_code, const char *file, int32_t line, const char *fmt,...)
 
FLECS_API void ecs_assert_log_ (int32_t error_code, const char *condition_str, const char *file, int32_t line, const char *fmt,...)
 
FLECS_API void ecs_parser_error_ (const char *name, const char *expr, int64_t column, const char *fmt,...)
 
FLECS_API void ecs_parser_errorv_ (const char *name, const char *expr, int64_t column, const char *fmt, va_list args)
 
FLECS_API int ecs_log_set_level (int level)
 Enable or disable log.
 
FLECS_API int ecs_log_get_level (void)
 Get current log level.
 
FLECS_API bool ecs_log_enable_colors (bool enabled)
 Enable/disable tracing with colors.
 
FLECS_API bool ecs_log_enable_timestamp (bool enabled)
 Enable/disable logging timestamp.
 
FLECS_API bool ecs_log_enable_timedelta (bool enabled)
 Enable/disable logging time since last log.
 
FLECS_API int ecs_log_last_error (void)
 Get last logged error code.
 

Detailed Description

Logging addon.

The logging addon provides an API for (debug) tracing and reporting errors at various levels. When enabled, the logging addon can provide more detailed information about the state of the ECS and any errors that may occur.

The logging addon can be disabled to reduce footprint of the library, but limits information logged to only file, line and error code.

When enabled the logging addon can be configured to exclude levels of tracing from the build to reduce the impact on performance. By default all debug tracing is enabled for debug builds, tracing is enabled at release builds.

Applications can change the logging level at runtime with ecs_log_set_level(), but what is actually logged depends on what is compiled (when compiled without debug tracing, setting the runtime level to debug won't have an effect).

The logging addon uses the OS API log_ function for all tracing.

Note that even when the logging addon is not enabled, its header/source must be included in a build. To prevent unused variable warnings in the code, some API functions are included when the addon is disabled, but have empty bodies.

Definition in file log.h.