UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LogTrace.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Containers/Array.h"
9#include "Misc/Build.h"
11#include "Trace/Config.h"
12#include "Trace/Trace.h"
14
15#if !defined(LOGTRACE_ENABLED)
16#if UE_TRACE_ENABLED && !UE_BUILD_SHIPPING
17#define LOGTRACE_ENABLED 1
18#else
19#define LOGTRACE_ENABLED 0
20#endif
21#endif
22
23#if LOGTRACE_ENABLED
25
26#if !defined(LOGTRACE_RUNTIME_FORMATTING_ENABLED)
27#define LOGTRACE_RUNTIME_FORMATTING_ENABLED 1
28#endif
29
31
32struct FLogCategoryBase;
33namespace UE { namespace Trace { class FChannel; } }
34
35struct FLogTrace
36{
37 CORE_API static void OutputLogCategory(const FLogCategoryBase* Category, const TCHAR* Name, ELogVerbosity::Type DefaultVerbosity);
38 CORE_API static void OutputLogMessageSpec(const void* LogPoint, const FLogCategoryBase* Category, ELogVerbosity::Type Verbosity, const ANSICHAR* File, int32 Line, const TCHAR* Format);
39 CORE_API static void OutputLogMessageSimple(const void* LogPoint, const TCHAR* Fmt, ...);
40
41 template <typename... Types>
42 FORCENOINLINE static void OutputLogMessage(const void* LogPoint, Types... FormatArgs)
43 {
44 // This inline size covers 99.96% of log messages in sampled traces
47 const uint8* FormatArgsBuffer = Buffer.GetData();
49 {
51 }
52 }
53
54private:
56};
57
58#define TRACE_LOG_CATEGORY(Category, Name, DefaultVerbosity) \
59 FLogTrace::OutputLogCategory(Category, Name, DefaultVerbosity);
60
61#if LOGTRACE_RUNTIME_FORMATTING_ENABLED
62#define TRACE_LOG_MESSAGE(Category, Verbosity, Format, ...) \
63 if (UE_TRACE_CHANNELEXPR_IS_ENABLED(LogChannel)) \
64 { \
65 static bool PREPROCESSOR_JOIN(__LogPoint, __LINE__); \
66 if (!PREPROCESSOR_JOIN(__LogPoint, __LINE__)) \
67 { \
68 FLogTrace::OutputLogMessageSpec(&PREPROCESSOR_JOIN(__LogPoint, __LINE__), &Category, ELogVerbosity::Verbosity, __FILE__, __LINE__, TEXT("%s")); \
69 PREPROCESSOR_JOIN(__LogPoint, __LINE__) = true; \
70 } \
71 FLogTrace::OutputLogMessageSimple(&PREPROCESSOR_JOIN(__LogPoint, __LINE__), Format, ##__VA_ARGS__); \
72 }
73#else
74#define TRACE_LOG_MESSAGE(Category, Verbosity, Format, ...) \
75 static_assert(TIsArrayOrRefOfTypeByPredicate<decltype(Format), TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array."); \
76 if (UE_TRACE_CHANNELEXPR_IS_ENABLED(LogChannel)) \
77 { \
78 static bool PREPROCESSOR_JOIN(__LogPoint, __LINE__); \
79 if (!PREPROCESSOR_JOIN(__LogPoint, __LINE__)) \
80 { \
81 FLogTrace::OutputLogMessageSpec(&PREPROCESSOR_JOIN(__LogPoint, __LINE__), &Category, ELogVerbosity::Verbosity, __FILE__, __LINE__, (const TCHAR*)Format); \
82 PREPROCESSOR_JOIN(__LogPoint, __LINE__) = true; \
83 } \
84 FLogTrace::OutputLogMessage(&PREPROCESSOR_JOIN(__LogPoint, __LINE__), ##__VA_ARGS__); \
85 }
86#endif
87
88#else
89#define TRACE_LOG_CATEGORY(Category, Name, DefaultVerbosity)
90#define TRACE_LOG_MESSAGE(Category, Verbosity, Format, ...)
91#endif
#define FORCENOINLINE
Definition AndroidPlatform.h:142
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::ANSICHAR ANSICHAR
An ANSI character. Normally a signed type.
Definition Platform.h:1131
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_TRACE_CHANNEL_EXTERN(ChannelName,...)
Definition Trace.h:448
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Array.h:670
Type
Definition LogVerbosity.h:17
Definition AdvancedWidgetsModule.cpp:13
static int32 EncodeArgumentsWithArray(BufferType &Array, Types... FormatArgs)
Definition FormatArgsTrace.h:32
Definition LogCategory.h:21