diff --git a/cmake/scripts/Regression.cmake b/cmake/scripts/Regression.cmake index 909cee2137..7cf79359d7 100644 --- a/cmake/scripts/Regression.cmake +++ b/cmake/scripts/Regression.cmake @@ -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}") diff --git a/regression/regression/result.txt b/regression/regression/result.txt index f1d20754b0..57c8a400a9 100644 --- a/regression/regression/result.txt +++ b/regression/regression/result.txt @@ -1,4 +1,3 @@ - --TestInit-- Ops: 9988 TickTest: 1 diff --git a/regression/stationlist/result.txt b/regression/stationlist/result.txt index 20e594766f..c04a306358 100644 --- a/regression/stationlist/result.txt +++ b/regression/stationlist/result.txt @@ -1,4 +1,3 @@ - --StationList-- Count(): 5 Location ListDump: diff --git a/src/debug.cpp b/src/debug.cpp index fba8111dd6..7cc28e4280 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -108,16 +108,16 @@ void DumpDebugFacilityNames(std::back_insert_iterator &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 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; diff --git a/src/debug.h b/src/debug.h index a46bb8ec53..f3a9bf8a01 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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();