Quellcode durchsuchen

Add another new log level (TRACE) for verbose tracing.
Close #2163.

Yao Wei Tjong 姚伟忠 vor 8 Jahren
Ursprung
Commit
949af7adc7

+ 8 - 0
Source/Urho3D/AngelScript/IOAPI.cpp

@@ -98,6 +98,11 @@ static void LogWrite(const String& str, bool error, Log* ptr)
     Log::WriteRaw(str + "\n", error);
     Log::WriteRaw(str + "\n", error);
 }
 }
 
 
+static void LogTrace(const String& str, Log* ptr)
+{
+    Log::Write(LOG_TRACE, str);
+}
+
 static void LogDebug(const String& str, Log* ptr)
 static void LogDebug(const String& str, Log* ptr)
 {
 {
     Log::Write(LOG_DEBUG, str);
     Log::Write(LOG_DEBUG, str);
@@ -130,6 +135,7 @@ static void Print(bool value, bool error) { }
 static void Print(const Variant& value, bool error) { }
 static void Print(const Variant& value, bool error) { }
 static void PrintCallStack(bool error) { }
 static void PrintCallStack(bool error) { }
 static void LogWrite(const String& str, bool error, Log* ptr) { }
 static void LogWrite(const String& str, bool error, Log* ptr) { }
+static void LogTrace(const String& str, Log* ptr) { }
 static void LogDebug(const String& str, Log* ptr) { }
 static void LogDebug(const String& str, Log* ptr) { }
 static void LogInfo(const String& str, Log* ptr) { }
 static void LogInfo(const String& str, Log* ptr) { }
 static void LogWarning(const String& str, Log* ptr) { }
 static void LogWarning(const String& str, Log* ptr) { }
@@ -139,6 +145,7 @@ static void LogError(const String& str, Log* ptr) { }
 
 
 static void RegisterLog(asIScriptEngine* engine)
 static void RegisterLog(asIScriptEngine* engine)
 {
 {
+    engine->RegisterGlobalProperty("const int LOG_TRACE", (void*)&LOG_TRACE);
     engine->RegisterGlobalProperty("const int LOG_DEBUG", (void*)&LOG_DEBUG);
     engine->RegisterGlobalProperty("const int LOG_DEBUG", (void*)&LOG_DEBUG);
     engine->RegisterGlobalProperty("const int LOG_INFO", (void*)&LOG_INFO);
     engine->RegisterGlobalProperty("const int LOG_INFO", (void*)&LOG_INFO);
     engine->RegisterGlobalProperty("const int LOG_WARNING", (void*)&LOG_WARNING);
     engine->RegisterGlobalProperty("const int LOG_WARNING", (void*)&LOG_WARNING);
@@ -149,6 +156,7 @@ static void RegisterLog(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Log", "void Open(const String&in)", asMETHOD(Log, Open), asCALL_THISCALL);
     engine->RegisterObjectMethod("Log", "void Open(const String&in)", asMETHOD(Log, Open), asCALL_THISCALL);
     engine->RegisterObjectMethod("Log", "void Close()", asMETHOD(Log, Close), asCALL_THISCALL);
     engine->RegisterObjectMethod("Log", "void Close()", asMETHOD(Log, Close), asCALL_THISCALL);
     engine->RegisterObjectMethod("Log", "void Write(const String&in, bool error = false)", asFUNCTION(LogWrite), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Write(const String&in, bool error = false)", asFUNCTION(LogWrite), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Log", "void Trace(const String&in)", asFUNCTION(LogTrace), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Debug(const String&in)", asFUNCTION(LogDebug), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Debug(const String&in)", asFUNCTION(LogDebug), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Info(const String&in)", asFUNCTION(LogInfo), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Info(const String&in)", asFUNCTION(LogInfo), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Warning(const String&in)", asFUNCTION(LogWarning), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Log", "void Warning(const String&in)", asFUNCTION(LogWarning), asCALL_CDECL_OBJLAST);

+ 2 - 2
Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -1890,7 +1890,7 @@ void Graphics::OnWindowMoved()
     position_.x_ = newX;
     position_.x_ = newX;
     position_.y_ = newY;
     position_.y_ = newY;
 
 
-    URHO3D_LOGDEBUGF("Window was moved to %d,%d", position_.x_, position_.y_);
+    URHO3D_LOGTRACEF("Window was moved to %d,%d", position_.x_, position_.y_);
 
 
     using namespace WindowPos;
     using namespace WindowPos;
 
 
@@ -2104,7 +2104,7 @@ void Graphics::AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen,
             SDL_MaximizeWindow(window_);
             SDL_MaximizeWindow(window_);
             SDL_GetWindowSize(window_, &newWidth, &newHeight);
             SDL_GetWindowSize(window_, &newWidth, &newHeight);
         }
         }
-        else 
+        else
         {
         {
             SDL_Rect display_rect;
             SDL_Rect display_rect;
             SDL_GetDisplayBounds(monitor, &display_rect);
             SDL_GetDisplayBounds(monitor, &display_rect);

+ 1 - 1
Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -2140,7 +2140,7 @@ void Graphics::OnWindowMoved()
     position_.x_ = newX;
     position_.x_ = newX;
     position_.y_ = newY;
     position_.y_ = newY;
 
 
-    URHO3D_LOGDEBUGF("Window was moved to %d,%d", position_.x_, position_.y_);
+    URHO3D_LOGTRACEF("Window was moved to %d,%d", position_.x_, position_.y_);
 
 
     using namespace WindowPos;
     using namespace WindowPos;
 
 

+ 2 - 2
Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp

@@ -2108,7 +2108,7 @@ PODVector<int> Graphics::GetMultiSampleLevels() const
     for (int i = 2; i <= maxSamples && i <= 16; i *= 2)
     for (int i = 2; i <= maxSamples && i <= 16; i *= 2)
         ret.Push(i);
         ret.Push(i);
 #endif
 #endif
-    
+
     return ret;
     return ret;
 }
 }
 
 
@@ -2301,7 +2301,7 @@ void Graphics::OnWindowMoved()
     position_.x_ = newX;
     position_.x_ = newX;
     position_.y_ = newY;
     position_.y_ = newY;
 
 
-    URHO3D_LOGDEBUGF("Window was moved to %d,%d", position_.x_, position_.y_);
+    URHO3D_LOGTRACEF("Window was moved to %d,%d", position_.x_, position_.y_);
 
 
     using namespace WindowPos;
     using namespace WindowPos;
 
 

+ 4 - 3
Source/Urho3D/IO/Log.cpp

@@ -47,6 +47,7 @@ namespace Urho3D
 
 
 const char* logLevelPrefixes[] =
 const char* logLevelPrefixes[] =
 {
 {
+    "TRACE",
     "DEBUG",
     "DEBUG",
     "INFO",
     "INFO",
     "WARNING",
     "WARNING",
@@ -115,7 +116,7 @@ void Log::Close()
 
 
 void Log::SetLevel(int level)
 void Log::SetLevel(int level)
 {
 {
-    if (level < LOG_DEBUG || level > LOG_NONE)
+    if (level < LOG_TRACE || level > LOG_NONE)
     {
     {
         URHO3D_LOGERRORF("Attempted to set erroneous log level %d", level);
         URHO3D_LOGERRORF("Attempted to set erroneous log level %d", level);
         return;
         return;
@@ -144,7 +145,7 @@ void Log::Write(int level, const String& message)
     }
     }
 
 
     // No-op if illegal level
     // No-op if illegal level
-    if (level < LOG_DEBUG || level >= LOG_NONE)
+    if (level < LOG_TRACE || level >= LOG_NONE)
         return;
         return;
 
 
     // If not in the main thread, store message for later processing
     // If not in the main thread, store message for later processing
@@ -171,7 +172,7 @@ void Log::Write(int level, const String& message)
         formattedMessage = "[" + Time::GetTimeStamp() + "] " + formattedMessage;
         formattedMessage = "[" + Time::GetTimeStamp() + "] " + formattedMessage;
 
 
 #if defined(__ANDROID__)
 #if defined(__ANDROID__)
-    int androidLevel = ANDROID_LOG_DEBUG + level;
+    int androidLevel = ANDROID_LOG_VERBOSE + level;
     __android_log_print(androidLevel, "Urho3D", "%s", message.CString());
     __android_log_print(androidLevel, "Urho3D", "%s", message.CString());
 #elif defined(IOS) || defined(TVOS)
 #elif defined(IOS) || defined(TVOS)
     SDL_IOS_LogMessage(message.CString());
     SDL_IOS_LogMessage(message.CString());

+ 11 - 5
Source/Urho3D/IO/Log.h

@@ -32,16 +32,18 @@ namespace Urho3D
 
 
 /// Fictional message level to indicate a stored raw message.
 /// Fictional message level to indicate a stored raw message.
 static const int LOG_RAW = -1;
 static const int LOG_RAW = -1;
+/// Trace message level.
+static const int LOG_TRACE = 0;
 /// Debug message level. By default only shown in debug mode.
 /// Debug message level. By default only shown in debug mode.
-static const int LOG_DEBUG = 0;
+static const int LOG_DEBUG = 1;
 /// Informative message level.
 /// Informative message level.
-static const int LOG_INFO = 1;
+static const int LOG_INFO = 2;
 /// Warning message level.
 /// Warning message level.
-static const int LOG_WARNING = 2;
+static const int LOG_WARNING = 3;
 /// Error message level.
 /// Error message level.
-static const int LOG_ERROR = 3;
+static const int LOG_ERROR = 4;
 /// Disable all log messages.
 /// Disable all log messages.
-static const int LOG_NONE = 4;
+static const int LOG_NONE = 5;
 
 
 class File;
 class File;
 
 
@@ -131,22 +133,26 @@ private:
 };
 };
 
 
 #ifdef URHO3D_LOGGING
 #ifdef URHO3D_LOGGING
+#define URHO3D_LOGTRACE(message) Urho3D::Log::Write(Urho3D::LOG_TRACE, message)
 #define URHO3D_LOGDEBUG(message) Urho3D::Log::Write(Urho3D::LOG_DEBUG, message)
 #define URHO3D_LOGDEBUG(message) Urho3D::Log::Write(Urho3D::LOG_DEBUG, message)
 #define URHO3D_LOGINFO(message) Urho3D::Log::Write(Urho3D::LOG_INFO, message)
 #define URHO3D_LOGINFO(message) Urho3D::Log::Write(Urho3D::LOG_INFO, message)
 #define URHO3D_LOGWARNING(message) Urho3D::Log::Write(Urho3D::LOG_WARNING, message)
 #define URHO3D_LOGWARNING(message) Urho3D::Log::Write(Urho3D::LOG_WARNING, message)
 #define URHO3D_LOGERROR(message) Urho3D::Log::Write(Urho3D::LOG_ERROR, message)
 #define URHO3D_LOGERROR(message) Urho3D::Log::Write(Urho3D::LOG_ERROR, message)
 #define URHO3D_LOGRAW(message) Urho3D::Log::WriteRaw(message)
 #define URHO3D_LOGRAW(message) Urho3D::Log::WriteRaw(message)
+#define URHO3D_LOGTRACEF(format, ...) Urho3D::Log::Write(Urho3D::LOG_TRACE, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGDEBUGF(format, ...) Urho3D::Log::Write(Urho3D::LOG_DEBUG, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGDEBUGF(format, ...) Urho3D::Log::Write(Urho3D::LOG_DEBUG, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGINFOF(format, ...) Urho3D::Log::Write(Urho3D::LOG_INFO, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGINFOF(format, ...) Urho3D::Log::Write(Urho3D::LOG_INFO, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGWARNINGF(format, ...) Urho3D::Log::Write(Urho3D::LOG_WARNING, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGWARNINGF(format, ...) Urho3D::Log::Write(Urho3D::LOG_WARNING, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGERRORF(format, ...) Urho3D::Log::Write(Urho3D::LOG_ERROR, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGERRORF(format, ...) Urho3D::Log::Write(Urho3D::LOG_ERROR, Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGRAWF(format, ...) Urho3D::Log::WriteRaw(Urho3D::ToString(format, ##__VA_ARGS__))
 #define URHO3D_LOGRAWF(format, ...) Urho3D::Log::WriteRaw(Urho3D::ToString(format, ##__VA_ARGS__))
 #else
 #else
+#define URHO3D_LOGTRACE(message) ((void)0)
 #define URHO3D_LOGDEBUG(message) ((void)0)
 #define URHO3D_LOGDEBUG(message) ((void)0)
 #define URHO3D_LOGINFO(message) ((void)0)
 #define URHO3D_LOGINFO(message) ((void)0)
 #define URHO3D_LOGWARNING(message) ((void)0)
 #define URHO3D_LOGWARNING(message) ((void)0)
 #define URHO3D_LOGERROR(message) ((void)0)
 #define URHO3D_LOGERROR(message) ((void)0)
 #define URHO3D_LOGRAW(message) ((void)0)
 #define URHO3D_LOGRAW(message) ((void)0)
+#define URHO3D_LOGTRACEF(message) ((void)0)
 #define URHO3D_LOGDEBUGF(...) ((void)0)
 #define URHO3D_LOGDEBUGF(...) ((void)0)
 #define URHO3D_LOGINFOF(...) ((void)0)
 #define URHO3D_LOGINFOF(...) ((void)0)
 #define URHO3D_LOGWARNINGF(...) ((void)0)
 #define URHO3D_LOGWARNINGF(...) ((void)0)

+ 4 - 3
Source/Urho3D/LuaScript/pkgs/IO/Log.pkg

@@ -1,5 +1,6 @@
 $#include "IO/Log.h"
 $#include "IO/Log.h"
 
 
+static const int LOG_TRACE;
 static const int LOG_DEBUG;
 static const int LOG_DEBUG;
 static const int LOG_INFO;
 static const int LOG_INFO;
 static const int LOG_WARNING;
 static const int LOG_WARNING;
@@ -13,15 +14,15 @@ class Log : public Object
     void SetLevel(int level);
     void SetLevel(int level);
     void SetTimeStamp(bool enable);
     void SetTimeStamp(bool enable);
     void SetQuiet(bool quiet);
     void SetQuiet(bool quiet);
-    
+
     int GetLevel() const;
     int GetLevel() const;
     bool GetTimeStamp() const;
     bool GetTimeStamp() const;
     String GetLastMessage() const;
     String GetLastMessage() const;
     bool IsQuiet() const;
     bool IsQuiet() const;
-    
+
     static void Write(int level, const String message);
     static void Write(int level, const String message);
     static void WriteRaw(const String message, bool error = false);
     static void WriteRaw(const String message, bool error = false);
-    
+
     tolua_property__get_set int level;
     tolua_property__get_set int level;
     tolua_property__get_set bool timeStamp;
     tolua_property__get_set bool timeStamp;
     tolua_property__is_set bool quiet;
     tolua_property__is_set bool quiet;