Browse Source

Minor changes in logging

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
f4700bec84
3 changed files with 21 additions and 43 deletions
  1. 7 4
      AnKi/Core/DeveloperConsole.cpp
  2. 4 3
      AnKi/Core/DeveloperConsole.h
  3. 10 36
      AnKi/Util/Logger.cpp

+ 7 - 4
AnKi/Core/DeveloperConsole.cpp

@@ -15,6 +15,7 @@ DeveloperConsole::~DeveloperConsole()
 	{
 	{
 		LogItem* item = &m_logItems.getFront();
 		LogItem* item = &m_logItems.getFront();
 		m_logItems.popFront();
 		m_logItems.popFront();
+		item->m_threadName.destroy(m_alloc);
 		item->m_msg.destroy(m_alloc);
 		item->m_msg.destroy(m_alloc);
 		m_alloc.deleteInstance(item);
 		m_alloc.deleteInstance(item);
 	}
 	}
@@ -71,10 +72,10 @@ void DeveloperConsole::build(CanvasPtr ctx)
 			ANKI_ASSERT(0);
 			ANKI_ASSERT(0);
 		}
 		}
 
 
-		static constexpr Array<const char*, U(LoggerMessageType::kCount)> kMsgText = {"I", "E", "W", "F"};
-		ImGui::TextWrapped("[%s][%s] %s (%s:%d %s)", kMsgText[item.m_type],
+		constexpr Array<const Char*, U(LoggerMessageType::kCount)> kMsgText = {"I", "E", "W", "F"};
+		ImGui::TextWrapped("[%s][%s] %s [%s:%d][%s][%s]", kMsgText[item.m_type],
 						   (item.m_subsystem) ? item.m_subsystem : "N/A ", item.m_msg.cstr(), item.m_file, item.m_line,
 						   (item.m_subsystem) ? item.m_subsystem : "N/A ", item.m_msg.cstr(), item.m_file, item.m_line,
-						   item.m_func);
+						   item.m_func, item.m_threadName.cstr());
 
 
 		ImGui::PopStyleColor();
 		ImGui::PopStyleColor();
 	}
 	}
@@ -93,7 +94,7 @@ void DeveloperConsole::build(CanvasPtr ctx)
 	// Commands
 	// Commands
 	ImGui::Separator();
 	ImGui::Separator();
 	ImGui::PushItemWidth(-1.0f); // Use the whole size
 	ImGui::PushItemWidth(-1.0f); // Use the whole size
