|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
22 #include "3rdparty/fmt/chrono.h"
38 int _debug_driver_level;
41 int _debug_misc_level;
43 int _debug_sprite_level;
44 int _debug_oldloader_level;
46 int _debug_yapf_level;
47 int _debug_fontcache_level;
48 int _debug_script_level;
50 int _debug_gamelog_level;
51 int _debug_desync_level;
52 int _debug_console_level;
54 int _debug_random_level;
62 #define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
70 DEBUG_LEVEL(oldloader),
73 DEBUG_LEVEL(fontcache),
94 fmt::format_to(output_iterator,
"List of debug facility names:\n");
96 fmt::format_to(output_iterator,
", ");
98 fmt::format_to(output_iterator,
"{}", i->name);
102 fmt::format_to(output_iterator,
"\n\n");
111 void DebugPrint(
const char *category,
int level,
const std::string &message)
113 if (strcmp(category,
"desync") == 0) {
115 if (f ==
nullptr)
return;
120 }
else if (strcmp(category,
"random") == 0) {
122 if (f ==
nullptr)
return;
124 fmt::print(f,
"{}\n", message);
128 fmt::print(stderr,
"{}dbg: [{}:{}] {}\n",
GetLogPrefix(
true), category, level, message);
152 std::map<const char *, int> new_levels;
155 if (*s >=
'0' && *s <=
'9') {
158 v = std::strtoul(s, &end, 0);
161 for (i = debug_level; i !=
endof(debug_level); ++i) {
162 new_levels[i->name] = v;
169 while (*s ==
' ' || *s ==
',' || *s ==
'\t') s++;
170 if (*s ==
'\0')
break;
173 while (*s >=
'a' && *s <=
'z') s++;
177 for (
const DebugLevel *i = debug_level; i !=
endof(debug_level); ++i) {
178 if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) {
185 v = std::strtoul(s, &end, 0);
187 if (found !=
nullptr) {
188 new_levels[found->name] = v;
190 std::string error_string = fmt::format(
"Unknown debug level '{}'", std::string(t, s - t));
191 error_func(error_string);
197 for (
const DebugLevel *i = debug_level; i !=
endof(debug_level); ++i) {
198 const auto &nl = new_levels.find(i->name);
199 if (nl != new_levels.end()) {
200 *i->level = nl->second;
213 for (
const DebugLevel *i = debug_level; i !=
endof(debug_level); ++i) {
214 if (!result.empty()) result +=
", ";
215 fmt::format_to(std::back_inserter(result),
"{}={}", i->name, *i->level);
230 std::string log_prefix;
232 log_prefix = fmt::format(
"[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(
nullptr)));
std::atomic< bool > _debug_remote_console
Whether we need to send data to either NetworkAdminConsole or IConsolePrint.
std::mutex lock
synchronization for playback status fields
@ ADMIN_UPDATE_CONSOLE
The admin would like to have console messages.
void DumpDebugFacilityNames(std::back_insert_iterator< std::string > &output_iterator)
Dump the available debug facility names in the help text.
static Pool::IterateWrapperFiltered< ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter > IterateActive(size_t from=0)
Returns an iterable ensemble of all active admin sockets.
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
ClientSettings _settings_client
The current settings for this game.
void SetDebugString(const char *s, void(*error_func)(const std::string &))
Set debugging levels by parsing the text in s.
void NetworkAdminConsole(const std::string_view origin, const std::string_view string)
Send console to the admin network (if they did opt in for the respective update).
std::string level
The used debug level.
bool show_date_in_logs
whether to show dates in console logs
std::string message
The actual formatted message.
std::string GetDebugString()
Print out the current debug-level.
std::vector< QueuedDebugItem > _debug_remote_console_queue_spare
Spare queue to swap with _debug_remote_console_queue.
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
static const TextColour CC_DEBUG
Colour for debug output.
std::string GetLogPrefix(bool force)
Get the prefix for logs.
std::vector< QueuedDebugItem > _debug_remote_console_queue
Queue for debug messages to be passed to NetworkAdminConsole or IConsolePrint.
#define endof(x)
Get the end element of an fixed size array.
Class for handling the server side of the game connection.
@ ADMIN_FREQUENCY_AUTOMATIC
The admin gets information about this when it changes.
void DebugSendRemoteMessages()
Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop threa...
uint8_t developer
print non-fatal warnings in console (>= 1), copy debug output to console (== 2)
std::mutex _debug_remote_console_mutex
Mutex to guard the queue of debug messages for either NetworkAdminConsole or IConsolePrint.
void DebugPrint(const char *category, int level, const std::string &message)
Internal function for outputting the debug line.
Element in the queue of debug messages that have to be passed to either NetworkAdminConsole or IConso...
void DebugReconsiderSendRemoteMessages()
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
GUISettings gui
settings related to the GUI
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.