Struct LogController
Burst-friendly backend for Logger that contains Logger
Inherited Members
Namespace: Unity.Logging
Assembly: Unity.Logging.dll
Syntax
public struct LogController
Constructors
LogController(LoggerHandle, in LogMemoryManagerParameters)
Constructor that initializes Memory
Declaration
public LogController(LoggerHandle loggerHandle, in LogMemoryManagerParameters memoryParameters)
Parameters
Type | Name | Description |
---|---|---|
Logger |
loggerHandle | Unique id of the parent Logger |
Log |
memoryParameters | Parameters used to initialize Memory |
Fields
DispatchQueue
Double-buffered queue that is used for dispatching Log
Declaration
public DispatchQueue DispatchQueue
Field Value
Type | Description |
---|---|
Dispatch |
Handle
Unique id of the Logger
Declaration
public LoggerHandle Handle
Field Value
Type | Description |
---|---|
Logger |
MemoryManager
Memory manager that stores binary representation of structured logging. Log
Declaration
public LogMemoryManager MemoryManager
Field Value
Type | Description |
---|---|
Log |
SyncMode
Current synchronization mode
Declaration
public SyncMode SyncMode
Field Value
Type | Description |
---|---|
Sync |
Properties
IsCreated
True if Logging system has been initialized.
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
bool |
NeedsStackTrace
True if any sink requested stack trace. If this is false - logging would work faster.
Declaration
public bool NeedsStackTrace { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
AddDecorateHandler(FunctionPointer<OutputWriterDecorateHandler>)
The function that can add function based decorator.
Internally used by Log
Declaration
public void AddDecorateHandler(FunctionPointer<LoggerManager.OutputWriterDecorateHandler> func)
Parameters
Type | Name | Description |
---|---|---|
Function |
func | Function based decorator to add |
AddSinkStruct(SinkSystemBase)
Creates new sink using Sink
Declaration
public void AddSinkStruct(SinkSystemBase sink)
Parameters
Type | Name | Description |
---|---|---|
Sink |
sink | SinkSystemBase object |
BeginEditDecoratePayloadHandles(in LogControllerScopedLock, out int)
Function that is called by the logging codegeneration.
Used to populate Decorate array. See LogDeclaration
public static LogContextWithDecorator BeginEditDecoratePayloadHandles(in LogControllerScopedLock @lock, out int nBefore)
Parameters
Type | Name | Description |
---|---|---|
Log |
lock | Log |
int | nBefore | Current count of Decorations - PayloadHandles at the moment |
Returns
Type | Description |
---|---|
Log |
Log |
DecorateHandlerCount()
Returns count of Function-based Decorators (that you can add with Log.Decorate(function) or Add
Declaration
public int DecorateHandlerCount()
Returns
Type | Description |
---|---|
int | Count of Function-based Decorators |
DecoratePayloadsCount()
Returns count of constant Decorators (that you can add with Log.Decorate("name", value)) They will be copied to new log message payload each time log message is created
Declaration
public int DecoratePayloadsCount()
Returns
Type | Description |
---|---|
int | Count of constant Decorators |
DispatchMessage(PayloadHandle, long, LogLevel)
Dispatches a Log
Declaration
public void DispatchMessage(PayloadHandle payload, long stacktraceId, LogLevel logLevel)
Parameters
Type | Name | Description |
---|---|---|
Payload |
payload | PayloadHandle of the binary data associated with the message |
long | stacktraceId | Id of the stacktrace connected to the LogMessage, 0 is none |
Log |
logLevel | LogLevel of the LogMessage |
Remarks
This method is thread-safe and can be called from any thread context or Job. If successful, the Logging system will take over ownership of the message data and ensure the memory buffer is released after the message has been processed.
EndEditDecoratePayloadHandles(ref LogController, int)
Function that is called by the logging codegeneration.
Used to populate Decorate array. See LogDeclaration
public static FixedList64Bytes<PayloadHandle> EndEditDecoratePayloadHandles(ref LogController lc, int nBefore)
Parameters
Type | Name | Description |
---|---|---|
Log |
lc | Log |
int | nBefore | Same variable that was returned in Begin |
Returns
Type | Description |
---|---|
Fixed |
Array of just added Decorations - PayloadHandles |
FlushSync()
Burst-friendly way to immediately and synchronously Update/Flush the DispatchQueue into sinks. This is a slower alternative to LoggerManager.ScheduleUpdate but can be called from Burst / not main thread.
Declaration
[BurstCompile]
public void FlushSync()
HasSinksFor(LogLevel)
Returns true if the LogLevel is supported by at least one Sink
Declaration
public bool HasSinksFor(LogLevel level)
Parameters
Type | Name | Description |
---|---|---|
Log |
level | LogLevel enum |
Returns
Type | Description |
---|---|
bool | Returns true if the LogLevel is supported by at least one Sink |
LogDispatched()
Count of log messages dispatched and waiting to be processed
Declaration
public int LogDispatched()
Returns
Type | Description |
---|---|
int | Count of log messages dispatched and waiting to be processed |
MustBeValid()
Checks that IsCreated == true. Throws otherwise.
Declaration
[Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
[Conditional("UNITY_DOTS_DEBUG")]
public void MustBeValid()
Exceptions
Type | Condition |
---|---|
Exception | Throws if IsCreated == false |
RemoveDecorateHandler(FunctionPointer<OutputWriterDecorateHandler>)
The function that remove function based decorator that was added by Add
Declaration
public void RemoveDecorateHandler(FunctionPointer<LoggerManager.OutputWriterDecorateHandler> func)
Parameters
Type | Name | Description |
---|---|---|
Function |
func | Function based decorator to remove |
SetMinimalLogLevelForSink(int, LogLevel)
Changes the minimal level of the sink
Declaration
public void SetMinimalLogLevelForSink(int sinkId, LogLevel minimalLevel)
Parameters
Type | Name | Description |
---|---|---|
int | sinkId | Id that was returned by Add |
Log |
minimalLevel | New minimal log level for the sink |
Shutdown()
Stops Logging and releases the memory and destroys systems created by LogController.
Declaration
public void Shutdown()
Remarks
This must be called from the main thread (do not call from a Job) after all Logging calls have completed; any log messages "in flight" will be discarded.
IMPORTANT: Accessing the Payload buffer of a log message when Shutdown is called, e.g. during an asynchronous I/O operation, will result in undefined behavior.