Flecs v4.1
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__)
 Base logging function.
 
#define ecs_printv(level, fmt, args)    ecs_printv_(level, __FILE__, __LINE__, fmt, args)
 Base logging function with va_list.
 
#define ecs_log(level, ...)    ecs_log_(level, __FILE__, __LINE__, __VA_ARGS__)
 Log at the provided level.
 
#define ecs_logv(level, fmt, args)    ecs_logv_(level, __FILE__, __LINE__, fmt, args)
 Log at the provided level with va_list.
 
#define ecs_trace_(file, line, ...)   ecs_log_(0, file, line, __VA_ARGS__)
 Tracing.
 
#define ecs_trace(...)   ecs_trace_(__FILE__, __LINE__, __VA_ARGS__)
 Tracing macro.
 
#define ecs_warn_(file, line, ...)   ecs_log_(-2, file, line, __VA_ARGS__)
 Warning.
 
#define ecs_warn(...)   ecs_warn_(__FILE__, __LINE__, __VA_ARGS__)
 Warning macro.
 
#define ecs_err_(file, line, ...)   ecs_log_(-3, file, line, __VA_ARGS__)
 Error.
 
#define ecs_err(...)   ecs_err_(__FILE__, __LINE__, __VA_ARGS__)
 Error macro.
 
#define ecs_fatal_(file, line, ...)   ecs_log_(-4, file, line, __VA_ARGS__)
 Fatal.
 
#define ecs_fatal(...)   ecs_fatal_(__FILE__, __LINE__, __VA_ARGS__)
 Fatal macro.
 
#define ecs_deprecated(...)    ecs_deprecated_(__FILE__, __LINE__, __VA_ARGS__)
 Optionally include warnings about using deprecated features.
 
#define FLECS_LOG_3   /* Enable all tracing in debug mode. May slow things down */
 
#define ecs_dbg_1(...)   ecs_log(1, __VA_ARGS__);
 Debug trace at level 1.
 
#define ecs_dbg_2(...)   ecs_log(2, __VA_ARGS__);
 Debug trace at level 2.
 
#define ecs_dbg_3(...)   ecs_log(3, __VA_ARGS__);
 Debug trace at level 3.
 
#define ecs_log_push_1()   ecs_log_push_(1);
 Push log indentation at level 1.
 
#define ecs_log_push_2()   ecs_log_push_(2);
 Push log indentation at level 2.
 
#define ecs_log_push_3()   ecs_log_push_(3);
 Push log indentation at level 3.
 
#define ecs_log_pop_1()   ecs_log_pop_(1);
 Pop log indentation at level 1.
 
#define ecs_log_pop_2()   ecs_log_pop_(2);
 Pop log indentation at level 2.
 
#define ecs_log_pop_3()   ecs_log_pop_(3);
 Pop log indentation at level 3.
 
#define ecs_should_log_1()   ecs_should_log(1)
 Test if level 1 logging is enabled.
 
#define ecs_should_log_2()   ecs_should_log(2)
 Test if level 2 logging is enabled.
 
#define ecs_should_log_3()   ecs_should_log(3)
 Test if level 3 logging is enabled.
 
#define FLECS_LOG_2
 
#define FLECS_LOG_1
 
#define FLECS_LOG_0
 
#define ecs_dbg   ecs_dbg_1
 Default debug tracing is at level 1.
 
#define ecs_log_push()   ecs_log_push_(0)
 Push log indentation at the default level.
 
#define ecs_log_pop()   ecs_log_pop_(0)
 Pop log indentation at the default level.
 
#define ecs_abort(error_code, ...)
 Abort.
 
#define ecs_assert(condition, error_code, ...)
 Assert.
 
#define ecs_dbg_assert(condition, error_code, ...)   ecs_assert(condition, error_code, __VA_ARGS__)
 Debug assert.
 
#define ecs_always_assert(condition, error_code, ...)
 Always assert.
 
#define ecs_san_assert(condition, error_code, ...)
 Sanitize assert.
 
#define ecs_dummy_check
 Silence dead code/unused label warnings when compiling without checks.
 
#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)
 Parser error with va_list.
 
#define ecs_parser_warning(name, expr, column, ...)    ecs_parser_warning_(name, expr, column, __VA_ARGS__)
 Parser warning.
 
#define ecs_parser_warningv(name, expr, column, fmt, args)    ecs_parser_warningv_(name, expr, column, fmt, args)
 Parser warning with va_list.
 
#define ECS_INVALID_OPERATION   (1)
 Invalid operation error code.
 
#define ECS_INVALID_PARAMETER   (2)
 Invalid parameter error code.
 
#define ECS_CONSTRAINT_VIOLATED   (3)
 Constraint violated error code.
 
#define ECS_OUT_OF_MEMORY   (4)
 Out of memory error code.
 
#define ECS_OUT_OF_RANGE   (5)
 Out of range error code.
 
#define ECS_UNSUPPORTED   (6)
 Unsupported error code.
 
#define ECS_INTERNAL_ERROR   (7)
 Internal error code.
 
#define ECS_ALREADY_DEFINED   (8)
 Already defined error code.
 
