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;
45 int _debug_yapf_level;
46 int _debug_fontcache_level;
47 int _debug_script_level;
49 int _debug_gamelog_level;
50 int _debug_desync_level;
51 int _debug_console_level;
53 int _debug_random_level;
61 #define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
69 DEBUG_LEVEL(oldloader),
71 DEBUG_LEVEL(fontcache),
90 for (
const auto &debug_level : _debug_levels) {
92 fmt::format_to(output_iterator,
"List of debug facility names:\n");
94 fmt::format_to(output_iterator,
", ");
96 fmt::format_to(output_iterator,
"{}", debug_level.name);
100 fmt::format_to(output_iterator,
"\n\n");
109 void DebugPrint(
const char *category,
int level,
const std::string &message)
111 if (strcmp(category,
"desync") == 0 && level != 0) {
113 if (!f.has_value())
return;
118 }
else if (strcmp(category,
"random") == 0) {
120 if (!f.has_value())
return;
122 fmt::print(*f,
"{}\n", message);
126 fmt::print(stderr,
"{}dbg: [{}:{}] {}\n",
GetLogPrefix(
true), category, level, message);
150 std::map<const char *, int> new_levels;
153 if (*s >=
'0' && *s <=
'9') {
154 v = std::strtoul(s, &end, 0);
157 for (
const auto &debug_level : _debug_levels) {
158 new_levels[debug_level.name] = v;
165 while (*s ==
' ' || *s ==
',' || *s ==
'\t') s++;
166 if (*s ==
'\0')
break;
169 while (*s >=
'a' && *s <=
'z') s++;
173 for (
const auto &debug_level : _debug_levels) {
174 if (s == t + strlen(debug_level.name) && strncmp(t, debug_level.name, s - t) == 0) {
175 found = &debug_level;
181 v = std::strtoul(s, &end, 0);
183 if (found !=
nullptr) {
184 new_levels[found->name] = v;
186 std::string error_string = fmt::format(
"Unknown debug level '{}'", std::string(t, s - t));
187 error_func(error_string);
193 for (
const auto &debug_level : _debug_levels) {
194 const auto &nl = new_levels.find(debug_level.name);
195 if (nl != new_levels.end()) {
196 *debug_level.level = nl->second;
209 for (
const auto &debug_level : _debug_levels) {
210 if (!result.empty()) result +=
", ";
211 fmt::format_to(std::back_inserter(result),
"{}={}", debug_level.name, *debug_level.level);
226 std::string log_prefix;
228 log_prefix = fmt::format(
"[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(
nullptr)));
Class for handling the server side of the game connection.
static Pool::IterateWrapperFiltered< ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter > IterateActive(size_t from=0)
Returns an iterable ensemble of all active admin sockets.
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.
Console functions used outside of the console code.
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.
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.
void DebugReconsiderSendRemoteMessages()
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
std::atomic< bool > _debug_remote_console
Whether we need to send data to either NetworkAdminConsole or IConsolePrint.
void SetDebugString(const char *s, void(*error_func)(const std::string &))
Set debugging levels by parsing the text in s.
void DumpDebugFacilityNames(std::back_insert_iterator< std::string > &output_iterator)
Dump the available debug facility names in the help text.
std::vector< QueuedDebugItem > _debug_remote_console_queue_spare
Spare queue to swap with _debug_remote_console_queue.
std::string GetDebugString()
Print out the current debug-level.
void DebugSendRemoteMessages()
Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop threa...
Functions related to debugging.
std::optional< FileHandle > FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Functions for Standard In/Out file operations.
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
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).
Server part of the admin network protocol.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
GUISettings gui
settings related to the GUI
bool show_date_in_logs
whether to show dates in console logs
uint8_t developer
print non-fatal warnings in console (>= 1), copy debug output to console (== 2)
Element in the queue of debug messages that have to be passed to either NetworkAdminConsole or IConso...
std::string level
The used debug level.
std::string message
The actual formatted message.
@ ADMIN_FREQUENCY_AUTOMATIC
The admin gets information about this when it changes.
@ ADMIN_UPDATE_CONSOLE
The admin would like to have console messages.
declarations of functions for MS windows systems
std::mutex lock
synchronization for playback status fields