2
0

LogFile.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /*!
  33. * CLogFile implements ILog interface.
  34. */
  35. class SANDBOX_API CLogFile
  36. : public ILogCallback
  37. {
  38. public:
  39. static const char* GetLogFileName();
  40. static void AttachListBox(QListWidget* hWndListBox);
  41. static void AttachEditBox(QTextEdit* hWndEditBox);
  42. //! Write to log snapshot of current process memory usage.
  43. static QString GetMemUsage();
  44. static void WriteString(const char* pszString);
  45. static void WriteString(const QString& string) { WriteString(string.toUtf8().data()); }
  46. static void WriteLine(const char* pszLine);
  47. static void WriteLine(const QString& string) { WriteLine(string.toUtf8().data()); }
  48. static void FormatLine(const char* pszMessage, ...);
  49. static void FormatLineV(const char* pszMessage, va_list argList);
  50. //////////////////////////////////////////////////////////////////////////
  51. // ILogCallback
  52. //////////////////////////////////////////////////////////////////////////
  53. virtual void OnWrite([[maybe_unused]] AZStd::string_view sText, [[maybe_unused]] IMiniLog::ELogType type) override {};
  54. virtual void OnWriteToConsole(AZStd::string_view sText, bool bNewLine) override;
  55. virtual void OnWriteToFile(AZStd::string_view sText, bool bNewLine) override;
  56. //////////////////////////////////////////////////////////////////////////
  57. // logs some useful information
  58. // should be called after CryLog() is available
  59. static void AboutSystem();
  60. private:
  61. static void OpenFile();
  62. // Attached control(s)
  63. static QListWidget* m_hWndListBox;
  64. static QTextEdit* m_hWndEditBox;
  65. static bool m_bShowMemUsage;
  66. static bool m_bIsQuitting;
  67. };
  68. #endif // CRYINCLUDE_EDITOR_LOGFILE_H