Daniele Bartolini 11 лет назад
Родитель
Сommit
64dfe086e5
3 измененных файлов с 58 добавлено и 35 удалено
  1. 1 12
      engine/console_server.h
  2. 39 0
      engine/core/log.cpp
  3. 18 23
      engine/core/log.h

+ 1 - 12
engine/console_server.h

@@ -7,22 +7,11 @@
 
 #include "socket.h"
 #include "id_array.h"
+#include "log.h"
 
 namespace crown
 {
 
-/// Enumerates log levels.
-struct LogSeverity
-{
-	enum Enum
-	{
-		INFO	= 0,
-		WARN	= 1,
-		ERROR	= 2,
-		DEBUG	= 3
-	};
-};
-
 struct Client
 {
 	Id id;

+ 39 - 0
engine/core/log.cpp

@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
+ * License: https://github.com/taylor001/crown/blob/master/LICENSE
+ */
+
+#include "log.h"
+#include "console_server.h"
+#include "string_utils.h"
+#include "os.h"
+
+#if CROWN_DEBUG
+
+namespace crown
+{
+namespace log_internal
+{
+	void logx(LogSeverity::Enum sev, const char* msg, va_list args)
+	{
+		char buf[2048];
+		int len = vsnprintf(buf, sizeof(buf), msg, args);
+		if (len > (int)sizeof(buf))
+			len = sizeof(buf) - 1;
+
+		buf[len] = '\0';
+		console_server_globals::console().log(buf, sev);
+		os::log(buf);
+	}
+
+	void logx(LogSeverity::Enum sev, const char* msg, ...)
+	{
+		va_list args;
+		va_start(args, msg);
+		logx(sev, msg, args);
+		va_end(args);
+	}
+} // namespace log
+} // namespace crown
+
+#endif // CROWN_DEBUG

+ 18 - 23
engine/core/log.h

@@ -5,37 +5,32 @@
 
 #pragma once
 
-#if CROWN_DEBUG
-
-#include "console_server.h"
-#include "string_utils.h"
-#include "os.h"
+#include "config.h"
+#include <cstdarg>
 
 namespace crown
 {
-namespace log_internal
+
+/// Enumerates log levels.
+struct LogSeverity
 {
-	inline void logx(LogSeverity::Enum sev, const char* msg, va_list args)
+	enum Enum
 	{
-		char buf[2048];
-		int len = vsnprintf(buf, sizeof(buf), msg, args);
-		if (len > (int)sizeof(buf))
-			len = sizeof(buf) - 1;
-
-		buf[len] = '\0';
-		console_server_globals::console().log(buf, sev);
-		os::log(buf);
-	}
+		INFO	= 0,
+		WARN	= 1,
+		ERROR	= 2,
+		DEBUG	= 3
+	};
+};
 
-	inline void logx(LogSeverity::Enum sev, const char* msg, ...)
-	{
-		va_list args;
-		va_start(args, msg);
-		logx(sev, msg, args);
-		va_end(args);
-	}
+namespace log_internal
+{
+	void logx(LogSeverity::Enum sev, const char* msg, va_list args);
+	void logx(LogSeverity::Enum sev, const char* msg, ...);
 } // namespace log_internal
 } // namespace crown
+
+#if CROWN_DEBUG
 	#define CE_LOGI(msg, ...) crown::log_internal::logx(crown::LogSeverity::INFO, msg, ##__VA_ARGS__)
 	#define CE_LOGD(msg, ...) crown::log_internal::logx(crown::LogSeverity::DEBUG, msg, ##__VA_ARGS__)
 	#define CE_LOGE(msg, ...) crown::log_internal::logx(crown::LogSeverity::ERROR, msg, ##__VA_ARGS__)