Changeset - r28620:953e949c2631
[Not reviewed]
master
0 5 0
Patric Stout - 3 months ago 2024-01-30 22:02:16
truebrain@openttd.org
Change: forcefully enable prefixing logs with date (#11930)

Additionally, add the log-level to the log message.
5 files changed with 21 insertions and 18 deletions:
0 comments (0 inline, 0 general)
cmake/scripts/Regression.cmake
Show inline comments
 
@@ -34,7 +34,6 @@ execute_process(COMMAND ${OPENTTD_EXECUT
 
                        -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" REGR
 
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}")
regression/regression/result.txt
Show inline comments
 

	
 
--TestInit--
 
 Ops:      9988
 
 TickTest: 1
regression/stationlist/result.txt
Show inline comments
 

	
 
--StationList--
 
  Count():             5
 
  Location ListDump:
src/debug.cpp
Show inline comments
 
@@ -108,16 +108,16 @@ void DumpDebugFacilityNames(std::back_in
 
 * @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
 
		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;
src/debug.h
Show inline comments
 
@@ -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();
0 comments (0 inline, 0 general)