#define ECS_MISSING_OS_API   (9)
 Missing OS API error code.
 
#define ECS_OPERATION_FAILED   (10)
 Operation failed error code.
 
#define ECS_INVALID_CONVERSION   (11)
 Invalid conversion error code.
 
#define ECS_CYCLE_DETECTED   (13)
 Cycle detected error code.
 
#define ECS_LEAK_DETECTED   (14)
 Leak detected error code.
 
#define ECS_DOUBLE_FREE   (15)
 Double free error code.
 
#define ECS_INCONSISTENT_NAME   (20)
 Inconsistent name error code.
 
#define ECS_NAME_IN_USE   (21)
 Name in use error code.
 
#define ECS_INVALID_COMPONENT_SIZE   (23)
 Invalid component size error code.
 
#define ECS_INVALID_COMPONENT_ALIGNMENT   (24)
 Invalid component alignment error code.
 
#define ECS_COMPONENT_NOT_REGISTERED   (25)
 Component not registered error code.
 
#define ECS_INCONSISTENT_COMPONENT_ID   (26)
 Inconsistent component id error code.
 
#define ECS_INCONSISTENT_COMPONENT_ACTION   (27)
 Inconsistent component action error code.
 
#define ECS_MODULE_UNDEFINED   (28)
 Module undefined error code.
 
#define ECS_MISSING_SYMBOL   (29)
 Missing symbol error code.
 
#define ECS_ALREADY_IN_USE   (30)
 Already in use error code.
 
#define ECS_ACCESS_VIOLATION   (40)
 Access violation error code.
 
#define ECS_COLUMN_INDEX_OUT_OF_RANGE   (41)
 Column index out of range error code.
 
#define ECS_COLUMN_IS_NOT_SHARED   (42)
 Column is not shared error code.
 
#define ECS_COLUMN_IS_SHARED   (43)
 Column is shared error code.
 
#define ECS_COLUMN_TYPE_MISMATCH   (45)
 Column type mismatch error code.
 
#define ECS_INVALID_WHILE_READONLY   (70)
 Invalid while readonly error code.
 
#define ECS_LOCKED_STORAGE   (71)
 Locked storage error code.
 
#define ECS_INVALID_FROM_WORKER   (72)
 Invalid from worker error code.
 
#define ECS_BLACK   "\033[1;30m"
 Black ANSI color escape code.
 
#define ECS_RED   "\033[0;31m"
 Red ANSI color escape code.
 
#define ECS_GREEN   "\033[0;32m"
 Green ANSI color escape code.
 
#define ECS_YELLOW   "\033[0;33m"
 Yellow ANSI color escape code.
 
#define ECS_BLUE   "\033[0;34m"
 Blue ANSI color escape code.
 
#define ECS_MAGENTA   "\033[0;35m"
 Magenta ANSI color escape code.
 
#define ECS_CYAN   "\033[0;36m"
 Cyan ANSI color escape code.
 
#define ECS_WHITE   "\033[1;37m"
 White ANSI color escape code.
 
#define ECS_GREY   "\033[0;37m"
 Grey ANSI color escape code.
 
#define ECS_NORMAL   "\033[0;49m"
 Normal ANSI color escape code.
 
#define ECS_BOLD   "\033[1;49m"
 Bold ANSI escape code.
 

Functions

FLECS_API void ecs_deprecated_ (const char *file, int32_t line, const char *msg)
 Log message indicating an operation is deprecated.
 
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,...)
 Print at the provided log level.
 
FLECS_API void ecs_printv_ (int level, const char *file, int32_t line, const char *fmt, va_list args)
 Print at the provided log level (va_list).
 
FLECS_API void ecs_log_ (int32_t level, const char *file, int32_t line, const char *fmt,...)
 Log at the provided level.
 
FLECS_API void ecs_logv_ (int level, const char *file, int32_t line, const char *fmt, va_list args)
 Log at the provided level (va_list).
 
FLECS_API void ecs_abort_ (int32_t error_code, const char *file, int32_t line, const char *fmt,...)
 Abort with error code.
 
FLECS_API void ecs_assert_log_ (int32_t error_code, const char *condition_str, const char *file, int32_t line, const char *fmt,...)
 Log an assertion failure.
 
FLECS_API void ecs_parser_error_ (const char *name, const char *expr, int64_t column, const char *fmt,...)
 Log a parser error.
 
FLECS_API void ecs_parser_errorv_ (const char *name, const char *expr, int64_t column, const char *fmt, va_list args)
 Log a parser error (va_list).
 
FLECS_API void ecs_parser_warning_ (const char *name, const char *expr, int64_t column, const char *fmt,...)
 Log a parser warning.
 
FLECS_API void ecs_parser_warningv_ (const char *name, const char *expr, int64_t column, const char *fmt, va_list args)
 Log a parser warning (va_list).
 
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.
 
FLECS_API void ecs_log_start_capture (bool capture_try)
 Start capturing log output.
 
FLECS_API char * ecs_log_stop_capture (void)
 Stop capturing log output.
 

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 the 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 for 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 and 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.