mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
Codechange: use fmt in DebugPrint where applicable
This commit is contained in:
parent
352dbdd570
commit
7d79180040
@ -100,46 +100,43 @@ char *DumpDebugFacilityNames(char *buf, char *last)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal function for outputting the debug line.
|
* Internal function for outputting the debug line.
|
||||||
* @param dbg Debug category.
|
* @param level Debug category.
|
||||||
* @param buf Text line to output.
|
* @param message The message to output.
|
||||||
*/
|
*/
|
||||||
void debug_print(const char *dbg, const char *buf)
|
void DebugPrint(const char *level, const std::string &message)
|
||||||
{
|
{
|
||||||
if (_debug_socket != INVALID_SOCKET) {
|
if (_debug_socket != INVALID_SOCKET) {
|
||||||
char buf2[1024 + 32];
|
std::string msg = fmt::format("{}dbg: [{}] {}\n", GetLogPrefix(), level, message);
|
||||||
|
|
||||||
seprintf(buf2, lastof(buf2), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
|
|
||||||
/* Sending out an error when this fails would be nice, however... the error
|
/* Sending out an error when this fails would be nice, however... the error
|
||||||
* would have to be send over this failing socket which won't work. */
|
* would have to be send over this failing socket which won't work. */
|
||||||
send(_debug_socket, buf2, (int)strlen(buf2), 0);
|
send(_debug_socket, msg.c_str(), (int)msg.size(), 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (strcmp(dbg, "desync") == 0) {
|
if (strcmp(level, "desync") == 0) {
|
||||||
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
|
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
|
||||||
if (f == nullptr) return;
|
if (f == nullptr) return;
|
||||||
|
|
||||||
fprintf(f, "%s%s\n", GetLogPrefix(), buf);
|
fprintf(f, "%s%s\n", GetLogPrefix(), message.c_str());
|
||||||
fflush(f);
|
fflush(f);
|
||||||
#ifdef RANDOM_DEBUG
|
#ifdef RANDOM_DEBUG
|
||||||
} else if (strcmp(dbg, "random") == 0) {
|
} else if (strcmp(level, "random") == 0) {
|
||||||
static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
|
static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
|
||||||
if (f == nullptr) return;
|
if (f == nullptr) return;
|
||||||
|
|
||||||
fprintf(f, "%s\n", buf);
|
fprintf(f, "%s\n", message.c_str());
|
||||||
fflush(f);
|
fflush(f);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
char buffer[512];
|
std::string msg = fmt::format("{}dbg: [{}] {}\n", GetLogPrefix(), level, message);
|
||||||
seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
wchar_t system_buf[512];
|
wchar_t system_buf[512];
|
||||||
convert_to_fs(buffer, system_buf, lengthof(system_buf));
|
convert_to_fs(msg.c_str(), system_buf, lengthof(system_buf));
|
||||||
fputws(system_buf, stderr);
|
fputws(system_buf, stderr);
|
||||||
#else
|
#else
|
||||||
fputs(buffer, stderr);
|
fputs(msg.c_str(), stderr);
|
||||||
#endif
|
#endif
|
||||||
NetworkAdminConsole(dbg, buf);
|
NetworkAdminConsole(level, message);
|
||||||
IConsoleDebug(dbg, buf);
|
IConsoleDebug(level, message.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,15 +28,14 @@
|
|||||||
* 6.. - extremely detailed spamming
|
* 6.. - extremely detailed spamming
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void debug_print(const char *dbg, const char *buf);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ouptut a line of debugging information.
|
* Ouptut a line of debugging information.
|
||||||
* @param name The category of debug 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 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.
|
* @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())
|
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) DebugPrint(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
|
||||||
|
void DebugPrint(const char *level, const std::string &message);
|
||||||
|
|
||||||
extern int _debug_driver_level;
|
extern int _debug_driver_level;
|
||||||
extern int _debug_grf_level;
|
extern int _debug_grf_level;
|
||||||
|
Loading…
Reference in New Issue
Block a user