TraceMessageHook.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Debug/TraceMessageBus.h>
  10. #include <AzToolsFramework/Debug/TraceContextMultiStackHandler.h>
  11. #include <AssetBuilderSDK/AssetBuilderBusses.h>
  12. namespace AssetBuilder
  13. {
  14. class TraceMessageHook
  15. : public AZ::Debug::TraceMessageBus::Handler
  16. , public AssetBuilderSDK::AssetBuilderTraceBus::Handler
  17. {
  18. public:
  19. TraceMessageHook();
  20. ~TraceMessageHook() override;
  21. void EnableTraceContext(bool enable);
  22. void EnableDebugMode(bool enable);
  23. bool OnAssert(const char* message) override;
  24. bool OnPreError(const char* window, const char* fileName, int line, const char* func, const char* message) override;
  25. bool OnPreWarning(const char* window, const char* fileName, int line, const char* func, const char* message) override;
  26. bool OnException(const char* message) override;
  27. bool OnPrintf(const char* window, const char* message) override;
  28. bool OnOutput(const char* window, const char* message) override;
  29. void IgnoreNextErrors(AZ::u32 count) override;
  30. void IgnoreNextWarning(AZ::u32 count) override;
  31. void IgnoreNextPrintf(AZ::u32 count) override;
  32. void ResetWarningCount() override;
  33. void ResetErrorCount() override;
  34. AZ::u32 GetWarningCount() override;
  35. AZ::u32 GetErrorCount() override;
  36. void DumpTraceContext(FILE* stream) const;
  37. void CleanMessage(FILE* stream, const char* prefix, const char* message, bool forceFlush, const char* extraPrefix = nullptr, bool includeTraceContext = true) const;
  38. protected:
  39. AzToolsFramework::Debug::TraceContextMultiStackHandler* m_stacks;
  40. AZ::u32 m_skipErrorsCount;
  41. AZ::u32 m_skipWarningsCount;
  42. AZ::u32 m_skipPrintfsCount;
  43. AZ::u32 m_totalWarningCount;
  44. AZ::u32 m_totalErrorCount;
  45. bool m_inDebugMode;
  46. // once we're in an exception, we accept all log data as error, since we will terminate
  47. // this ensures that call stack info (which is 'traced', not 'exceptioned') is present.
  48. bool m_isInException = false;
  49. };
  50. } // namespace AssetBuilder