UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
StructuredLogFormat.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
8#include "Misc/ScopeExit.h"
10#include "Templates/UniquePtr.h"
11
12#define UE_API CORE_API
13
15class FCbWriter;
16
17namespace UE { class FLogTemplate; }
18namespace UE { struct FLogTemplateOptions; }
19namespace UE::Logging::Private { struct FLogField; }
20
22{
23
26{
27public:
28 inline void* Allocate(int32 Size)
29 {
30 Data.SetNum(Size);
31 return Data.GetData();
32 }
33
34 inline const void* Get() const
35 {
36 return Data.GetData();
37 }
38
39private:
40 // FLogTemplate is 8 bytes plus the encoded ops.
41 // There are 2 ops for each field. There is 1 op for each contiguous region of literal text.
42 // There is 1 op for each escaped character. There is 1 op to mark the end.
43 // Most ops encode as 1 byte. A format string that has 12 fields with text surrounding each
44 // field will typically be encoded in 46 bytes.
46};
47
50{
51public:
52 inline void* Allocate(int32 Size)
53 {
55 return Data.Get();
56 }
57
58 inline const void* Get() const
59 {
60 return Data.Get();
61 }
62
63private:
65};
66
69{
70public:
74
76 {
77 Free(Data);
78 }
79
80 inline void* Allocate(int32 Size)
81 {
82 Free(Data);
83 Data = FMemory::Malloc(Size);
84 return Data;
85 }
86
87 inline const void* Get() const
88 {
89 return Data;
90 }
91
92 inline void* Detach()
93 {
94 ON_SCOPE_EXIT { Data = nullptr; };
95 return Data;
96 }
97
98 inline static void Free(void* D)
99 {
100 if (D)
101 {
103 }
104 }
105
106private:
107 void* Data = nullptr;
108};
109
110UE_API void CreateLogTemplate(const TCHAR* Format, const FLogTemplateOptions& Options, const FLogField* Fields, int32 FieldCount, TFunctionWithContext<void* (int32)> Allocate);
111UE_API void CreateLogTemplate(const UTF8CHAR* Format, const FLogTemplateOptions& Options, const FLogField* Fields, int32 FieldCount, TFunctionWithContext<void* (int32)> Allocate);
112UE_API void CreateLocalizedLogTemplate(const FText& Format, const FLogTemplateOptions& Options, const FLogField* Fields, int32 FieldCount, TFunctionWithContext<void* (int32)> Allocate);
113UE_API void CreateLocalizedLogTemplate(const TCHAR* TextNamespace, const TCHAR* TextKey, const TCHAR* Format, const FLogTemplateOptions& Options, const FLogField* Fields, int32 FieldCount, TFunctionWithContext<void* (int32)> Allocate);
114UE_API void CreateLocalizedLogTemplate(const TCHAR* TextNamespace, const TCHAR* TextKey, const UTF8CHAR* Format, const FLogTemplateOptions& Options, const FLogField* Fields, int32 FieldCount, TFunctionWithContext<void* (int32)> Allocate);
115
116UE_API void DestroyLogTemplate(FLogTemplate* Template);
117
118} // UE::Logging::Private
119
120namespace UE
121{
122
124struct FLogTemplateOptions
125{
127 bool bAllowSubObjectReferences = false;
128};
129
130UE_API void FormatLogTo(FUtf8StringBuilderBase& Out, const FLogTemplate* Template, const FCbFieldViewIterator& Fields);
131UE_API void FormatLogTo(FWideStringBuilderBase& Out, const FLogTemplate* Template, const FCbFieldViewIterator& Fields);
132UE_API FText FormatLogToText(const FLogTemplate* Template, const FCbFieldViewIterator& Fields);
133
135template <typename StorageType>
136class TLogTemplate
137{
138public:
139 inline explicit TLogTemplate(const TCHAR* Format, const FLogTemplateOptions& Options = {}, const Logging::Private::FLogField* Fields = nullptr, int32 FieldCount = 0)
140 {
141 Logging::Private::CreateLogTemplate(Format, Options, Fields, FieldCount, [this](int32 Size) { return Storage.Allocate(Size); });
142 }
143public:
144 inline explicit TLogTemplate(const UTF8CHAR* Format, const FLogTemplateOptions& Options = {}, const Logging::Private::FLogField* Fields = nullptr, int32 FieldCount = 0)
145 {
146 Logging::Private::CreateLogTemplate(Format, Options, Fields, FieldCount, [this](int32 Size) { return Storage.Allocate(Size); });
147 }
148
149 inline explicit TLogTemplate(const FText& Format, const FLogTemplateOptions& Options = {}, const Logging::Private::FLogField* Fields = nullptr, int32 FieldCount = 0)
150 {
151 Logging::Private::CreateLocalizedLogTemplate(Format, Options, Fields, FieldCount, [this](int32 Size) { return Storage.Allocate(Size); });
152 }
153
154 inline explicit TLogTemplate(const TCHAR* TextNamespace, const TCHAR* TextKey, const TCHAR* Format, const FLogTemplateOptions& Options = {}, const Logging::Private::FLogField* Fields = nullptr, int32 FieldCount = 0)
155 {
156 Logging::Private::CreateLocalizedLogTemplate(TextNamespace, TextKey, Format, Options, Fields, FieldCount, [this](int32 Size) { return Storage.Allocate(Size); });
157 }
158
159 inline explicit TLogTemplate(const TCHAR* TextNamespace, const TCHAR* TextKey, const UTF8CHAR* Format, const FLogTemplateOptions& Options = {}, const Logging::Private::FLogField* Fields = nullptr, int32 FieldCount = 0)
160 {
161 Logging::Private::CreateLocalizedLogTemplate(TextNamespace, TextKey, Format, Options, Fields, FieldCount, [this](int32 Size) { return Storage.Allocate(Size); });
162 }
163
164 inline void FormatTo(FUtf8StringBuilderBase& Out, const FCbFieldViewIterator& Fields)
165 {
166 FormatLogTo(Out, Get(), Fields);
167 }
168
169 inline void FormatTo(FWideStringBuilderBase& Out, const FCbFieldViewIterator& Fields)
170 {
171 FormatLogTo(Out, Get(), Fields);
172 }
173
174 inline FText FormatToText(const FCbFieldViewIterator& Fields)
175 {
176 return FormatLogToText(Get(), Fields);
177 }
178
179 inline ~TLogTemplate()
180 {
182 }
183
184 inline FLogTemplate* Get() const
185 {
186 return (FLogTemplate*)Storage.Get();
187 }
188
189 inline FLogTemplate* Detach()
190 requires requires (StorageType& S) { S.Detach(); }
191 {
192 return (FLogTemplate*)Storage.Detach();
193 }
194
195private:
196 TLogTemplate() = default;
197
198 StorageType Storage;
199};
200
203
206
207UE_DEPRECATED(5.6, "Use FInlineLogTemplate or FUniqueLogTemplate.")
208inline FLogTemplate* CreateLogTemplate(const TCHAR* Format, const FLogTemplateOptions& Options = {})
209{
211}
212
213UE_DEPRECATED(5.6, "Use FInlineLogTemplate or FUniqueLogTemplate.")
214inline FLogTemplate* CreateLogTemplate(const FText& Format, const FLogTemplateOptions& Options = {})
215{
217}
218
219UE_DEPRECATED(5.6, "Use FInlineLogTemplate or FUniqueLogTemplate.")
220inline FLogTemplate* CreateLogTemplate(const TCHAR* TextNamespace, const TCHAR* TextKey, const TCHAR* Format, const FLogTemplateOptions& Options = {})
221{
222 return TLogTemplate<Logging::Private::FMemoryLogTemplateStorage>(TextNamespace, TextKey, Format, Options).Detach();
223}
224
225UE_DEPRECATED(5.6, "Use FInlineLogTemplate or FUniqueLogTemplate.")
226inline void DestroyLogTemplate(FLogTemplate* Template)
227{
230}
231
238UE_API void SerializeLogFormat(FCbWriter& Writer, const FText& Format);
239
240} // UE
241
242#undef UE_API
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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::UTF8CHAR UTF8CHAR
An 8-bit character containing a UTF8 (Unicode, 8-bit, variable-width) code unit.
Definition Platform.h:1137
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_API
Definition SColorGradingComponentViewer.h:12
#define ON_SCOPE_EXIT
Definition ScopeExit.h:73
uint32 Size
Definition VulkanMemory.cpp:4034
Definition CompactBinary.h:892
Definition CompactBinaryWriter.h:68
Definition Text.h:385
Definition Array.h:670
Definition StringBuilder.h:79
Definition UniquePtr.h:107
UE_FORCEINLINE_HINT T * Get() const
Definition UniquePtr.h:324
Definition StructuredLogFormat.h:26
void * Allocate(int32 Size)
Definition StructuredLogFormat.h:28
const void * Get() const
Definition StructuredLogFormat.h:34
Definition StructuredLogFormat.h:69
FMemoryLogTemplateStorage(const FMemoryLogTemplateStorage &)=delete
~FMemoryLogTemplateStorage()
Definition StructuredLogFormat.h:75
void * Detach()
Definition StructuredLogFormat.h:92
FMemoryLogTemplateStorage & operator=(const FMemoryLogTemplateStorage &)=delete
const void * Get() const
Definition StructuredLogFormat.h:87
void * Allocate(int32 Size)
Definition StructuredLogFormat.h:80
static void Free(void *D)
Definition StructuredLogFormat.h:98
Definition StructuredLogFormat.h:50
const void * Get() const
Definition StructuredLogFormat.h:58
void * Allocate(int32 Size)
Definition StructuredLogFormat.h:52
Definition FunctionWithContext.h:37
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
Definition StructuredLog.cpp:48
UE_API void DestroyLogTemplate(FLogTemplate *Template)
Definition StructuredLog.cpp:938
UE_API void CreateLocalizedLogTemplate(const FText &Format, const FLogTemplateOptions &Options, const FLogField *Fields, int32 FieldCount, TFunctionWithContext< void *(int32)> Allocate)
Definition StructuredLog.cpp:921
Definition AdvancedWidgetsModule.cpp:13
static FORCENOINLINE CORE_API void Free(void *Original)
Definition UnrealMemory.cpp:685