mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
Change: forcefully enable prefixing logs with date (#11930)
Additionally, add the log-level to the log message.
This commit is contained in:
parent
41f2eed425
commit
46b1114c67
@ -34,7 +34,6 @@ execute_process(COMMAND ${OPENTTD_EXECUTABLE}
|
||||
-mnull
|
||||
-vnull:ticks=30000
|
||||
-d script=2
|
||||
-d misc=9
|
||||
-Q
|
||||
OUTPUT_VARIABLE REGRESSION_OUTPUT
|
||||
ERROR_VARIABLE REGRESSION_RESULT
|
||||
@ -58,10 +57,13 @@ string(REPLACE "0x0x0" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
string(REPLACE "\\" "/" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
|
||||
# Remove timestamps if any
|
||||
string(REGEX REPLACE "\[[0-9-]+ [0-9:]+\] " "" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
string(REGEX REPLACE "\\\[[0-9-]+ [0-9:]+\\\] " "" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
|
||||
# Remove log level
|
||||
string(REGEX REPLACE "\\\[script:[0-9]\\\]" "" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
|
||||
# Convert the output to a format that is expected (and more readable) by result.txt
|
||||
string(REPLACE "\ndbg: [script]" "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
string(REPLACE "\ndbg: " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
string(REPLACE "\n " "\nERROR: " REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
string(REPLACE "\nERROR: [1] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
string(REPLACE "\n[P] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
--TestInit--
|
||||
Ops: 9988
|
||||
TickTest: 1
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
--StationList--
|
||||
Count(): 5
|
||||
Location ListDump:
|
||||
|
@ -108,16 +108,16 @@ void DumpDebugFacilityNames(std::back_insert_iterator<std::string> &output_itera
|
||||
* @param level Debug category.
|
||||
* @param message The message to output.
|
||||
*/
|
||||
void DebugPrint(const char *level, const std::string &message)
|
||||
void DebugPrint(const char *category, int level, const std::string &message)
|
||||
{
|
||||
if (strcmp(level, "desync") == 0) {
|
||||
if (strcmp(category, "desync") == 0) {
|
||||
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
|
||||
if (f == nullptr) return;
|
||||
|
||||
fmt::print(f, "{}{}\n", GetLogPrefix(), message);
|
||||
fmt::print(f, "{}{}\n", GetLogPrefix(true), message);
|
||||
fflush(f);
|
||||
#ifdef RANDOM_DEBUG
|
||||
} else if (strcmp(level, "random") == 0) {
|
||||
} else if (strcmp(category, "random") == 0) {
|
||||
static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
|
||||
if (f == nullptr) return;
|
||||
|
||||
@ -125,12 +125,12 @@ void DebugPrint(const char *level, const std::string &message)
|
||||
fflush(f);
|
||||
#endif
|
||||
} else {
|
||||
fmt::print(stderr, "{}dbg: [{}] {}\n", GetLogPrefix(), level, message);
|
||||
fmt::print(stderr, "{}dbg: [{}:{}] {}\n", GetLogPrefix(true), category, level, message);
|
||||
|
||||
if (_debug_remote_console.load()) {
|
||||
/* Only add to the queue when there is at least one consumer of the data. */
|
||||
std::lock_guard<std::mutex> lock(_debug_remote_console_mutex);
|
||||
_debug_remote_console_queue.push_back({ level, message });
|
||||
_debug_remote_console_queue.push_back({ category, message });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,14 +218,17 @@ std::string GetDebugString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the prefix for logs; if show_date_in_logs is enabled it returns
|
||||
* Get the prefix for logs.
|
||||
*
|
||||
* If show_date_in_logs or \p force is enabled it returns
|
||||
* the date, otherwise it returns an empty string.
|
||||
*
|
||||
* @return the prefix for logs.
|
||||
*/
|
||||
std::string GetLogPrefix()
|
||||
std::string GetLogPrefix(bool force)
|
||||
{
|
||||
std::string log_prefix;
|
||||
if (_settings_client.gui.show_date_in_logs) {
|
||||
if (force || _settings_client.gui.show_date_in_logs) {
|
||||
log_prefix = fmt::format("[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(nullptr)));
|
||||
}
|
||||
return log_prefix;
|
||||
|
@ -30,12 +30,12 @@
|
||||
|
||||
/**
|
||||
* Ouptut a line of debugging information.
|
||||
* @param name The category of debug information.
|
||||
* @param category The category of debug information.
|
||||
* @param level The maximum debug level this message should be shown at. When the debug level for this category is set lower, then the message will not be shown.
|
||||
* @param format_string The formatting string of the message.
|
||||
*/
|
||||
#define Debug(name, level, format_string, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) DebugPrint(#name, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
|
||||
void DebugPrint(const char *level, const std::string &message);
|
||||
#define Debug(category, level, format_string, ...) if ((level) == 0 || _debug_ ## category ## _level >= (level)) DebugPrint(#category, level, fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
|
||||
void DebugPrint(const char *category, int level, const std::string &message);
|
||||
|
||||
extern int _debug_driver_level;
|
||||
extern int _debug_grf_level;
|
||||
@ -99,7 +99,7 @@ struct TicToc {
|
||||
void ShowInfoI(const std::string &str);
|
||||
#define ShowInfo(format_string, ...) ShowInfoI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
|
||||
|
||||
std::string GetLogPrefix();
|
||||
std::string GetLogPrefix(bool force = false);
|
||||
|
||||
void DebugSendRemoteMessages();
|
||||
void DebugReconsiderSendRemoteMessages();
|
||||
|
Loading…
Reference in New Issue
Block a user