IMiniLog.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // Description : This is the smallest possible interface to the Log -
  9. // it s independent and small so that it can be easily moved
  10. // across the engine and test applications to test engine
  11. // parts that need logging (e.g. Streaming Engine) separately
  12. #pragma once
  13. #include <AzCore/std/function/function_fwd.h>
  14. namespace AZ::IO
  15. {
  16. class GenericStream;
  17. }
  18. struct IMiniLog
  19. {
  20. enum ELogType
  21. {
  22. eMessage,
  23. eWarning,
  24. eError,
  25. eAlways,
  26. eWarningAlways,
  27. eErrorAlways,
  28. eInput, // e.g. "e_CaptureFolder ?" or all printouts from history or auto completion
  29. eInputResponse, // e.g. "Set output folder for video capturing" in response to "e_CaptureFolder ?"
  30. eComment
  31. };
  32. // <interfuscator:shuffle>
  33. // Notes:
  34. // You only have to implement this function.
  35. virtual void LogV(ELogType nType, const char* szFormat, va_list args) PRINTF_PARAMS(3, 0) = 0;
  36. virtual void LogV(ELogType nType, int flags, const char* szFormat, va_list args) PRINTF_PARAMS(4, 0) = 0;
  37. //! Callback function which is invoked to allow writing to the supplied GenericStream
  38. using LogWriteCallback = AZStd::function<void(AZ::IO::GenericStream&)>;
  39. // Description:
  40. // Logging function which accepts string_view and writes it directly to the log
  41. // It is not restricted by the buffer of a format string, so the message can be larger than 4096 + 32 bytes
  42. virtual void LogWithCallback(ELogType nType, const LogWriteCallback&) = 0;
  43. // Summary:
  44. // Logs using type.
  45. inline void LogWithType(ELogType nType, const char* szFormat, ...) PRINTF_PARAMS(3, 4);
  46. inline void LogWithType(ELogType nType, int flags, const char* szFormat, ...) PRINTF_PARAMS(4, 5);
  47. // --------------------------------------------------------------------------
  48. // Summary:
  49. // Destructor.
  50. virtual ~IMiniLog() {}
  51. // Description:
  52. // This is the simplest log function for messages
  53. // with the default implementation.
  54. virtual inline void Log(const char* szFormat, ...) PRINTF_PARAMS(2, 3);
  55. // Description:
  56. // This is the simplest log function for warnings
  57. // with the default implementation.
  58. virtual inline void LogWarning(const char* szFormat, ...) PRINTF_PARAMS(2, 3);
  59. // Description:
  60. // This is the simplest log function for errors
  61. // with the default implementation.
  62. virtual inline void LogError(const char* szFormat, ...) PRINTF_PARAMS(2, 3);
  63. // </interfuscator:shuffle>
  64. };
  65. inline void IMiniLog::LogWithType(ELogType nType, int flags, const char* szFormat, ...)
  66. {
  67. va_list args;
  68. va_start(args, szFormat);
  69. LogV(nType, flags, szFormat, args);
  70. va_end(args);
  71. }
  72. inline void IMiniLog::LogWithType(ELogType nType, const char* szFormat, ...)
  73. {
  74. va_list args;
  75. va_start(args, szFormat);
  76. LogV(nType, szFormat, args);
  77. va_end(args);
  78. }
  79. inline void IMiniLog::Log(const char* szFormat, ...)
  80. {
  81. va_list args;
  82. va_start(args, szFormat);
  83. LogV (eMessage, szFormat, args);
  84. va_end(args);
  85. }
  86. inline void IMiniLog::LogWarning(const char* szFormat, ...)
  87. {
  88. va_list args;
  89. va_start(args, szFormat);
  90. LogV (eWarning, szFormat, args);
  91. va_end(args);
  92. }
  93. inline void IMiniLog::LogError(const char* szFormat, ...)
  94. {
  95. va_list args;
  96. va_start(args, szFormat);
  97. LogV (eError, szFormat, args);
  98. va_end(args);
  99. }
  100. // Notes:
  101. // By default, to make it possible not to implement the log at the beginning at all,
  102. // empty implementations of the two functions are given.
  103. struct CNullMiniLog
  104. : public IMiniLog
  105. {
  106. // Notes:
  107. // The default implementation just won't do anything
  108. //##@{
  109. void LogV([[maybe_unused]] ELogType nType, [[maybe_unused]] const char* szFormat, [[maybe_unused]] va_list args) override {}
  110. void LogV ([[maybe_unused]] ELogType nType, [[maybe_unused]] int flags, [[maybe_unused]] const char* szFormat, [[maybe_unused]] va_list args) override {}
  111. void LogWithCallback(ELogType, const LogWriteCallback&) override {}
  112. //##@}
  113. };