4d26f13c26
* Added function name logging to mgba_logger * Addendum to no-op defines * Fixed compile errors * Added "()" to function name in log to make it clearer it's a function * Corrected documentation * clang-format...? * Removed MGBA_LOG_LEVEL_MASK magic number * Added CHECK_NULL_ARG macros * clang-format...? * clang-format for real * Added documentation for CHECK_NULL_ARG_VOID and CHECK_NULL_ARG_RET * Fixed typo Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fixed macro safety by wrappinh with do-while Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fixed format string cut risk in mgba_func_printf * clang-format * clang-format some more * clang-format for real * Fixed DEBUG -> INFO in comment Co-authored-by: Rickey <ric@rf3.xyz> * Moved NULL-check macros to util.h and renamed them * Small additions - macro rename + clang-format * Truncate the string instead of the function name * Cleaned up code from previous commit * clang-format * Added mgba_logger_available check to mgba_func_printf * Updated documentation for latest change * Changed CHECK_NULL_ARG functions to generic RETURN_ON_ERROR_VAL functions. * clang-format * Changed back to specifically check NULL * clang-format * Changed "=" into "==" in the error message * clang-format * Fixed forgotten "==" --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Rickey <ric@rf3.xyz>
105 lines
2.9 KiB
C
105 lines
2.9 KiB
C
/**
|
|
* @file mgba_logger.h
|
|
*
|
|
* @brief Interface to interact with the mgba logger.
|
|
*
|
|
* Use with mgba in the command line.
|
|
*
|
|
* You can pass which logs you'd like to print with a flag passed to mgba
|
|
* with `-l` or `--log-level`.
|
|
*
|
|
* | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
|
* |---|---|---|-------|------|------|-------|-------|
|
|
* | / | / | / | DEBUG | INFO | WARN | ERROR | FATAL |
|
|
*
|
|
* ```sh
|
|
* mgba -l 3 game.rom # ERROR and FATAL
|
|
* mgba -l 14 game.rom # INFO, WARN, and ERROR
|
|
* ```
|
|
*
|
|
* @note You have to fight with other logs in mgba and INFO can get messy.
|
|
*
|
|
* @note FATAL does kill the game. Use with care.
|
|
*/
|
|
#ifndef MGBA_LOGGER_H
|
|
#define MGBA_LOGGER_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
typedef enum
|
|
{
|
|
MGBA_LOG_FATAL,
|
|
MGBA_LOG_ERROR,
|
|
MGBA_LOG_WARN,
|
|
MGBA_LOG_INFO,
|
|
MGBA_LOG_DEBUG,
|
|
} MgbaLogLevel;
|
|
|
|
/**
|
|
* @brief Initialize mgba logger
|
|
*
|
|
* Checks that the logger is available by checking the expected registers
|
|
* magic number
|
|
*/
|
|
bool mgba_logger_init(void);
|
|
|
|
/**
|
|
* @brief Print to mgba log with a format string
|
|
*
|
|
* @param level
|
|
* @param fmt Format string
|
|
* @param ... variadic arguments
|
|
*
|
|
* @note for all logs, it's cutoff at the hard mgba limit of 0x100
|
|
*/
|
|
void mgba_printf(MgbaLogLevel level, const char* fmt, ...);
|
|
|
|
/**
|
|
* @brief Print to mgba log with a format string and function name
|
|
*
|
|
* @param level
|
|
* @param func_name Function name - prepended to the log string "<func_name>(): <log_string>"
|
|
* @param fmt Format string
|
|
* @param ... variadic arguments
|
|
*
|
|
* @note for all logs, it's cutoff at the hard mgba limit of 0x100
|
|
*/
|
|
void mgba_func_printf(MgbaLogLevel level, const char* func_name, const char* fmt, ...);
|
|
|
|
// clang-format off
|
|
#ifdef MGBA_LOGGING
|
|
|
|
#define MGBA_FATAL(...) mgba_printf(MGBA_LOG_FATAL, __VA_ARGS__)
|
|
#define MGBA_ERROR(...) mgba_printf(MGBA_LOG_ERROR, __VA_ARGS__)
|
|
#define MGBA_WARN(...) mgba_printf(MGBA_LOG_WARN, __VA_ARGS__)
|
|
#define MGBA_INFO(...) mgba_printf(MGBA_LOG_INFO, __VA_ARGS__)
|
|
#define MGBA_DEBUG(...) mgba_printf(MGBA_LOG_DEBUG, __VA_ARGS__)
|
|
|
|
#define MGBA_FUNC_LOG(level, ...) mgba_func_printf(level, __func__, __VA_ARGS__)
|
|
|
|
#define MGBA_FUNC_FATAL(...) MGBA_FUNC_LOG(MGBA_LOG_FATAL, __VA_ARGS__)
|
|
#define MGBA_FUNC_ERROR(...) MGBA_FUNC_LOG(MGBA_LOG_ERROR, __VA_ARGS__)
|
|
#define MGBA_FUNC_WARN(...) MGBA_FUNC_LOG(MGBA_LOG_WARN, __VA_ARGS__)
|
|
#define MGBA_FUNC_INFO(...) MGBA_FUNC_LOG(MGBA_LOG_INFO, __VA_ARGS__)
|
|
#define MGBA_FUNC_DEBUG(...) MGBA_FUNC_LOG(MGBA_LOG_DEBUG, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define MGBA_FATAL(...) ((void)0)
|
|
#define MGBA_ERROR(...) ((void)0)
|
|
#define MGBA_WARN(...) ((void)0)
|
|
#define MGBA_INFO(...) ((void)0)
|
|
#define MGBA_DEBUG(...) ((void)0)
|
|
|
|
#define MGBA_FUNC_LOG(level, ...) ((void)0)
|
|
|
|
#define MGBA_FUNC_FATAL(...) ((void)0)
|
|
#define MGBA_FUNC_ERROR(...) ((void)0)
|
|
#define MGBA_FUNC_WARN(...) ((void)0)
|
|
#define MGBA_FUNC_INFO(...) ((void)0)
|
|
#define MGBA_FUNC_DEBUG(...) ((void)0)
|
|
#endif
|
|
// clang-format on
|
|
|
|
#endif
|