mirror of https://github.com/OpenTTD/OpenTTD.git
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
|
-mnull
|
||||||
-vnull:ticks=30000
|
-vnull:ticks=30000
|
||||||
-d script=2
|
-d script=2
|
||||||
-d misc=9
|
|
||||||
-Q
|
-Q
|
||||||
OUTPUT_VARIABLE REGRESSION_OUTPUT
|
OUTPUT_VARIABLE REGRESSION_OUTPUT
|
||||||
ERROR_VARIABLE REGRESSION_RESULT
|
ERROR_VARIABLE REGRESSION_RESULT
|
||||||
|
@ -58,10 +57,13 @@ string(REPLACE "0x0x0" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||||
string(REPLACE "\\" "/" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
string(REPLACE "\\" "/" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||||
|
|
||||||
# Remove timestamps if any
|
# 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
|
# 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 "\n " "\nERROR: " REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||||
string(REPLACE "\nERROR: [1] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
string(REPLACE "\nERROR: [1] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||||
string(REPLACE "\n[P] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
string(REPLACE "\n[P] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
--TestInit--
|
--TestInit--
|
||||||
Ops: 9988
|
Ops: 9988
|
||||||
TickTest: 1
|
TickTest: 1
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
--StationList--
|
--StationList--
|
||||||
Count(): 5
|
Count(): 5
|
||||||
Location ListDump:
|
Location ListDump:
|
||||||
|
|
|
@ -108,16 +108,16 @@ void DumpDebugFacilityNames(std::back_insert_iterator<std::string> &output_itera
|
||||||
* @param level Debug category.
|
* @param level Debug category.
|
||||||
* @param message The message to output.
|
* @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);
|
static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
|
||||||
if (f == nullptr) return;
|
if (f == nullptr) return;
|
||||||
|
|
||||||
fmt::print(f, "{}{}\n", GetLogPrefix(), message);
|
fmt::print(f, "{}{}\n", GetLogPrefix(true), message);
|
||||||
fflush(f);
|
fflush(f);
|
||||||
#ifdef RANDOM_DEBUG
|
#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);
|
static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
|
||||||
if (f == nullptr) return;
|
if (f == nullptr) return;
|
||||||
|
|
||||||
|
@ -125,12 +125,12 @@ void DebugPrint(const char *level, const std::string &message)
|
||||||
fflush(f);
|
fflush(f);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
fmt::print(stderr, "{}dbg: [{}] {}\n", GetLogPrefix(), level, message);
|
fmt::print(stderr, "{}dbg: [{}:{}] {}\n", GetLogPrefix(true), category, level, message);
|
||||||
|
|
||||||
if (_debug_remote_console.load()) {
|
if (_debug_remote_console.load()) {
|
||||||
/* Only add to the queue when there is at least one consumer of the data. */
|
/* 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);
|
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.
|
* the date, otherwise it returns an empty string.
|
||||||
|
*
|
||||||
* @return the prefix for logs.
|
* @return the prefix for logs.
|
||||||
*/
|
*/
|
||||||
std::string GetLogPrefix()
|
std::string GetLogPrefix(bool force)
|
||||||
{
|
{
|
||||||
std::string log_prefix;
|
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)));
|
log_prefix = fmt::format("[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(nullptr)));
|
||||||
}
|
}
|
||||||
return log_prefix;
|
return log_prefix;
|
||||||
|
|
|
@ -30,12 +30,12 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ouptut a line of debugging information.
|
* 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 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.
|
* @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__))
|
#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 *level, const std::string &message);
|
void DebugPrint(const char *category, int level, const std::string &message);
|
||||||
|
|
||||||
extern int _debug_driver_level;
|
extern int _debug_driver_level;
|
||||||
extern int _debug_grf_level;
|
extern int _debug_grf_level;
|
||||||
|
@ -99,7 +99,7 @@ struct TicToc {
|
||||||
void ShowInfoI(const std::string &str);
|
void ShowInfoI(const std::string &str);
|
||||||
#define ShowInfo(format_string, ...) ShowInfoI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__))
|
#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 DebugSendRemoteMessages();
|
||||||
void DebugReconsiderSendRemoteMessages();
|
void DebugReconsiderSendRemoteMessages();
|
||||||
|
|
Loading…
Reference in New Issue