123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- // Description : This is the smallest possible interface to the Log -
- // it s independent and small so that it can be easily moved
- // across the engine and test applications to test engine
- // parts that need logging (e.g. Streaming Engine) separately
- #pragma once
- #include <AzCore/std/function/function_fwd.h>
- namespace AZ::IO
- {
- class GenericStream;
- }
- struct IMiniLog
- {
- enum ELogType
- {
- eMessage,
- eWarning,
- eError,
- eAlways,
- eWarningAlways,
- eErrorAlways,
- eInput, // e.g. "e_CaptureFolder ?" or all printouts from history or auto completion
- eInputResponse, // e.g. "Set output folder for video capturing" in response to "e_CaptureFolder ?"
- eComment
- };
- // <interfuscator:shuffle>
- // Notes:
- // You only have to implement this function.
- virtual void LogV(ELogType nType, const char* szFormat, va_list args) PRINTF_PARAMS(3, 0) = 0;
- virtual void LogV(ELogType nType, int flags, const char* szFormat, va_list args) PRINTF_PARAMS(4, 0) = 0;
- //! Callback function which is invoked to allow writing to the supplied GenericStream
- using LogWriteCallback = AZStd::function<void(AZ::IO::GenericStream&)>;
- // Description:
- // Logging function which accepts string_view and writes it directly to the log
- // It is not restricted by the buffer of a format string, so the message can be larger than 4096 + 32 bytes
- virtual void LogWithCallback(ELogType nType, const LogWriteCallback&) = 0;
- // Summary:
- // Logs using type.
- inline void LogWithType(ELogType nType, const char* szFormat, ...) PRINTF_PARAMS(3, 4);
- inline void LogWithType(ELogType nType, int flags, const char* szFormat, ...) PRINTF_PARAMS(4, 5);
- // --------------------------------------------------------------------------
- // Summary:
- // Destructor.
- virtual ~IMiniLog() {}
- // Description:
- // This is the simplest log function for messages
- // with the default implementation.
- virtual inline void Log(const char* szFormat, ...) PRINTF_PARAMS(2, 3);
- // Description:
- // This is the simplest log function for warnings
- // with the default implementation.
- virtual inline void LogWarning(const char* szFormat, ...) PRINTF_PARAMS(2, 3);
- // Description:
- // This is the simplest log function for errors
- // with the default implementation.
- virtual inline void LogError(const char* szFormat, ...) PRINTF_PARAMS(2, 3);
- // </interfuscator:shuffle>
- };
- inline void IMiniLog::LogWithType(ELogType nType, int flags, const char* szFormat, ...)
- {
- va_list args;
- va_start(args, szFormat);
- LogV(nType, flags, szFormat, args);
- va_end(args);
- }
- inline void IMiniLog::LogWithType(ELogType nType, const char* szFormat, ...)
- {
- va_list args;
- va_start(args, szFormat);
- LogV(nType, szFormat, args);
- va_end(args);
- }
- inline void IMiniLog::Log(const char* szFormat, ...)
- {
- va_list args;
- va_start(args, szFormat);
- LogV (eMessage, szFormat, args);
- va_end(args);
- }
- inline void IMiniLog::LogWarning(const char* szFormat, ...)
- {
- va_list args;
- va_start(args, szFormat);
- LogV (eWarning, szFormat, args);
- va_end(args);
- }
- inline void IMiniLog::LogError(const char* szFormat, ...)
- {
- va_list args;
- va_start(args, szFormat);
- LogV (eError, szFormat, args);
- va_end(args);
- }
- // Notes:
- // By default, to make it possible not to implement the log at the beginning at all,
- // empty implementations of the two functions are given.
- struct CNullMiniLog
- : public IMiniLog
- {
- // Notes:
- // The default implementation just won't do anything
- //##@{
- void LogV([[maybe_unused]] ELogType nType, [[maybe_unused]] const char* szFormat, [[maybe_unused]] va_list args) override {}
- void LogV ([[maybe_unused]] ELogType nType, [[maybe_unused]] int flags, [[maybe_unused]] const char* szFormat, [[maybe_unused]] va_list args) override {}
- void LogWithCallback(ELogType, const LogWriteCallback&) override {}
- //##@}
- };
|