Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
OutputDeviceRedirector.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"
6#include "Containers/ContainerAllocationPolicies.h"
7#include "CoreTypes.h"
8#include "Logging/LogVerbosity.h"
9#include "Misc/EnumClassFlags.h"
10#include "Misc/OutputDevice.h"
11#include "Templates/PimplPtr.h"
12#include "UObject/NameTypes.h"
13
14/*-----------------------------------------------------------------------------
15FOutputDeviceRedirector.
16-----------------------------------------------------------------------------*/
17
18namespace UE::Private { struct FOutputDeviceRedirectorState; }
19
20/** The type of lines buffered by secondary threads. */
22{
24 {
25 EMoveCtor = 0
26 };
27
28 const TCHAR* Data;
30 const double Time;
33
34 FBufferedLine(const TCHAR* InData, const FName& InCategory, ELogVerbosity::Type InVerbosity, const double InTime = -1);
35
37 : Data(InBufferedLine.Data)
38 , Category(InBufferedLine.Category)
39 , Time(InBufferedLine.Time)
40 , Verbosity(InBufferedLine.Verbosity)
42 {
43 InBufferedLine.Data = nullptr;
44 InBufferedLine.bExternalAllocation = false;
45 }
46
47 /** Noncopyable for now, could be made movable */
48 FBufferedLine(const FBufferedLine&) = delete;
51};
52
54{
55 None = 0,
56
57 /**
58 * Flush asynchronously when possible.
59 *
60 * When this flag is set and there is a dedicated primary logging thread, the flush function returns immediately.
61 * Otherwise, the flush function does not return until the requested type of flush is complete.
62 */
63 Async = 1 << 0,
64};
65
67
68/**
69 * Class used for output redirection to allow logs to show in multiple output devices.
70 */
71class FOutputDeviceRedirector final : public FOutputDevice
72{
73public:
74 UE_DEPRECATED(5.1, "TLocalOutputDevicesArray is being removed. Use TArray<FOutputDevice*, TInlineAllocator<16>>.")
76
77 /** Initialization constructor. */
79
80 /** Get the GLog singleton. */
81 static FOutputDeviceRedirector* Get();
82
83 /**
84 * Adds an output device to the chain of redirections.
85 *
86 * @param OutputDevice Output device to add.
87 */
88 void AddOutputDevice(FOutputDevice* OutputDevice);
89
90 /**
91 * Removes an output device from the chain of redirections.
92 *
93 * @param OutputDevice Output device to remove.
94 */
95 void RemoveOutputDevice(FOutputDevice* OutputDevice);
96
97 /**
98 * Returns whether an output device is in the list of redirections.
99 *
100 * @param OutputDevice Output device to check the list against.
101 * @return true if messages are currently redirected to the the passed in output device, false otherwise.
102 */
103 bool IsRedirectingTo(FOutputDevice* OutputDevice);
104
105 /** Flushes lines buffered by secondary threads. */
107
108 /** See Panic. */
109 UE_DEPRECATED(5.1, "Use Panic() when the caller is handling a crash, otherwise use FlushThreadedLogs().")
110 void PanicFlushThreadedLogs() { Panic(); }
111
112 /**
113 * Serializes the current backlog to the specified output device.
114 * @param OutputDevice Output device that will receive the current backlog.
115 */
116 void SerializeBacklog(FOutputDevice* OutputDevice);
117
118 /**
119 * Enables or disables the backlog.
120 *
121 * @param bEnable Starts saving a backlog if true, disables and discards any backlog if false.
122 */
123 void EnableBacklog(bool bEnable);
124
125 /**
126 * Sets the current thread to be the thread that redirects logs to buffered output devices.
127 *
128 * The current thread can redirect to buffered output devices without buffering, and becomes
129 * responsible for flushing buffered logs from secondary threads. Logs from secondary threads
130 * will not be redirected unless the current thread periodically flushes threaded logs.
131 */
133
134 UE_DEPRECATED(5.1, "Use SetCurrentThreadAsPrimaryThread().")
136
137 /**
138 * Starts a dedicated primary thread that redirects logs to buffered output devices.
139 *
140 * A thread will not be started for certain configurations or platforms, or when threading is disabled.
141 *
142 * @return true if a dedicated primary logging thread is running, false otherwise.
143 */
145
146 /**
147 * Serializes the log record via all current output devices.
148 *
149 * The format string pointed to by the record must remain valid indefinitely.
150 */
151 void SerializeRecord(const UE::FLogRecord& Record) final;
152
153 /**
154 * Serializes the passed in data via all current output devices.
155 *
156 * @param Data Text to log.
157 * @param Event Event name used for suppression purposes.
158 */
159 void Serialize(const TCHAR* Data, ELogVerbosity::Type Verbosity, const FName& Category, const double Time) final;
160
161 /**
162 * Serializes the passed in data via all current output devices.
163 *
164 * @param Data Text to log.
165 * @param Event Event name used for suppression purposes.
166 */
167 void Serialize(const TCHAR* Data, ELogVerbosity::Type Verbosity, const FName& Category) final;
168
169 /** Same as Serialize(). */
170 void RedirectLog(const FName& Category, ELogVerbosity::Type Verbosity, const TCHAR* Data);
171 void RedirectLog(const FLazyName& Category, ELogVerbosity::Type Verbosity, const TCHAR* Data);
172
173 /** Passes on the flush request to all current output devices. */
174 void Flush() final;
175
176 /**
177 * Attempts to set the calling thread as the panic thread and enable panic mode.
178 *
179 * Only one thread can be the panic thread. Subsequent calls from other threads are ignored.
180 * Only redirects logs to panic-safe output devices from this point forward.
181 * Makes the calling thread the primary log thread as well.
182 * Flushes buffered logs to panic-safe output devices.
183 * Flushes panic-safe output devices.
184 */
185 void Panic();
186
187 /**
188 * Closes output device and cleans up.
189 *
190 * This can't happen in the destructor as we might have to call "delete" which cannot be done for static/global objects.
191 */
192 void TearDown() final;
193
194 /**
195 * Determine if the backlog is enabled.
196 */
197 bool IsBacklogEnabled() const;
198
199private:
201};
#define UE_DEPRECATED(Version, Message)
#define ENUM_CLASS_FLAGS(Enum)
EOutputDeviceRedirectorFlushOptions
Definition Enums.h:22943
bool TryStartDedicatedPrimaryThread()
void EnableBacklog(bool bEnable)
void SerializeRecord(const UE::FLogRecord &Record) final
void RedirectLog(const FName &Category, ELogVerbosity::Type Verbosity, const TCHAR *Data)
void AddOutputDevice(FOutputDevice *OutputDevice)
void SetCurrentThreadAsPrimaryThread()
void RemoveOutputDevice(FOutputDevice *OutputDevice)
static FOutputDeviceRedirector * Get()
void RedirectLog(const FLazyName &Category, ELogVerbosity::Type Verbosity, const TCHAR *Data)
void Serialize(const TCHAR *Data, ELogVerbosity::Type Verbosity, const FName &Category) final
TArray< FOutputDevice *, TInlineAllocator< 16 > > TLocalOutputDevicesArray
bool IsRedirectingTo(FOutputDevice *OutputDevice)
TPimplPtr< UE::Private::FOutputDeviceRedirectorState > State
void SerializeBacklog(FOutputDevice *OutputDevice)
void Serialize(const TCHAR *Data, ELogVerbosity::Type Verbosity, const FName &Category, const double Time) final
void FlushThreadedLogs(EOutputDeviceRedirectorFlushOptions Options=EOutputDeviceRedirectorFlushOptions::None)
bool IsBacklogEnabled() const
Definition Vector.h:40
const FLazyName Category
FBufferedLine(const FBufferedLine &)=delete
FBufferedLine(FBufferedLine &InBufferedLine, EBufferedLineInit Unused)
FBufferedLine(const TCHAR *InData, const FName &InCategory, ELogVerbosity::Type InVerbosity, const double InTime=-1)
const ELogVerbosity::Type Verbosity
FBufferedLine & operator=(const FBufferedLine &)=delete