Daniele Bartolini 10 ani în urmă
părinte
comite
cc20ee4634
3 a modificat fișierele cu 32 adăugiri și 38 ștergeri
  1. 0 34
      src/console_server.cpp
  2. 0 3
      src/console_server.h
  3. 32 1
      src/core/log.cpp

+ 0 - 34
src/console_server.cpp

@@ -44,40 +44,6 @@ void ConsoleServer::shutdown()
 	_server.close();
 }
 
-namespace console_server_internal
-{
-	StringStream& sanitize(StringStream& ss, const char* msg)
-	{
-		using namespace string_stream;
-		const char* ch = msg;
-		for (; *ch; ch++)
-		{
-			if (*ch == '"')
-				ss << "\\";
-			ss << *ch;
-		}
-
-		return ss;
-	}
-}
-
-void ConsoleServer::log(const char* msg, LogSeverity::Enum severity)
-{
-	using namespace string_stream;
-	using namespace console_server_internal;
-	static const char* stt[] = { "info", "warning", "error", "debug" };
-
-	// Build json message
-	TempAllocator2048 alloc;
-	StringStream json(alloc);
-
-	json << "{\"type\":\"message\",";
-	json << "\"severity\":\"" << stt[severity] << "\",";
-	json << "\"message\":\""; sanitize(json, msg) << "\"}";
-
-	send(c_str(json));
-}
-
 void ConsoleServer::send(TCPSocket client, const char* json)
 {
 	uint32_t len = strlen(json);

+ 0 - 3
src/console_server.h

@@ -7,7 +7,6 @@
 
 #include "container_types.h"
 #include "socket.h"
-#include "log.h"
 
 namespace crown
 {
@@ -21,8 +20,6 @@ public:
 	ConsoleServer(uint16_t port, bool wait);
 	void shutdown();
 
-	void log(const char* msg, LogSeverity::Enum severity = LogSeverity::INFO);
-
 	/// Collects requests from clients and processes them all.
 	void update();
 

+ 32 - 1
src/core/log.cpp

@@ -7,6 +7,7 @@
 #include "console_server.h"
 #include "string_utils.h"
 #include "os.h"
+#include "string_stream.h"
 
 #if CROWN_DEBUG
 
@@ -14,6 +15,36 @@ namespace crown
 {
 namespace log_internal
 {
+	StringStream& sanitize(StringStream& ss, const char* msg)
+	{
+		using namespace string_stream;
+		const char* ch = msg;
+		for (; *ch; ch++)
+		{
+			if (*ch == '"')
+				ss << "\\";
+			ss << *ch;
+		}
+
+		return ss;
+	}
+
+	void console_log(const char* msg, LogSeverity::Enum severity)
+	{
+		using namespace string_stream;
+		static const char* stt[] = { "info", "warning", "error", "debug" };
+
+		// Build json message
+		TempAllocator2048 alloc;
+		StringStream json(alloc);
+
+		json << "{\"type\":\"message\",";
+		json << "\"severity\":\"" << stt[severity] << "\",";
+		json << "\"message\":\""; sanitize(json, msg) << "\"}";
+
+		console_server_globals::console().send(c_str(json));
+	}
+
 	void logx(LogSeverity::Enum sev, const char* msg, va_list args)
 	{
 		char buf[2048];
@@ -22,7 +53,7 @@ namespace log_internal
 			len = sizeof(buf) - 1;
 
 		buf[len] = '\0';
-		console_server_globals::console().log(buf, sev);
+		console_log(buf, sev);
 		os::log(buf);
 	}