Update to 12.0-beta1
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include "os/windows/win32.h"
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include "walltime_func.h"
|
||||
|
||||
#include "network/network_admin.h"
|
||||
SOCKET _debug_socket = INVALID_SOCKET;
|
||||
@@ -100,67 +100,41 @@ char *DumpDebugFacilityNames(char *buf, char *last)
|
||||
|
||||
/**
|
||||
* Internal function for outputting the debug line.
|
||||
* @param dbg Debug category.
|
||||
* @param buf Text line to output.
|
||||
* @param level Debug category.
|
||||
* @param message The message to output.
|
||||
*/
|
||||
static void debug_print(const char *dbg, const char *buf)
|
||||
void DebugPrint(const char *level, const std::string &message)
|
||||
{
|
||||
if (_debug_socket != INVALID_SOCKET) {
|
||||
char buf2[1024 + 32];
|
||||
|
||||
seprintf(buf2, lastof(buf2), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
|
||||
std::string msg = fmt::format("{}dbg: [{}] {}\n", GetLogPrefix(), level, message);
|
||||
/* 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. */
|
||||
send(_debug_socket, buf2, (int)strlen(buf2), 0);
|
||||
send(_debug_socket, msg.c_str(), (int)msg.size(), 0);
|
||||
return;
|
||||
}
|
||||
if (strcmp(dbg, "desync") == 0) {
|
||||
if (strcmp(level, "desync") == 0) {
|
||||
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
|
||||
if (f == nullptr) return;
|
||||
|
||||
fprintf(f, "%s%s\n", GetLogPrefix(), buf);
|
||||
fprintf(f, "%s%s\n", GetLogPrefix(), message.c_str());
|
||||
fflush(f);
|
||||
#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);
|
||||
if (f == nullptr) return;
|
||||
|
||||
fprintf(f, "%s\n", buf);
|
||||
fprintf(f, "%s\n", message.c_str());
|
||||
fflush(f);
|
||||
#endif
|
||||
} else {
|
||||
char buffer[512];
|
||||
seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
|
||||
#if defined(_WIN32)
|
||||
wchar_t system_buf[512];
|
||||
convert_to_fs(buffer, system_buf, lengthof(system_buf), true);
|
||||
_fputts(system_buf, stderr);
|
||||
#else
|
||||
fputs(buffer, stderr);
|
||||
#endif
|
||||
NetworkAdminConsole(dbg, buf);
|
||||
IConsoleDebug(dbg, buf);
|
||||
std::string msg = fmt::format("{}dbg: [{}] {}\n", GetLogPrefix(), level, message);
|
||||
fputs(msg.c_str(), stderr);
|
||||
|
||||
NetworkAdminConsole(level, message);
|
||||
if (_settings_client.gui.developer >= 2) IConsolePrint(CC_DEBUG, "dbg: [{}] {}", level, message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a debug line.
|
||||
* @note Do not call directly, use the #DEBUG macro instead.
|
||||
* @param dbg Debug category.
|
||||
* @param format Text string a la printf, with optional arguments.
|
||||
*/
|
||||
void CDECL debug(const char *dbg, const char *format, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
vseprintf(buf, lastof(buf), format, va);
|
||||
va_end(va);
|
||||
|
||||
debug_print(dbg, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set debugging levels by parsing the text in \a s.
|
||||
* For setting individual levels a string like \c "net=3,grf=6" should be used.
|
||||
@@ -248,8 +222,7 @@ const char *GetLogPrefix()
|
||||
{
|
||||
static char _log_prefix[24];
|
||||
if (_settings_client.gui.show_date_in_logs) {
|
||||
time_t cur_time = time(nullptr);
|
||||
strftime(_log_prefix, sizeof(_log_prefix), "[%Y-%m-%d %H:%M:%S] ", localtime(&cur_time));
|
||||
LocalTime::Format(_log_prefix, lastof(_log_prefix), "[%Y-%m-%d %H:%M:%S] ");
|
||||
} else {
|
||||
*_log_prefix = '\0';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user