LogFile.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef CRYINCLUDE_EDITOR_LOGFILE_H
  9. #define CRYINCLUDE_EDITOR_LOGFILE_H
  10. #pragma once
  11. #include "ILog.h"
  12. #include <IConsole.h>
  13. #include <stdarg.h>
  14. #define MAX_LOGBUFFER_SIZE 16384
  15. class QTextEdit;
  16. class QListWidget;
  17. //struct IConsole;
  18. //struct ICVar;
  19. //////////////////////////////////////////////////////////////////////////
  20. // Global log functions.
  21. //////////////////////////////////////////////////////////////////////////
  22. // the 'v' versions are for when you've already done your unpack, so that we are not forced to truncate the buffer
  23. //! Displays error message.
  24. SANDBOX_API void Error(const char* format, ...);
  25. SANDBOX_API void ErrorV(const char* format, va_list argList);
  26. //! Log to console and file.
  27. SANDBOX_API void Log(const char* format, ...);
  28. SANDBOX_API void LogV(const char* format, va_list argList);
  29. //! Display Warning dialog.
  30. SANDBOX_API void Warning(const char* format, ...);
  31. SANDBOX_API void WarningV(const char* format, va_list argList);
  32. AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  33. /*!
  34. * CLogFile implements ILog interface.
  35. */
  36. class SANDBOX_API CLogFile
  37. : public ILogCallback
  38. {
  39. AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  40. public:
  41. static const char* GetLogFileName();
  42. static void AttachListBox(QListWidget* hWndListBox);
  43. static void AttachEditBox(QTextEdit* hWndEditBox);
  44. //! Write to log snapshot of current process memory usage.
  45. static QString GetMemUsage();
  46. static void WriteString(const char* pszString);
  47. static void WriteString(const QString& string) { WriteString(string.toUtf8().data()); }
  48. static void WriteLine(const char* pszLine);
  49. static void WriteLine(const QString& string) { WriteLine(string.toUtf8().data()); }
  50. static void FormatLine(const char* pszMessage, ...);
  51. static void FormatLineV(const char* pszMessage, va_list argList);
  52. //////////////////////////////////////////////////////////////////////////
  53. // ILogCallback
  54. //////////////////////////////////////////////////////////////////////////
  55. virtual void OnWrite([[maybe_unused]] AZStd::string_view sText, [[maybe_unused]] IMiniLog::ELogType type) override {};
  56. virtual void OnWriteToConsole(AZStd::string_view sText, bool bNewLine) override;
  57. virtual void OnWriteToFile(AZStd::string_view sText, bool bNewLine) override;
  58. //////////////////////////////////////////////////////////////////////////
  59. // logs some useful information
  60. // should be called after CryLog() is available
  61. static void AboutSystem();
  62. private:
  63. static void OpenFile();
  64. // Attached control(s)
  65. static QListWidget* m_hWndListBox;
  66. static QTextEdit* m_hWndEditBox;
  67. static bool m_bShowMemUsage;
  68. static bool m_bIsQuitting;
  69. };
  70. #endif // CRYINCLUDE_EDITOR_LOGFILE_H