UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
OutputDevice.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreFwd.h"
6#include "CoreTypes.h"
8#include "Misc/VarArgs.h"
12
13class FString;
14class FText;
15
16namespace UE { class FLogRecord; }
17
18#ifndef USE_DEBUG_LOGGING
19#define USE_DEBUG_LOGGING 1
20#endif
21
22#ifndef USE_EVENT_LOGGING
23#define USE_EVENT_LOGGING 1
24#endif
25
26#if !PLATFORM_SUPPORTS_COLORIZED_OUTPUT_DEVICE
27 // don't support colorized text on consoles
28 #define SET_WARN_COLOR(Color)
29 #define SET_WARN_COLOR_AND_BACKGROUND(Color, Bkgrnd)
30 #define CLEAR_WARN_COLOR()
31#else
32
33/*-----------------------------------------------------------------------------
34Colorized text.
35
36To use colored text from a commandlet, you use the SET_WARN_COLOR macro with
37one of the following standard colors. Then use CLEAR_WARN_COLOR to return
38to default.
39
40To use the standard colors, you simply do this:
41SET_WARN_COLOR(COLOR_YELLOW);
42
43You can specify a background color by appending it to the foreground:
44SET_WARN_COLOR, COLOR_YELLOW COLOR_DARK_RED);
45
46This will have bright yellow text on a dark red background.
47
48Or you can make your own in the format:
49
50ForegroundRed | ForegroundGreen | ForegroundBlue | ForegroundBright | BackgroundRed | BackgroundGreen | BackgroundBlue | BackgroundBright
51where each value is either 0 or 1 (can leave off trailing 0's), so
52blue on bright yellow is "00101101" and red on black is "1"
53
54An empty string reverts to the normal gray on black.
55-----------------------------------------------------------------------------*/
56
57// putting them in a namespace to protect against future name conflicts
58namespace OutputDeviceColor
59{
60 inline const TCHAR* const COLOR_BLACK = TEXT("0000");
61
62 inline const TCHAR* const COLOR_DARK_RED = TEXT("1000");
63 inline const TCHAR* const COLOR_DARK_GREEN = TEXT("0100");
64 inline const TCHAR* const COLOR_DARK_BLUE = TEXT("0010");
65 inline const TCHAR* const COLOR_DARK_YELLOW = TEXT("1100");
66 inline const TCHAR* const COLOR_DARK_CYAN = TEXT("0110");
67 inline const TCHAR* const COLOR_DARK_PURPLE = TEXT("1010");
68 inline const TCHAR* const COLOR_DARK_WHITE = TEXT("1110");
69 inline const TCHAR* const COLOR_GRAY = COLOR_DARK_WHITE;
70
71 inline const TCHAR* const COLOR_RED = TEXT("1001");
72 inline const TCHAR* const COLOR_GREEN = TEXT("0101");
73 inline const TCHAR* const COLOR_BLUE = TEXT("0011");
74 inline const TCHAR* const COLOR_YELLOW = TEXT("1101");
75 inline const TCHAR* const COLOR_CYAN = TEXT("0111");
76 inline const TCHAR* const COLOR_PURPLE = TEXT("1011");
77 inline const TCHAR* const COLOR_WHITE = TEXT("1111");
78
79 inline const TCHAR* const COLOR_NONE = TEXT("");
80}
81
82using namespace OutputDeviceColor;
83
84
85// let a console or (UE_BUILD_SHIPPING || UE_BUILD_TEST) define it to nothing
86#ifndef SET_WARN_COLOR
87
91#define SET_WARN_COLOR(Color) \
92 UE_LOG(LogHAL, SetColor, TEXT("%s"), Color);
93#define SET_WARN_COLOR_AND_BACKGROUND(Color, Bkgrnd) \
94 UE_LOG(LogHAL, SetColor, TEXT("%s%s"), Color, Bkgrnd);
95
99#define CLEAR_WARN_COLOR() \
100 UE_LOG(LogHAL, SetColor, TEXT("%s"), COLOR_NONE);
101
102#endif
103#endif
104
108namespace ELogTimes
109{
110 enum Type
111 {
112 // Do not display log timestamps
114
115 // Display log timestamps in UTC
117
118 // Display log timestamps in seconds elapsed since GStartTime
120
121 // Display log timestamps in local time
123
124 // Display log timestamps in timecode format
126 };
127}
128
129class FName;
130
131// An output device.
133{
134public:
136
141
143
144 // FOutputDevice interface.
145 virtual void Serialize( const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category ) = 0;
146 virtual void Serialize( const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category, const double Time )
147 {
148 Serialize( V, Verbosity, Category );
149 }
150
151 CORE_API virtual void SerializeRecord(const UE::FLogRecord& Record);
152
153 virtual void Flush()
154 {
155 }
156
162 virtual void TearDown()
163 {
164 }
165
176
181 virtual void Dump(class FArchive& Ar)
182 {
183 }
184
188 virtual bool IsMemoryOnly() const
189 {
190 return false;
191 }
192
196 virtual bool CanBeUsedOnAnyThread() const
197 {
198 return false;
199 }
200
204 virtual bool CanBeUsedOnMultipleThreads() const
205 {
206 return false;
207 }
208
213 virtual bool CanBeUsedOnPanicThread() const
214 {
215 return false;
216 }
217
218 // Simple text printing.
219 CORE_API void Log( const TCHAR* S );
220 CORE_API void Log( ELogVerbosity::Type Verbosity, const TCHAR* S );
221 CORE_API void Log( const FName& Category, ELogVerbosity::Type Verbosity, const TCHAR* Str );
222 CORE_API void Log( const FString& S );
223 CORE_API void Log( const FText& S );
224 CORE_API void Log( ELogVerbosity::Type Verbosity, const FString& S );
225 CORE_API void Log( const FName& Category, ELogVerbosity::Type Verbosity, const FString& S );
226
227private:
228 CORE_API void VARARGS LogfImpl(const TCHAR* Fmt, ...);
229 CORE_API void VARARGS LogfImpl(ELogVerbosity::Type Verbosity, const TCHAR* Fmt, ...);
230 CORE_API void VARARGS CategorizedLogfImpl(const FName& Category, ELogVerbosity::Type Verbosity, const TCHAR* Fmt, ...);
231
232public:
233 template <typename FmtType>
234 void Logf(const FmtType& Fmt)
235 {
236 static_assert(TIsArrayOrRefOfTypeByPredicate<FmtType, TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array.");
237 return Log((const TCHAR*)Fmt);
238 }
239
240 template <typename FmtType, typename... Types>
241 inline void Logf(const FmtType& Fmt, Types... Args)
242 {
243 static_assert(TIsArrayOrRefOfTypeByPredicate<FmtType, TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array.");
244 static_assert((TIsValidVariadicFunctionArg<Types>::Value && ...), "Invalid argument(s) passed to FOutputDevice::Logf");
245
246 LogfImpl((const TCHAR*)Fmt, Args...);
247 }
248
249 template <typename FmtType, typename... Types>
250 inline void Logf(ELogVerbosity::Type Verbosity, const FmtType& Fmt, Types... Args)
251 {
252 static_assert(TIsArrayOrRefOfTypeByPredicate<FmtType, TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array.");
253 static_assert((TIsValidVariadicFunctionArg<Types>::Value && ...), "Invalid argument(s) passed to FOutputDevice::Logf");
254
255 LogfImpl(Verbosity, (const TCHAR*)Fmt, Args...);
256 }
257
258 template <typename FmtType, typename... Types>
259 inline void CategorizedLogf(const FName& Category, ELogVerbosity::Type Verbosity, const FmtType& Fmt, Types... Args)
260 {
261 static_assert(TIsArrayOrRefOfTypeByPredicate<FmtType, TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array.");
262 static_assert((TIsValidVariadicFunctionArg<Types>::Value && ...), "Invalid argument(s) passed to FOutputDevice::CategorizedLogf");
263
264 CategorizedLogfImpl(Category, Verbosity, (const TCHAR*)Fmt, Args...);
265 }
266
267protected:
272};
273
274
275
#define VARARGS
Definition AndroidPlatform.h:134
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Archive.h:1208
Definition NameTypes.h:617
Definition OutputDevice.h:133
virtual bool CanBeUsedOnPanicThread() const
Definition OutputDevice.h:213
UE_FORCEINLINE_HINT bool GetSuppressEventTag() const
Definition OutputDevice.h:170
void SetSuppressEventTag(bool bInSuppressEventTag)
Definition OutputDevice.h:166
CORE_API void Log(const FName &Category, ELogVerbosity::Type Verbosity, const TCHAR *Str)
virtual bool IsMemoryOnly() const
Definition OutputDevice.h:188
virtual void Serialize(const TCHAR *V, ELogVerbosity::Type Verbosity, const FName &Category, const double Time)
Definition OutputDevice.h:146
CORE_API FOutputDevice(FOutputDevice &&)
virtual void Dump(class FArchive &Ar)
Definition OutputDevice.h:181
bool bAutoEmitLineTerminator
Definition OutputDevice.h:271
virtual bool CanBeUsedOnAnyThread() const
Definition OutputDevice.h:196
void CategorizedLogf(const FName &Category, ELogVerbosity::Type Verbosity, const FmtType &Fmt, Types... Args)
Definition OutputDevice.h:259
bool bSuppressEventTag
Definition OutputDevice.h:269
void Logf(const FmtType &Fmt, Types... Args)
Definition OutputDevice.h:241
CORE_API FOutputDevice(const FOutputDevice &)
void Logf(const FmtType &Fmt)
Definition OutputDevice.h:234
virtual void Flush()
Definition OutputDevice.h:153
virtual CORE_API void SerializeRecord(const UE::FLogRecord &Record)
Definition OutputDevice.cpp:84
void Logf(ELogVerbosity::Type Verbosity, const FmtType &Fmt, Types... Args)
Definition OutputDevice.h:250
CORE_API FOutputDevice()
Definition OutputDevice.cpp:22
CORE_API void Log(const FName &Category, ELogVerbosity::Type Verbosity, const FString &S)
UE_FORCEINLINE_HINT bool GetAutoEmitLineTerminator() const
Definition OutputDevice.h:175
virtual void Serialize(const TCHAR *V, ELogVerbosity::Type Verbosity, const FName &Category)=0
virtual void TearDown()
Definition OutputDevice.h:162
virtual CORE_API ~FOutputDevice()
virtual bool CanBeUsedOnMultipleThreads() const
Definition OutputDevice.h:204
CORE_API FOutputDevice & operator=(FOutputDevice &&)
CORE_API FOutputDevice & operator=(const FOutputDevice &)
void SetAutoEmitLineTerminator(bool bInAutoEmitLineTerminator)
Definition OutputDevice.h:171
Definition Text.h:385
Definition StructuredLog.h:182
Definition OutputDevice.h:109
Type
Definition OutputDevice.h:111
@ UTC
Definition OutputDevice.h:116
@ Timecode
Definition OutputDevice.h:125
@ None
Definition OutputDevice.h:113
@ Local
Definition OutputDevice.h:122
@ SinceGStartTime
Definition OutputDevice.h:119
Type
Definition LogVerbosity.h:17
Definition AdvancedWidgetsModule.cpp:13
Definition IsArrayOrRefOfTypeByPredicate.h:13
Definition IsValidVariadicFunctionArg.h:14