mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use the fmt library for simpler debug formats
parent
662d8dfc30
commit
a99ac62c1a
|
@ -103,7 +103,7 @@ char *DumpDebugFacilityNames(char *buf, char *last)
|
||||||
* @param dbg Debug category.
|
* @param dbg Debug category.
|
||||||
* @param buf Text line to output.
|
* @param buf Text line to output.
|
||||||
*/
|
*/
|
||||||
static void debug_print(const char *dbg, const char *buf)
|
void debug_print(const char *dbg, const char *buf)
|
||||||
{
|
{
|
||||||
if (_debug_socket != INVALID_SOCKET) {
|
if (_debug_socket != INVALID_SOCKET) {
|
||||||
char buf2[1024 + 32];
|
char buf2[1024 + 32];
|
||||||
|
|
11
src/debug.h
11
src/debug.h
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include "3rdparty/fmt/format.h"
|
||||||
|
|
||||||
/* Debugging messages policy:
|
/* Debugging messages policy:
|
||||||
* These should be the severities used for direct DEBUG() calls
|
* These should be the severities used for direct DEBUG() calls
|
||||||
|
@ -27,6 +28,16 @@
|
||||||
* 6.. - extremely detailed spamming
|
* 6.. - extremely detailed spamming
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void debug_print(const char *dbg, const char *buf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ouptut a line of debugging information.
|
||||||
|
* @param name The category of debug information.
|
||||||
|
* @param level The maximum debug level this message should be shown at. When the debug level for this category is set lower, then the message will not be shown.
|
||||||
|
* @param format_string The formatting string of the message.
|
||||||
|
*/
|
||||||
|
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug_print(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__).c_str())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output a line of debugging information.
|
* Output a line of debugging information.
|
||||||
* @param name Category
|
* @param name Category
|
||||||
|
|
|
@ -425,6 +425,9 @@ static_assert(SIZE_MAX >= UINT32_MAX);
|
||||||
# define unlikely(x) (x)
|
# define unlikely(x) (x)
|
||||||
#endif /* __GNUC__ || __clang__ */
|
#endif /* __GNUC__ || __clang__ */
|
||||||
|
|
||||||
|
/* For the FMT library we only want to use the headers, not link to some library. */
|
||||||
|
#define FMT_HEADER_ONLY
|
||||||
|
|
||||||
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
|
void NORETURN CDECL usererror(const char *str, ...) WARN_FORMAT(1, 2);
|
||||||
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
|
void NORETURN CDECL error(const char *str, ...) WARN_FORMAT(1, 2);
|
||||||
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
|
#define NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__)
|
||||||
|
|
Loading…
Reference in New Issue