Skip to content

debug.h

Devon edited this page Feb 12, 2021 · 1 revision

If you find any errors, please open an issue or submit a pull request!

Initialization

The debug system doesn't require initialization, but does have a context which can be obtained with the method d_ctx_get() in debug.h. The context is initialized statically at runtime.

Output

The debug header in astera has a few ways of outputting.

ASTERA_DBG - Output to the debug function `_l` if available
ASTERA_FUNC_DBG - Output to debug function `_l` with leading function name if available
_l - Output to stdio/logs if either enabled
_e - Output to stderr/logs if either enabled

Note that ASTERA_DBG and ASTERA_FUNC_DBG don't work with the MSVC compiler, so as a result don't output anything. These two methods are macros meant to be re-definable by the user to redirect output internally within the engine. _l and _e are the internal implementations of astera's debug functions, which don't need to be used at all.

Logging

By default, logging is disabled within Astera. You can enable it by calling:

/* Disable / Enable & set usage of outputting the log to file
 *  log - 1 = use log, 0 = don't
 *  fp - the filepath (optional if disabling) */
void d_set_log(uint8_t log, const char* fp);

If logging is already enabled and you want to change the filepath, you can set that with:

/* Set the file to use for log output
 * fp - the file path*/
void d_set_log_fp(const char* fp);

If you want to enable timestamps within the log, you can do so by calling:

/* Enable / disable usage of the timestamp
 * timestamp - use timestamp, 0 = don't */
void d_use_timestamp(uint8_t timestamp);

Cleanup

If you wish to remove any logs on say program exit or for any other reason you can call:

/* Remove any files created by runtime (except for error files)
 * returns: success = 1, failure = 0 */
uint8_t d_cleanup();

As well, if you wish to push the log to an error file you can also do so with:

/* Post the output file to a unique timestamped error file
 * returns: success = 1, failure = 0 */
uint8_t d_post_to_err();
Clone this wiki locally