-	if(ImGui::InputText("", &m_inputText[0], m_inputText.getSizeInBytes(), ImGuiInputTextFlags_EnterReturnsTrue,
+	if(ImGui::InputText("##noname", &m_inputText[0], m_inputText.getSizeInBytes(), ImGuiInputTextFlags_EnterReturnsTrue,
 						nullptr, nullptr))
 						nullptr, nullptr))
 	{
 	{
 		const Error err = m_scriptEnv.evalString(&m_inputText[0]);
 		const Error err = m_scriptEnv.evalString(&m_inputText[0]);
@@ -123,6 +124,7 @@ void DeveloperConsole::newLogItem(const LoggerMessageInfo& inf)
 		m_logItems.popFront();
 		m_logItems.popFront();
 
 
 		first->m_msg.destroy(m_alloc);
 		first->m_msg.destroy(m_alloc);
+		first->m_threadName.destroy(m_alloc);
 
 
 		// Re-use the log item
 		// Re-use the log item
 		newLogItem = first;
 		newLogItem = first;
@@ -137,6 +139,7 @@ void DeveloperConsole::newLogItem(const LoggerMessageInfo& inf)
 	newLogItem->m_file = inf.m_file;
 	newLogItem->m_file = inf.m_file;
 	newLogItem->m_func = inf.m_func;
 	newLogItem->m_func = inf.m_func;
 	newLogItem->m_subsystem = inf.m_subsystem;
 	newLogItem->m_subsystem = inf.m_subsystem;
+	newLogItem->m_threadName.create(m_alloc, inf.m_threadName);
 	newLogItem->m_msg.create(m_alloc, inf.m_msg);
 	newLogItem->m_msg.create(m_alloc, inf.m_msg);
 	newLogItem->m_line = inf.m_line;
 	newLogItem->m_line = inf.m_line;
 	newLogItem->m_type = inf.m_type;
 	newLogItem->m_type = inf.m_type;

+ 4 - 3
AnKi/Core/DeveloperConsole.h

@@ -36,9 +36,10 @@ private:
 	class LogItem : public IntrusiveListEnabled<LogItem>
 	class LogItem : public IntrusiveListEnabled<LogItem>
 	{
 	{
 	public:
 	public:
-		const char* m_file;
-		const char* m_func;
-		const char* m_subsystem;
+		const Char* m_file;
+		const Char* m_func;
+		const Char* m_subsystem;
+		String m_threadName;
 		String m_msg;
 		String m_msg;
 		I32 m_line;
 		I32 m_line;
 		LoggerMessageType m_type;
 		LoggerMessageType m_type;

+ 10 - 36
AnKi/Util/Logger.cpp

@@ -180,9 +180,9 @@ void Logger::defaultSystemMessageHandler(void*, const LoggerMessageInfo& info)
 		endTerminalColor = "";
 		endTerminalColor = "";
 	}
 	}
 
 
-	fprintf(out, "%s[%s][%s][%-15s]%s%s %s (%s:%d %s)%s\n", terminalColorBg, kMessageTypeTxt[U(info.m_type)],
-			info.m_subsystem ? info.m_subsystem : "N/A ", info.m_threadName, endTerminalColor, terminalColor,
-			info.m_msg, info.m_file, info.m_line, info.m_func, endTerminalColor);
+	fprintf(out, "%s[%s][%s]%s%s %s [%s:%d][%s][%s]%s\n", terminalColorBg, kMessageTypeTxt[U(info.m_type)],
+			info.m_subsystem ? info.m_subsystem : "N/A ", endTerminalColor, terminalColor, info.m_msg, info.m_file,
+			info.m_line, info.m_func, info.m_threadName, endTerminalColor);
 #elif ANKI_OS_WINDOWS
 #elif ANKI_OS_WINDOWS
 	WORD attribs = 0;
 	WORD attribs = 0;
 	FILE* out = nullptr;
 	FILE* out = nullptr;
@@ -227,10 +227,9 @@ void Logger::defaultSystemMessageHandler(void*, const LoggerMessageInfo& info)
 		SetConsoleTextAttribute(consoleHandle, attribs);
 		SetConsoleTextAttribute(consoleHandle, attribs);
 
 
 		// Print
 		// Print
-		static_assert(Thread::kThreadNameMaxLength == 15, "See file");
-		fprintf(out, "[%s][%-4s][%-15s] %s (%s:%d %s)\n", kMessageTypeTxt[info.m_type],
-				info.m_subsystem ? info.m_subsystem : "N/A", info.m_threadName, info.m_msg, info.m_file, info.m_line,
-				info.m_func);
+		fprintf(out, "[%s][%-4s] %s [%s:%d][%s][%s]\n", kMessageTypeTxt[info.m_type],
+				info.m_subsystem ? info.m_subsystem : "N/A", info.m_msg, info.m_file, info.m_line, info.m_func,
+				info.m_threadName);
 
 
 		// Restore state
 		// Restore state
 		SetConsoleTextAttribute(consoleHandle, savedAttribs);
 		SetConsoleTextAttribute(consoleHandle, savedAttribs);
@@ -258,36 +257,11 @@ void Logger::defaultSystemMessageHandler(void*, const LoggerMessageInfo& info)
 	}
 	}
 
 
 	static_assert(Thread::kThreadNameMaxLength == 15, "See file");
 	static_assert(Thread::kThreadNameMaxLength == 15, "See file");
-	__android_log_print(andMsgType, "AnKi", "[%s][%s][%-15s] %s (%s:%d %s)\n", kMessageTypeTxt[info.m_type],
-						info.m_subsystem ? info.m_subsystem : "N/A ", info.m_threadName, info.m_msg, info.m_file,
-						info.m_line, info.m_func);
+	__android_log_print(andMsgType, "AnKi", "[%s][%-4s] %s [%s:%d][%s][%s]\n", kMessageTypeTxt[info.m_type],
+						info.m_subsystem ? info.m_subsystem : "N/A ", info.m_msg, info.m_file, info.m_line, info.m_func,
+						info.m_threadName);
 #else
 #else
-	FILE* out = NULL;
-
-	switch(info.m_type)
-	{
-	case LoggerMessageType::kNormal:
-	case LoggerMessageType::kVerbose:
-		out = stdout;
-		break;
-	case LoggerMessageType::kError:
-		out = stderr;
-		break;
-	case LoggerMessageType::kWarning:
-		out = stderr;
-		break;
-	case LoggerMessageType::kFatal:
-		out = stderr;
-		break;
-	default:
-		ANKI_ASSERT(0);
-	}
-
-	fprintf(out, "[%s][%s][%" PRIx64 "] %s (%s:%d %s)\n", kMessageTypeTxt[info.m_type],
-			info.m_subsystem ? info.m_subsystem : "N/A ", info.m_tid, info.m_msg, info.m_file, info.m_line,
-			info.m_func);
-
-	fflush(out);
+#	error "Not implemented"
 #endif
 #endif
 }
 }