Browse Source

Add new AZ_Trace and AZ_Info macros

Signed-off-by: Pip Potter <[email protected]>
Pip Potter 3 years ago
parent
commit
cf92cebc58

+ 1 - 1
Code/Framework/AzCore/AzCore/Debug/Trace.cpp

@@ -87,7 +87,7 @@ namespace AZ::Debug
         Debug::ITrace::Instance().SetAlwaysPrintCallstack(enable);
     }
 
-    AZ_CVAR_SCOPED(int, bg_traceLogLevel, LogLevel::Info, &TraceLevelChanged, ConsoleFunctorFlags::Null, "Enable trace message logging in release mode.  0=disabled, 1=errors, 2=warnings, 3=info.");
+    AZ_CVAR_SCOPED(int, bg_traceLogLevel, static_cast<int>(LogLevel::Info), &TraceLevelChanged, ConsoleFunctorFlags::Null, "Enable trace message logging in release mode.  0=disabled, 1=errors, 2=warnings, 3=info, 4=debug, 5=trace.");
     AZ_CVAR_SCOPED(bool, bg_alwaysShowCallstack, false, &AlwaysShowCallstackChanged, ConsoleFunctorFlags::Null, "Force stack trace output without allowing ebus interception.");
 
     // Allow redirection of trace raw output writes to stdout, stderr or to /dev/null

+ 37 - 15
Code/Framework/AzCore/AzCore/Debug/Trace.h

@@ -30,13 +30,7 @@ namespace AZ
             void OutputToDebugger(AZStd::basic_string_view<char, AZStd::char_traits<char>> window, AZStd::basic_string_view<char, AZStd::char_traits<char>> message);
         }
 
-        enum LogLevel : int
-        {
-            Disabled = 0,
-            Errors = 1,
-            Warnings = 2,
-            Info = 3
-        };
+        enum class LogLevel { Disabled = 0, Errors = 1, Warnings = 2, Info = 3, Debug = 4, Trace = 5 };
 
         // Represents the options to select C language FILE* stream to write raw output
         enum class RedirectCStream
@@ -286,10 +280,10 @@ namespace AZ
             "String used in place of boolean expression for AZ_ErrorOnce.",                                                 \
             "Did you mean AZ_ErrorOnce("#window", false, \"%s\", "#expression"); ?",                                        \
             "Did you mean AZ_ErrorOnce("#window", false, "#expression", "#__VA_ARGS__"); ?");                               \
-        static bool AZ_CONCAT_VAR_NAME(azErrorDisplayed, __LINE__) = false;                                                                    \
-        if (!AZ_CONCAT_VAR_NAME(azErrorDisplayed, __LINE__))                                                                                  \
+        static bool AZ_CONCAT_VAR_NAME(azErrorDisplayed, __LINE__) = false;                                                 \
+        if (!AZ_CONCAT_VAR_NAME(azErrorDisplayed, __LINE__))                                                                \
         {                                                                                                                   \
-            AZ_CONCAT_VAR_NAME(azErrorDisplayed, __LINE__) = true;                                                                            \
+            AZ_CONCAT_VAR_NAME(azErrorDisplayed, __LINE__) = true;                                                          \
             AZ::Debug::Trace::Instance().Error(__FILE__, __LINE__, AZ_FUNCTION_SIGNATURE, window, __VA_ARGS__);             \
         }                                                                                                                   \
     }                                                                                                                       \
@@ -319,22 +313,50 @@ namespace AZ
             "String used in place of boolean expression for AZ_WarningOnce.",                                                   \
             "Did you mean AZ_WarningOnce("#window", false, \"%s\", "#expression"); ?",                                          \
             "Did you mean AZ_WarningOnce("#window", false, "#expression", "#__VA_ARGS__"); ?");                                 \
