diff --git a/src/debug.cpp b/src/debug.cpp index 2f3a1f7322..3128cc47d6 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -139,7 +139,7 @@ char *DumpDebugFacilityNames(char *buf, char *last) * @param dbg Debug category. * @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) { char buf2[1024 + 32]; diff --git a/src/debug.h b/src/debug.h index 4855c96abb..9a2409e006 100644 --- a/src/debug.h +++ b/src/debug.h @@ -64,6 +64,7 @@ extern bool _save_DBGC_data; extern std::string _loadgame_DBGC_data; void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3); +void debug_print(const char *dbg, const char *buf); char *DumpDebugFacilityNames(char *buf, char *last); void SetDebugString(const char *s, void (*error_func)(const char *)); diff --git a/src/debug_fmt.h b/src/debug_fmt.h new file mode 100644 index 0000000000..4011e28955 --- /dev/null +++ b/src/debug_fmt.h @@ -0,0 +1,24 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file debug_fmt.h Functions related to debugging. */ + +#ifndef DEBUG_FMT_H +#define DEBUG_FMT_H + +#include "debug.h" +#include "3rdparty/fmt/format.h" + +/** + * 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()) + +#endif /* DEBUG_FMT_H */