|
OpenTTD Source 20260911-master-gee2b2ac12a
|
Handling of printing debug messages. More...
#include "stdafx.h"#include "core/string_consumer.hpp"#include "console_func.h"#include "debug.h"#include "string_func.h"#include "fileio_func.h"#include "settings_type.h"#include <mutex>#include "3rdparty/fmt/chrono.h"#include "network/network_admin.h"#include "safeguards.h"Go to the source code of this file.
Data Structures | |
| struct | QueuedDebugItem |
| Element in the queue of debug messages that have to be passed to either NetworkAdminConsole or IConsolePrint. More... | |
Functions | |
| void | DumpDebugFacilityNames (std::back_insert_iterator< std::string > &output_iterator) |
| Dump the available debug facility names in the help text. | |
| void | DebugPrint (Facility facility, Severity severity, std::string &&message) |
| Internal function for outputting the debug line. | |
| void | SetDebugString (std::string_view s, SetDebugStringErrorFunc error_func) |
| Set debugging levels by parsing the text in s. | |
| std::string | GetDebugString () |
| Print out the current debug-level. | |
| std::string | GetLogPrefix (bool force) |
| Get the prefix for logs. | |
| void | DebugSendRemoteMessages () |
| Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop thread to prevent concurrent accesses to both the NetworkAdmin's packet queue as well as IConsolePrint's buffers. | |
| void | DebugReconsiderSendRemoteMessages () |
| Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint. | |
Variables | |
| std::atomic< bool > | _debug_remote_console |
| Whether we need to send data to either NetworkAdminConsole or IConsolePrint. | |
| std::mutex | _debug_remote_console_mutex |
| Mutex to guard the queue of debug messages for either NetworkAdminConsole or IConsolePrint. | |
| std::vector< QueuedDebugItem > | _debug_remote_console_queue |
| Queue for debug messages to be passed to NetworkAdminConsole or IConsolePrint. | |
| std::vector< QueuedDebugItem > | _debug_remote_console_queue_spare |
| Spare queue to swap with _debug_remote_console_queue. | |
| EnumIndexArray< Severity, Facility, Facility::End > | _debug_level |
| Severity level for each debug facility. | |
| static EnumIndexArray< std::string_view, Facility, Facility::End > | _debug_facilities |
| Name for each debug facility. | |
Handling of printing debug messages.
Definition in file debug.cpp.
Internal function for outputting the debug line.
| facility | The facility category/classification of the debug message. |
| severity | The severity of the debug level; lower is more likely to be shown. |
| message | The message to output. |
Definition at line 88 of file debug.cpp.
References _debug_facilities, _debug_remote_console, _debug_remote_console_mutex, _debug_remote_console_queue, Autosave, Critical, Desync, FioFOpenFile(), GetLogPrefix(), lock, and Random.
Referenced by StringConsumer::LogError().
| void DebugReconsiderSendRemoteMessages | ( | ) |
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
The former is when they have enabled console handling whereas the latter depends on the gui.developer setting's value.
This is to be called from the GameLoop thread.
Definition at line 231 of file debug.cpp.
References _debug_remote_console, _settings_client, Automatic, Console, and ServerNetworkAdminSocketHandler::IterateActive().
Referenced by LoadFromConfig(), ServerNetworkAdminSocketHandler::ReceiveAdminUpdateFrequency(), and ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler().
| void DebugSendRemoteMessages | ( | ) |
Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop thread to prevent concurrent accesses to both the NetworkAdmin's packet queue as well as IConsolePrint's buffers.
This is to be called from the GameLoop thread.
Definition at line 207 of file debug.cpp.
References _debug_facilities, _debug_remote_console, _debug_remote_console_mutex, _debug_remote_console_queue, _debug_remote_console_queue_spare, _settings_client, CC_DEBUG, IConsolePrint(), lock, and NetworkAdminConsole().
| void DumpDebugFacilityNames | ( | std::back_insert_iterator< std::string > & | output_iterator | ) |
Dump the available debug facility names in the help text.
| output_iterator | The iterator to write the string to. |
Definition at line 65 of file debug.cpp.
References _debug_facilities, and End.
Referenced by ShowHelp().
| std::string GetDebugString | ( | ) |
Print out the current debug-level.
Just return a string with the values of all the debug categories.
Definition at line 172 of file debug.cpp.
References _debug_facilities, _debug_level, and End.
Referenced by ConDebugLevel().
| std::string GetLogPrefix | ( | bool | force | ) |
Get the prefix for logs.
If show_date_in_logs or force is enabled it returns the date, otherwise it returns an empty string.
| force | Whether to force the prefix on. |
Definition at line 191 of file debug.cpp.
References _settings_client.
Referenced by DebugPrint(), and IConsolePrint().
| void SetDebugString | ( | std::string_view | s, |
| SetDebugStringErrorFunc | error_func ) |
Set debugging levels by parsing the text in s.
For setting individual levels a string like "net=3,grf=6" should be used. If the string starts with a number, the number is used as global debugging level.
| s | Text describing the wanted debugging levels. |
| error_func | The function to call if a parse error occurs. |
Definition at line 122 of file debug.cpp.
References _debug_facilities, _debug_level, StringConsumer::AnyBytesLeft(), StringConsumer::ReadUntilCharNotIn(), StringConsumer::SkipUntilCharIn(), and StringConsumer::TryReadIntegerBase().
Referenced by ConDebugLevel(), and openttd_main().
|
static |
Name for each debug facility.
Definition at line 43 of file debug.cpp.
Referenced by DebugPrint(), DebugSendRemoteMessages(), DumpDebugFacilityNames(), GetDebugString(), and SetDebugString().
| EnumIndexArray<Severity, Facility, Facility::End> _debug_level |
Severity level for each debug facility.
Definition at line 40 of file debug.cpp.
Referenced by GetDebugString(), IsVisibleSeverity(), and SetDebugString().
| std::atomic<bool> _debug_remote_console |
Whether we need to send data to either NetworkAdminConsole or IConsolePrint.
Definition at line 34 of file debug.cpp.
Referenced by DebugPrint(), DebugReconsiderSendRemoteMessages(), and DebugSendRemoteMessages().
| std::mutex _debug_remote_console_mutex |
Mutex to guard the queue of debug messages for either NetworkAdminConsole or IConsolePrint.
Definition at line 35 of file debug.cpp.
Referenced by DebugPrint(), and DebugSendRemoteMessages().
| std::vector<QueuedDebugItem> _debug_remote_console_queue |
Queue for debug messages to be passed to NetworkAdminConsole or IConsolePrint.
Definition at line 36 of file debug.cpp.
Referenced by DebugPrint(), and DebugSendRemoteMessages().
| std::vector<QueuedDebugItem> _debug_remote_console_queue_spare |
Spare queue to swap with _debug_remote_console_queue.
Definition at line 37 of file debug.cpp.
Referenced by DebugSendRemoteMessages().