Skip to content
Flecs v4.1
log.h
Go to the documentation of this file.
1/**
2 * @file addons/log.h
3 * @brief Logging addon.
4 *
5 * The logging addon provides an API for (debug) tracing and reporting errors
6 * at various levels. When enabled, the logging addon can provide more detailed
7 * information about the state of the ECS and any errors that may occur.
8 *
9 * The logging addon can be disabled to reduce the footprint of the library, but
10 * limits information logged to only file, line, and error code.
11 *
12 * When enabled, the logging addon can be configured to exclude levels of tracing
13 * from the build to reduce the impact on performance. By default, all debug
14 * tracing is enabled for debug builds, tracing is enabled for release builds.
15 *
16 * Applications can change the logging level at runtime with ecs_log_set_level(),
17 * but what is actually logged depends on what is compiled (when compiled
18 * without debug tracing, setting the runtime level to debug won't have an
19 * effect).
20 *
21 * The logging addon uses the OS API log_() function for all tracing.
22 *
23 * Note that even when the logging addon is not enabled, its header and source must
24 * be included in a build. To prevent unused variable warnings in the code, some
25 * API functions are included when the addon is disabled, but have empty bodies.
26 */
27
28#ifndef FLECS_LOG_H
29#define FLECS_LOG_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#ifdef FLECS_LOG
36
37/**
38 * @defgroup c_addons_log Log
39 * @ingroup c_addons
40 * Logging functions.
41 *
42 * @{
43 */
44
45////////////////////////////////////////////////////////////////////////////////
46//// Tracing
47////////////////////////////////////////////////////////////////////////////////
48
49/** Log message indicating an operation is deprecated.
50 *
51 * @param file The source file.
52 * @param line The source line.
53 * @param msg The deprecation message.
54 */
55FLECS_API
57 const char *file,
58 int32_t line,
59 const char *msg);
60
61/** Increase log stack.
62 * This operation increases the indent_ value of the OS API and can be useful to
63 * make nested behavior more visible.
64 *
65 * @param level The log level.
66 */
67FLECS_API
68void ecs_log_push_(int32_t level);
69
70/** Decrease log stack.
71 * This operation decreases the indent_ value of the OS API and can be useful to
72 * make nested behavior more visible.
73 *
74 * @param level The log level.
75 */
76FLECS_API
77void ecs_log_pop_(int32_t level);
78
79/** Should current level be logged.
80 * This operation returns true when the specified log level should be logged
81 * with the current log level.
82 *
83 * @param level The log level to check for.
84 * @return Whether logging is enabled for the current level.
85 */
86FLECS_API
87bool ecs_should_log(int32_t level);
88
89////////////////////////////////////////////////////////////////////////////////
90//// Error reporting
91////////////////////////////////////////////////////////////////////////////////
92
93/** Get description for error code.
94 *
95 * @param error_code The error code.
96 * @return String describing the error code.
97 */
98FLECS_API
99const char* ecs_strerror(
100 int32_t error_code);
101
102#else // FLECS_LOG
103
104////////////////////////////////////////////////////////////////////////////////
105//// Dummy macros for when logging is disabled
106////////////////////////////////////////////////////////////////////////////////
107
108#define ecs_deprecated_(file, line, msg)\
109 (void)file;\
110 (void)line;\
111 (void)msg
112
113#define ecs_log_push_(level)
114#define ecs_log_pop_(level)
115#define ecs_should_log(level) false
116
117#define ecs_strerror(error_code)\
118 (void)error_code
119
120#endif // FLECS_LOG
121
122
123////////////////////////////////////////////////////////////////////////////////
124//// Logging functions (do nothing when logging is disabled)
125////////////////////////////////////////////////////////////////////////////////
126
127/** Print at the provided log level.
128 *
129 * @param level The log level.
130 * @param file The source file.
131 * @param line The source line.
132 * @param fmt The format string.
133 */
134FLECS_API
136 int32_t level,
137 const char *file,
138 int32_t line,
139 const char *fmt,
140 ...);
141
142/** Print at the provided log level (va_list).
143 *
144 * @param level The log level.
145 * @param file The source file.
146 * @param line The source line.
147 * @param fmt The format string.
148 * @param args The format argument list.
149 */
150FLECS_API
152 int32_t level,
153 const char *file,
154 int32_t line,
155 const char *fmt,
156 va_list args);
157
158/** Log at the provided level.
159 *
160 * @param level The log level.
161 * @param file The source file.
162 * @param line The source line.
163 * @param fmt The format string.
164 */
165FLECS_API
167 int32_t level,
168 const char *file,
169 int32_t line,
170 const char *fmt,
171 ...);
172
173/** Log at the provided level (va_list).
174 *
175 * @param level The log level.
176 * @param file The source file.
177 * @param line The source line.
178 * @param fmt The format string.
179 * @param args The format argument list.
180 */
181FLECS_API
183 int32_t level,
184 const char *file,
185 int32_t line,
186 const char *fmt,
187 va_list args);
188
189/** Abort with error code.
190 *
191 * @param error_code The error code.
192 * @param file The source file.
193 * @param line The source line.
194 * @param fmt The format string.
195 */
196FLECS_API
198 int32_t error_code,
199 const char *file,
200 int32_t line,
201 const char *fmt,
202 ...);
203
204/** Log an assertion failure.
205 *
206 * @param error_code The error code.
207 * @param condition_str The condition that was not met.
208 * @param file The source file.
209 * @param line The source line.
210 * @param fmt The format string.
211 */
212FLECS_API
214 int32_t error_code,
215 const char *condition_str,
216 const char *file,
217 int32_t line,
218 const char *fmt,
219 ...);
220
221/** Log a parser error.
222 *
223 * @param name The name of the expression.
224 * @param expr The expression string.
225 * @param column The column at which the error occurred.
226 * @param fmt The format string.
227 */
228FLECS_API
230 const char *name,
231 const char *expr,
232 int64_t column,
233 const char *fmt,
234 ...);
235
236/** Log a parser error (va_list).
237 *
238 * @param name The name of the expression.
239 * @param expr The expression string.
240 * @param column The column at which the error occurred.
241 * @param fmt The format string.
242 * @param args The format argument list.
243 */
244FLECS_API
246 const char *name,
247 const char *expr,
248 int64_t column,
249 const char *fmt,
250 va_list args);
251
252/** Log a parser warning.
253 *
254 * @param name The name of the expression.
255 * @param expr The expression string.
256 * @param column The column at which the error occurred.
257 * @param fmt The format string.
258 */
259FLECS_API
261 const char *name,
262 const char *expr,
263 int64_t column,
264 const char *fmt,
265 ...);
266
267/** Log a parser warning (va_list).
268 *
269 * @param name The name of the expression.
270 * @param expr The expression string.
271 * @param column The column at which the error occurred.
272 * @param fmt The format string.
273 * @param args The format argument list.
274 */
275FLECS_API
277 const char *name,
278 const char *expr,
279 int64_t column,
280 const char *fmt,
281 va_list args);
282
283
284////////////////////////////////////////////////////////////////////////////////
285//// Logging macros
286////////////////////////////////////////////////////////////////////////////////
287
288#ifndef FLECS_LEGACY /* C89 doesn't support variadic macros */
289
290/** Base logging function. Accepts a custom level. */
291#define ecs_print(level, ...)\
292 ecs_print_(level, __FILE__, __LINE__, __VA_ARGS__)
293
294/** Base logging function with va_list. */
295#define ecs_printv(level, fmt, args)\
296 ecs_printv_(level, __FILE__, __LINE__, fmt, args)
297
298/** Log at the provided level. */
299#define ecs_log(level, ...)\
300 ecs_log_(level, __FILE__, __LINE__, __VA_ARGS__)
301
302/** Log at the provided level with va_list. */
303#define ecs_logv(level, fmt, args)\
304 ecs_logv_(level, __FILE__, __LINE__, fmt, args)
305
306/** Tracing. Used for logging of infrequent events. */
307#define ecs_trace_(file, line, ...) ecs_log_(0, file, line, __VA_ARGS__)
308/** Tracing macro. */
309#define ecs_trace(...) ecs_trace_(__FILE__, __LINE__, __VA_ARGS__)
310
311/** Warning. Used when an issue occurs, but operation is successful. */
312#define ecs_warn_(file, line, ...) ecs_log_(-2, file, line, __VA_ARGS__)
313/** Warning macro. */
314#define ecs_warn(...) ecs_warn_(__FILE__, __LINE__, __VA_ARGS__)
315
316/** Error. Used when an issue occurs, and operation failed. */
317#define ecs_err_(file, line, ...) ecs_log_(-3, file, line, __VA_ARGS__)
318/** Error macro. */
319#define ecs_err(...) ecs_err_(__FILE__, __LINE__, __VA_ARGS__)
320
321/** Fatal. Used when an issue occurs, and the application cannot continue. */
322#define ecs_fatal_(file, line, ...) ecs_log_(-4, file, line, __VA_ARGS__)
323/** Fatal macro. */
324#define ecs_fatal(...) ecs_fatal_(__FILE__, __LINE__, __VA_ARGS__)
325
326/** Optionally include warnings about using deprecated features. */
327#ifndef FLECS_NO_DEPRECATED_WARNINGS
328/** Emit deprecation warning. */
329#define ecs_deprecated(...)\
330 ecs_deprecated_(__FILE__, __LINE__, __VA_ARGS__)
331#else
332#define ecs_deprecated(...)
333#endif // FLECS_NO_DEPRECATED_WARNINGS
334
335/* If no tracing verbosity is defined, pick default based on build config */
336#if !(defined(FLECS_LOG_0) || defined(FLECS_LOG_1) || defined(FLECS_LOG_2) || defined(FLECS_LOG_3))
337#if !defined(FLECS_NDEBUG)
338#define FLECS_LOG_3 /* Enable all tracing in debug mode. May slow things down */
339#else
340#define FLECS_LOG_0 /* Only enable infrequent tracing in release mode */
341#endif // !defined(FLECS_NDEBUG)
342#endif // !(defined(FLECS_LOG_0) || defined(FLECS_LOG_1) || defined(FLECS_LOG_2) || defined(FLECS_LOG_3))
343
344
345/* Define/undefine macros based on compiled-in tracing level. This can optimize
346 * out tracing statements from a build, which improves performance. */
347
348#if defined(FLECS_LOG_3) /* All debug tracing enabled */
349/** Debug trace at level 1. */
350#define ecs_dbg_1(...) ecs_log(1, __VA_ARGS__);
351/** Debug trace at level 2. */
352#define ecs_dbg_2(...) ecs_log(2, __VA_ARGS__);
353/** Debug trace at level 3. */
354#define ecs_dbg_3(...) ecs_log(3, __VA_ARGS__);
355
356/** Push log indentation at level 1. */
357#define ecs_log_push_1() ecs_log_push_(1);
358/** Push log indentation at level 2. */
359#define ecs_log_push_2() ecs_log_push_(2);
360/** Push log indentation at level 3. */
361#define ecs_log_push_3() ecs_log_push_(3);
362
363/** Pop log indentation at level 1. */
364#define ecs_log_pop_1() ecs_log_pop_(1);
365/** Pop log indentation at level 2. */
366#define ecs_log_pop_2() ecs_log_pop_(2);
367/** Pop log indentation at level 3. */
368#define ecs_log_pop_3() ecs_log_pop_(3);
369
370/** Test if level 1 logging is enabled. */
371#define ecs_should_log_1() ecs_should_log(1)
372/** Test if level 2 logging is enabled. */
373#define ecs_should_log_2() ecs_should_log(2)
374/** Test if level 3 logging is enabled. */
375#define ecs_should_log_3() ecs_should_log(3)
376
377#define FLECS_LOG_2
378#define FLECS_LOG_1
379#define FLECS_LOG_0
380
381#elif defined(FLECS_LOG_2) /* Level 2 and below debug tracing enabled */
382#define ecs_dbg_1(...) ecs_log(1, __VA_ARGS__);
383#define ecs_dbg_2(...) ecs_log(2, __VA_ARGS__);
384#define ecs_dbg_3(...)
385
386#define ecs_log_push_1() ecs_log_push_(1);
387#define ecs_log_push_2() ecs_log_push_(2);
388#define ecs_log_push_3()
389
390#define ecs_log_pop_1() ecs_log_pop_(1);
391#define ecs_log_pop_2() ecs_log_pop_(2);
392#define ecs_log_pop_3()
393
394#define ecs_should_log_1() ecs_should_log(1)
395#define ecs_should_log_2() ecs_should_log(2)
396#define ecs_should_log_3() false
397
398#define FLECS_LOG_1
399#define FLECS_LOG_0
400
401#elif defined(FLECS_LOG_1) /* Level 1 debug tracing enabled */
402#define ecs_dbg_1(...) ecs_log(1, __VA_ARGS__);
403#define ecs_dbg_2(...)
404#define ecs_dbg_3(...)
405
406#define ecs_log_push_1() ecs_log_push_(1);
407#define ecs_log_push_2()
408#define ecs_log_push_3()
409
410#define ecs_log_pop_1() ecs_log_pop_(1);
411#define ecs_log_pop_2()
412#define ecs_log_pop_3()
413
414#define ecs_should_log_1() ecs_should_log(1)
415#define ecs_should_log_2() false
416#define ecs_should_log_3() false
417
418#define FLECS_LOG_0
419
420#elif defined(FLECS_LOG_0) /* No debug tracing enabled */
421#define ecs_dbg_1(...)
422#define ecs_dbg_2(...)
423#define ecs_dbg_3(...)
424
425#define ecs_log_push_1()
426#define ecs_log_push_2()
427#define ecs_log_push_3()
428
429#define ecs_log_pop_1()
430#define ecs_log_pop_2()
431#define ecs_log_pop_3()
432
433#define ecs_should_log_1() false
434#define ecs_should_log_2() false
435#define ecs_should_log_3() false
436
437#else /* No tracing enabled */
438#undef ecs_trace
439#define ecs_trace(...)
440#define ecs_dbg_1(...)
441#define ecs_dbg_2(...)
442#define ecs_dbg_3(...)
443
444#define ecs_log_push_1()
445#define ecs_log_push_2()
446#define ecs_log_push_3()
447
448#define ecs_log_pop_1()
449#define ecs_log_pop_2()
450#define ecs_log_pop_3()
451
452#endif // defined(FLECS_LOG_3)
453
454/** Default debug tracing is at level 1. */
455#define ecs_dbg ecs_dbg_1
456
457/** Push log indentation at the default level. */
458#define ecs_log_push() ecs_log_push_(0)
459/** Pop log indentation at the default level. */
460#define ecs_log_pop() ecs_log_pop_(0)
461
462/** Abort.
463 * Unconditionally aborts the process. */
464#define ecs_abort(error_code, ...)\
465 ecs_abort_(error_code, __FILE__, __LINE__, __VA_ARGS__);\
466 ecs_os_abort(); abort(); /* satisfy compiler/static analyzers */
467
468/** Assert.
469 * Aborts if condition is false, disabled in release mode. */
470#if defined(FLECS_NDEBUG) && !defined(FLECS_KEEP_ASSERT)
471#define ecs_assert(condition, error_code, ...)
472#else
473#define ecs_assert(condition, error_code, ...)\
474 if (!(condition)) {\
475 ecs_assert_log_(error_code, #condition, __FILE__, __LINE__, __VA_ARGS__);\
476 ecs_os_abort();\
477 }\
478 assert(condition) /* satisfy compiler/static analyzers */
479#endif // FLECS_NDEBUG
480
481/** Debug assert.
482 * Assert that is only valid in debug mode (ignores FLECS_KEEP_ASSERT). */
483#ifndef FLECS_NDEBUG
484#define ecs_dbg_assert(condition, error_code, ...) ecs_assert(condition, error_code, __VA_ARGS__)
485#else
486#define ecs_dbg_assert(condition, error_code, ...)
487#endif
488
489/** Always assert.
490 * Assert that is always active, even in release builds. Always aborts on
491 * failure (does not support FLECS_SOFT_ASSERT). */
492#define ecs_always_assert(condition, error_code, ...)\
493 if (!(condition)) {\
494 ecs_assert_log_(error_code, #condition, __FILE__, __LINE__, __VA_ARGS__);\
495 ecs_os_abort();\
496 }\
497 assert(condition) /* satisfy compiler/static analyzers */
498
499/** Sanitize assert.
500 * Assert that is only valid in sanitized mode (ignores FLECS_KEEP_ASSERT). */
501#ifdef FLECS_SANITIZE
502#define ecs_san_assert(condition, error_code, ...) ecs_assert(condition, error_code, __VA_ARGS__)
503#else
504#define ecs_san_assert(condition, error_code, ...)
505#endif
506
507
508/** Silence dead code/unused label warnings when compiling without checks. */
509#define ecs_dummy_check\
510 if ((false)) {\
511 goto error;\
512 }
513
514/** Check.
515 * Go to error if condition is false. */
516#if defined(FLECS_NDEBUG) && !defined(FLECS_KEEP_ASSERT)
517#define ecs_check(condition, error_code, ...) ecs_dummy_check
518#else
519#ifdef FLECS_SOFT_ASSERT
520#define ecs_check(condition, error_code, ...)\
521 if (!(condition)) {\
522 ecs_assert_log_(error_code, #condition, __FILE__, __LINE__, __VA_ARGS__);\
523 goto error;\
524 }\
525 ecs_dummy_check
526#else // FLECS_SOFT_ASSERT
527#define ecs_check(condition, error_code, ...)\
528 if (!(condition)) {\
529 ecs_assert_log_(error_code, #condition, __FILE__, __LINE__, __VA_ARGS__);\
530 ecs_os_abort();\
531 }\
532 assert(condition); /* satisfy compiler/static analyzers */ \
533 ecs_dummy_check
534#endif
535#endif // FLECS_NDEBUG
536
537/** Panic.
538 * Go to error when FLECS_SOFT_ASSERT is defined, otherwise abort. */
539#if defined(FLECS_NDEBUG) && !defined(FLECS_KEEP_ASSERT)
540#define ecs_throw(error_code, ...) ecs_dummy_check
541#else
542#ifdef FLECS_SOFT_ASSERT
543#define ecs_throw(error_code, ...)\
544 ecs_abort_(error_code, __FILE__, __LINE__, __VA_ARGS__);\
545 goto error;
546#else
547#define ecs_throw(error_code, ...)\
548 ecs_abort(error_code, __VA_ARGS__);\
549 ecs_dummy_check
550#endif
551#endif // FLECS_NDEBUG
552
553/** Parser error. */
554#define ecs_parser_error(name, expr, column, ...)\
555 ecs_parser_error_(name, expr, column, __VA_ARGS__)
556
557/** Parser error with va_list. */
558#define ecs_parser_errorv(name, expr, column, fmt, args)\
559 ecs_parser_errorv_(name, expr, column, fmt, args)
560
561/** Parser warning. */
562#define ecs_parser_warning(name, expr, column, ...)\
563 ecs_parser_warning_(name, expr, column, __VA_ARGS__)
564
565/** Parser warning with va_list. */
566#define ecs_parser_warningv(name, expr, column, fmt, args)\
567 ecs_parser_warningv_(name, expr, column, fmt, args)
568
569#endif // FLECS_LEGACY
570
571////////////////////////////////////////////////////////////////////////////////
572//// Functions that are always available
573////////////////////////////////////////////////////////////////////////////////
574
575/** Enable or disable log.
576 * This will enable the built-in log. For log to work, it will have to be
577 * compiled in, which requires defining one of the following macros:
578 *
579 * FLECS_LOG_0 - All log is disabled
580 * FLECS_LOG_1 - Enable log level 1
581 * FLECS_LOG_2 - Enable log level 2 and below
582 * FLECS_LOG_3 - Enable log level 3 and below
583 *
584 * If no log level is defined and this is a debug build, FLECS_LOG_3 will
585 * have been automatically defined.
586 *
587 * The provided level corresponds with the log level. If -1 is provided as
588 * value, warnings are disabled. If -2 is provided, errors are disabled as well.
589 *
590 * @param level Desired tracing level.
591 * @return Previous log level.
592 */
593FLECS_API
595 int level);
596
597/** Get current log level.
598 *
599 * @return Current log level.
600 */
601FLECS_API
603
604/** Enable/disable tracing with colors.
605 * By default, colors are enabled.
606 *
607 * @param enabled Whether to enable tracing with colors.
608 * @return Previous color setting.
609 */
610FLECS_API
612 bool enabled);
613
614/** Enable/disable logging timestamp.
615 * By default, timestamps are disabled. Note that enabling timestamps introduces
616 * overhead as the logging code will need to obtain the current time.
617 *
618 * @param enabled Whether to enable tracing with timestamps.
619 * @return Previous timestamp setting.
620 */
621FLECS_API
623 bool enabled);
624
625/** Enable/disable logging time since last log.
626 * By default, deltatime is disabled. Note that enabling timestamps introduces
627 * overhead as the logging code will need to obtain the current time.
628 *
629 * When enabled, this logs the amount of time in seconds passed since the last
630 * log, when this amount is non-zero. The format is a '+' character followed by
631 * the number of seconds:
632 *
633 * +1 trace: log message
634 *
635 * @param enabled Whether to enable tracing with timestamps.
636 * @return Previous timestamp setting.
637 */
638FLECS_API
640 bool enabled);
641
642/** Get last logged error code.
643 * Calling this operation resets the error code.
644 *
645 * @return Last error, 0 if none was logged since last call to last_error.
646 */
647FLECS_API
649
650/** Start capturing log output.
651 *
652 * @param capture_try If true, also capture messages from ecs_log_try blocks.
653 */
654FLECS_API
655void ecs_log_start_capture(bool capture_try);
656
657/** Stop capturing log output.
658 *
659 * @return The captured log output, or NULL if no output was captured.
660 */
661FLECS_API
663
664////////////////////////////////////////////////////////////////////////////////
665//// Error codes
666////////////////////////////////////////////////////////////////////////////////
667
668/** Invalid operation error code. */
669#define ECS_INVALID_OPERATION (1)
670/** Invalid parameter error code. */
671#define ECS_INVALID_PARAMETER (2)
672/** Constraint violated error code. */
673#define ECS_CONSTRAINT_VIOLATED (3)
674/** Out of memory error code. */
675#define ECS_OUT_OF_MEMORY (4)
676/** Out of range error code. */
677#define ECS_OUT_OF_RANGE (5)
678/** Unsupported error code. */
679#define ECS_UNSUPPORTED (6)
680/** Internal error code. */
681#define ECS_INTERNAL_ERROR (7)
682/** Already defined error code. */
683#define ECS_ALREADY_DEFINED (8)
684/** Missing OS API error code. */
685#define ECS_MISSING_OS_API (9)
686/** Operation failed error code. */
687#define ECS_OPERATION_FAILED (10)
688/** Invalid conversion error code. */
689#define ECS_INVALID_CONVERSION (11)
690/** Cycle detected error code. */
691#define ECS_CYCLE_DETECTED (13)
692/** Leak detected error code. */
693#define ECS_LEAK_DETECTED (14)
694/** Double free error code. */
695#define ECS_DOUBLE_FREE (15)
696
697/** Inconsistent name error code. */
698#define ECS_INCONSISTENT_NAME (20)
699/** Name in use error code. */
700#define ECS_NAME_IN_USE (21)
701/** Invalid component size error code. */
702#define ECS_INVALID_COMPONENT_SIZE (23)
703/** Invalid component alignment error code. */
704#define ECS_INVALID_COMPONENT_ALIGNMENT (24)
705/** Component not registered error code. */
706#define ECS_COMPONENT_NOT_REGISTERED (25)
707/** Inconsistent component id error code. */
708#define ECS_INCONSISTENT_COMPONENT_ID (26)
709/** Inconsistent component action error code. */
710#define ECS_INCONSISTENT_COMPONENT_ACTION (27)
711/** Module undefined error code. */
712#define ECS_MODULE_UNDEFINED (28)
713/** Missing symbol error code. */
714#define ECS_MISSING_SYMBOL (29)
715/** Already in use error code. */
716#define ECS_ALREADY_IN_USE (30)
717
718/** Access violation error code. */
719#define ECS_ACCESS_VIOLATION (40)
720/** Column index out of range error code. */
721#define ECS_COLUMN_INDEX_OUT_OF_RANGE (41)
722/** Column is not shared error code. */
723#define ECS_COLUMN_IS_NOT_SHARED (42)
724/** Column is shared error code. */
725#define ECS_COLUMN_IS_SHARED (43)
726/** Column type mismatch error code. */
727#define ECS_COLUMN_TYPE_MISMATCH (45)
728
729/** Invalid while readonly error code. */
730#define ECS_INVALID_WHILE_READONLY (70)
731/** Locked storage error code. */
732#define ECS_LOCKED_STORAGE (71)
733/** Invalid from worker error code. */
734#define ECS_INVALID_FROM_WORKER (72)
735
736
737////////////////////////////////////////////////////////////////////////////////
738//// Used when logging with colors is enabled
739////////////////////////////////////////////////////////////////////////////////
740
741/** Black ANSI color escape code. */
742#define ECS_BLACK "\033[1;30m"
743/** Red ANSI color escape code. */
744#define ECS_RED "\033[0;31m"
745/** Green ANSI color escape code. */
746#define ECS_GREEN "\033[0;32m"
747/** Yellow ANSI color escape code. */
748#define ECS_YELLOW "\033[0;33m"
749/** Blue ANSI color escape code. */
750#define ECS_BLUE "\033[0;34m"
751/** Magenta ANSI color escape code. */
752#define ECS_MAGENTA "\033[0;35m"
753/** Cyan ANSI color escape code. */
754#define ECS_CYAN "\033[0;36m"
755/** White ANSI color escape code. */
756#define ECS_WHITE "\033[1;37m"
757/** Grey ANSI color escape code. */
758#define ECS_GREY "\033[0;37m"
759/** Normal ANSI color escape code. */
760#define ECS_NORMAL "\033[0;49m"
761/** Bold ANSI escape code. */
762#define ECS_BOLD "\033[1;49m"
763
764#ifdef __cplusplus
765}
766#endif
767
768/** @} */
769
770#endif // FLECS_LOG_H
FLECS_API char * ecs_log_stop_capture(void)
Stop capturing log output.
FLECS_API void ecs_logv_(int32_t level, const char *file, int32_t line, const char *fmt, va_list args)
Log at the provided level (va_list).
FLECS_API int ecs_log_last_error(void)
Get last logged error code.
FLECS_API void ecs_log_pop_(int32_t level)
Decrease log stack.
FLECS_API void ecs_printv_(int32_t 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_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 void ecs_abort_(int32_t error_code, const char *file, int32_t line, const char *fmt,...)
Abort with error code.
FLECS_API void ecs_log_start_capture(bool capture_try)
Start capturing log output.
FLECS_API bool ecs_should_log(int32_t level)
Should current level be logged.
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_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_print_(int32_t level, const char *file, int32_t line, const char *fmt,...)
Print at the provided log level.
FLECS_API const char * ecs_strerror(int32_t error_code)
Get description for error code.
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_parser_warning_(const char *name, const char *expr, int64_t column, const char *fmt,...)
Log a parser warning.
FLECS_API bool ecs_log_enable_colors(bool enabled)
Enable/disable tracing with colors.
FLECS_API void ecs_parser_error_(const char *name, const char *expr, int64_t column, const char *fmt,...)
Log a parser error.
FLECS_API int ecs_log_get_level(void)
Get current log level.
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 int ecs_log_set_level(int level)
Enable or disable log.
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.