-        static bool AZ_CONCAT_VAR_NAME(azWarningDisplayed, __LINE__) = false;                                                                     \
-        if (!AZ_CONCAT_VAR_NAME(azWarningDisplayed, __LINE__))                                                                                    \
+        static bool AZ_CONCAT_VAR_NAME(azWarningDisplayed, __LINE__) = false;                                                   \
+        if (!AZ_CONCAT_VAR_NAME(azWarningDisplayed, __LINE__))                                                                  \
         {                                                                                                                       \
             AZ::Debug::Trace::Instance().Warning(__FILE__, __LINE__, AZ_FUNCTION_SIGNATURE, window, __VA_ARGS__);               \
-            AZ_CONCAT_VAR_NAME(azWarningDisplayed, __LINE__) = true;                                                                              \
+            AZ_CONCAT_VAR_NAME(azWarningDisplayed, __LINE__) = true;                                                            \
         }                                                                                                                       \
     }                                                                                                                           \
     AZ_POP_DISABLE_WARNING
 
-    #define AZ_TracePrintf(window, ...)                                                                            \
-    if(AZ::Debug::Trace::Instance().IsTraceLoggingEnabledForLevel(AZ::Debug::LogLevel::Info))                                 \
+    #define AZ_Info(window, ...)                                                                                   \
+    if(AZ::Debug::Trace::Instance().IsTraceLoggingEnabledForLevel(AZ::Debug::LogLevel::Info))                      \
     {                                                                                                              \
         AZ::Debug::Trace::Instance().Printf(window, __VA_ARGS__);                                                  \
     }
 
+    #define AZ_Trace(window, ...)                                                                                  \
+    if(AZ::Debug::Trace::Instance().IsTraceLoggingEnabledForLevel(AZ::Debug::LogLevel::Trace))                     \
+    {                                                                                                              \
+        AZ::Debug::Trace::Instance().Printf(window, __VA_ARGS__);                                                  \
+    }
+
+    //! The AZ_TraceOnce macro output the result of the format string only once for each use of the macro
+    //! It does not take into account the result of the format string to determine whether to output the string or not
+    //! What this means is that if the formatting results in different output string result only the first result
+    //! will ever be output
+    #define AZ_TraceOnce(window, ...) \
+    { \
+        static bool AZ_CONCAT_VAR_NAME(azTracePrintfDisplayed, __LINE__) = false; \
+        if (!AZ_CONCAT_VAR_NAME(azTracePrintfDisplayed, __LINE__)) \
+        { \
+            AZ_Trace(window, __VA_ARGS__); \
+            AZ_CONCAT_VAR_NAME(azTracePrintfDisplayed, __LINE__) = true; \
+        } \
+    }
+
+    // O3DE_DEPRECATION_NOTICE(GHI-xxxx) - Use AZ_Trace
+    // Use of AZ_TracePrintf and AZ_TracePrintfOnce are deprecated
+    #define AZ_TracePrintf(window, ...)                                                                            \
+    if(AZ::Debug::Trace::Instance().IsTraceLoggingEnabledForLevel(AZ::Debug::LogLevel::Info))                      \
+    {                                                                                                              \
+        AZ::Debug::Trace::Instance().Printf(window, __VA_ARGS__);                                                  \
+    }
 
+    // O3DE_DEPRECATION_NOTICE(GHI-xxxx) - Use AZ_TraceOnce
     //! The AZ_TrancePrintfOnce macro output the result of the format string only once for each use of the macro
     //! It does not take into account the result of the format string to determine whether to output the string or not
     //! What this means is that if the formatting results in different output string result only the first result

+ 7 - 7
Code/Framework/AzFramework/AzFramework/Asset/AssetSystemComponentHelper.cpp

@@ -97,12 +97,12 @@ namespace AzFramework
                 if (!AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, ip,
                     AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey, AzFramework::AssetSystem::AssetProcessorRemoteIp))
                 {
-                    AZ_TracePrintfOnce("AssetSystemComponent", "Failed to find ip, setting 127.0.0.1\n");
+                    AZ_TraceOnce("AssetSystemComponent", "Failed to find ip, setting 127.0.0.1\n");
                     outputConnectionSettings.m_assetProcessorIp = "127.0.0.1";
                 }
                 else if (ip.empty())
                 {
-                    AZ_TracePrintfOnce("AssetSystemComponent", "Ip is empty, setting 127.0.0.1\n");
+                    AZ_TraceOnce("AssetSystemComponent", "Ip is empty, setting 127.0.0.1\n");
                     outputConnectionSettings.m_assetProcessorIp = "127.0.0.1";
                 }
                 else
