23#include "3rdparty/fmt/chrono.h"
39int _debug_driver_level;
44int _debug_sprite_level;
45int _debug_oldloader_level;
47int _debug_fontcache_level;
48int _debug_script_level;
50int _debug_gamelog_level;
51int _debug_desync_level;
52int _debug_console_level;
54int _debug_random_level;
58 std::string_view name;
62#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
63static const std::initializer_list<DebugLevel> _debug_levels{
70 DEBUG_LEVEL(oldloader),
72 DEBUG_LEVEL(fontcache),
91 for (
const auto &debug_level : _debug_levels) {
93 fmt::format_to(output_iterator,
"List of debug facility names:\n");
95 fmt::format_to(output_iterator,
", ");
97 fmt::format_to(output_iterator,
"{}", debug_level.name);
101 fmt::format_to(output_iterator,
"\n\n");
110void DebugPrint(std::string_view category,
int level, std::string &&message)
112 if (category ==
"desync" && level != 0) {
114 if (!f.has_value())
return;
119 }
else if (category ==
"random") {
121 if (!f.has_value())
return;
123 fmt::print(*f,
"{}\n", message);
127 fmt::print(stderr,
"{}dbg: [{}:{}] {}\n",
GetLogPrefix(
true), category, level, message);
110void DebugPrint(std::string_view category,
int level, std::string &&message) {
…}
149 std::map<std::string_view, int> new_levels;
153 if (level.has_value()) {
154 for (
const auto &debug_level : _debug_levels) {
155 new_levels[debug_level.name] = *level;
159 static const std::string_view lowercase_letters{
"abcdefghijklmnopqrstuvwxyz"};
160 static const std::string_view lowercase_letters_and_digits{
"abcdefghijklmnopqrstuvwxyz0123456789"};
163 while (consumer.AnyBytesLeft()) {
164 consumer.SkipUntilCharIn(lowercase_letters);
165 if (!consumer.AnyBytesLeft())
break;
168 std::string_view key = consumer.ReadUntilCharNotIn(lowercase_letters);
169 auto it = std::ranges::find(_debug_levels, key, &DebugLevel::name);
170 if (it == std::end(_debug_levels)) {
171 error_func(fmt::format(
"Unknown debug level '{}'", key));
177 consumer.SkipUntilCharIn(lowercase_letters_and_digits);
178 level = consumer.TryReadIntegerBase<
int>(10);
179 if (!level.has_value()) {
180 error_func(fmt::format(
"Level for '{}' must be a valid integer.", key));
184 new_levels[it->name] = *level;
188 for (
const auto &debug_level : _debug_levels) {
189 const auto &nl = new_levels.find(debug_level.name);
190 if (nl != new_levels.end()) {
191 *debug_level.level = nl->second;
204 for (
const auto &debug_level : _debug_levels) {
205 if (!result.empty()) result +=
", ";
206 format_append(result,
"{}={}", debug_level.name, *debug_level.level);
221 std::string log_prefix;
223 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.
Parse data from a string / buffer.
std::optional< T > TryReadIntegerBase(int base, bool clamp=false)
Try to read and parse an integer in number 'base', and then advance the reader.
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 SetDebugString(std::string_view s, SetDebugStringErrorFunc error_func)
Set debugging levels by parsing the text in s.
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 DebugPrint(std::string_view category, int level, std::string &&message)
Internal function for outputting the debug line.
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(std::string_view filename, std::string_view 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(std::string_view origin, 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_view level
The used debug level.
std::string message
The actual formatted message.
@ ADMIN_UPDATE_CONSOLE
The admin would like to have console messages.
@ Automatic
The admin gets information about this when it changes.
declarations of functions for MS windows systems
std::mutex lock
synchronization for playback status fields