@@ -146,7 +146,7 @@ namespace AzFramework
                 AZ::s64 port64;
                 if (!AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, port64, AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey, AzFramework::AssetSystem::AssetProcessorRemotePort))
                 {
-                    AZ_TracePrintfOnce("AssetSystemComponent", "Failed to find port, setting 45643\n");
+                    AZ_TraceOnce("AssetSystemComponent", "Failed to find port, setting 45643\n");
                     outputConnectionSettings.m_assetProcessorPort = 45643;
                 }
                 else
@@ -160,7 +160,7 @@ namespace AzFramework
                 AZ::SettingsRegistryInterface::FixedValueString assetsPlatform;
                 if (!AZ::SettingsRegistryMergeUtils::PlatformGet(*settingsRegistry, assetsPlatform, AZ::SettingsRegistryMergeUtils::BootstrapSettingsRootKey, AzFramework::AssetSystem::Assets))
                 {
-                    AZ_TracePrintfOnce("AssetSystemComponent", "Failed to find asset platform, setting 'pc'\n");
+                    AZ_TraceOnce("AssetSystemComponent", "Failed to find asset platform, setting 'pc'\n");
                     outputConnectionSettings.m_assetPlatform = "pc";
                 }
                 else
@@ -171,7 +171,7 @@ namespace AzFramework
                 if (outputConnectionSettings.m_assetPlatform.empty())
                 {
                     assetsPlatform = AzFramework::OSPlatformToDefaultAssetPlatform(AZ_TRAIT_OS_PLATFORM_CODENAME);
-                    AZ_TracePrintfOnce("AssetSystemComponent", "Asset platform read from bootstrap is empty, setting %s\n", assetsPlatform.c_str());
+                    AZ_TraceOnce("AssetSystemComponent", "Asset platform read from bootstrap is empty, setting %s\n", assetsPlatform.c_str());
                 }
             }
 
@@ -184,7 +184,7 @@ namespace AzFramework
                     // The first time the AssetProcessor runs within a branch the bootstrap.cfg does not have a branch token set
                     // Therefore it is not an error for the branch token to not be in the bootstrap.cfg file
                     AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::CalculateBranchTokenForEngineRoot, branchToken);
-                    AZ_TracePrintfOnce("AssetSystemComponent", "Failed to read branch token from bootstrap. Calculating Branch Token: %s\n", branchToken.c_str());
+                    AZ_TraceOnce("AssetSystemComponent", "Failed to read branch token from bootstrap. Calculating Branch Token: %s\n", branchToken.c_str());
                     outputConnectionSettings.m_branchToken = branchToken;
                 }
                 else
@@ -193,7 +193,7 @@ namespace AzFramework
                     if (outputConnectionSettings.m_branchToken.empty())
                     {
                         AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::CalculateBranchTokenForEngineRoot, branchToken);
-                        AZ_TracePrintfOnce("AssetSystemComponent", "Branch token read from bootstrap is empty. Calculating Branch Token: %s\n", branchToken.c_str());
+                        AZ_TraceOnce("AssetSystemComponent", "Branch token read from bootstrap is empty. Calculating Branch Token: %s\n", branchToken.c_str());
                         outputConnectionSettings.m_branchToken = branchToken;
                     }
                 }

+ 1 - 1
Gems/Atom/Asset/Shader/Code/Source/Editor/AzslCompiler.cpp

@@ -60,7 +60,7 @@ namespace AZ
                 AZStd::string overridePath;
                 if (setReg->Get(overridePath, AzslCompilerOverridePath))
                 {
-                    AZ_TracePrintfOnce("AzslCompiler", "AZSLc executable override specified, using %s", azslcPath.c_str());
+                    AZ_TraceOnce("AzslCompiler", "AZSLc executable override specified, using %s", azslcPath.c_str());
                     azslcPath = AZStd::move(overridePath);
                 }
             }