Namespace Unity.Logging
Classes
BurstHelper
Helper functions for Burst
BurstStringWrapper
Helper functions for Burst compatible string operations.
Console
Static class for Console related operations. Provides Write(Byte*, Int32, Byte), Write(ref FixedString512Bytes) and Write(ref FixedString4096Bytes) for low-level writing to the Console. Use BeginBatch() and EndBatch() when you need to write a lot of data in a batch.
Consts
FixedString representation of LogLevel
DefaultSettings
Default integration of the logging package in the Unity player loop.
HideInStackTrace
Hides methods or any class' methods in the stacktrace in logging
JsonWriter
Utilities for writing JSON
LogFormatterJson
Json structured formatter
LogFormatterText
Plain text formatter
Logger
Main class of Logging library. Contains Sinks, unique identifier LoggerHandle
LoggerConfig
Configuration for Logger. Can be used to setup Logger and create it.
LoggerMinimumLevelConfig
Use to set the minimum log level that you want to use.
LoggerSyncModeConfig
Use to set the synchronization mode of the logger
LoggerWriterConfig
Config for the sink creation
LogLevelUtilsBurstCompatible
Static class with utility burst compatible functions for LogLevel - FixedString32Bytes convertion
LogWithName
Attribute to set a custom name that is different from field/property name
MessageParser
Static class used to parse message part of the log message.
NotLogged
Attribute to ignore field/property name from being serialized in logging
PerThreadData
Class that is used by logging to save some per-thread data for logging management. Usually stores thread's LoggerHandle that is currently used
UnityLogRedirector
Implements ILogHandler for redirection of Unity logs.
UnityLogRedirectorManager
Manages the details of redirection on a per-logger basis.
Structs
ArgumentInfo
Parsed Argument/Hole data. See https://messagetemplates.org/ for Holes
BinaryParser
Ref struct to hide unsafe pointer logic
Builder
Helper struct that helps pack data into LogMemoryManager Will be extended by Source Generator (that's why it is partial)
DispatchQueue
Double buffered thread-safe queue
Limited by a maximum size that is passed in the constructor. This is an important for performance, to avoid memory reallocation during the work.
In the usual case the queue works in the asynchronous mode:
- One buffer is used for write: several threads can add new LogMessage's to it, no one can read from that buffer. That is done via Enqueue(PayloadHandle, Int64, LogLevel) method that
does that under the read lock[1].
- Second buffer is used as a read-only buffer: several sinks can read from it, without modifying anything. This is done via BeginRead() and EndRead() that
enters/exits the read lock[1].
- Second buffer also can be in an exclusive mode: Cleanup system calls BeginReadExclusive() to enter the exclusive lock[2] to make sure only it can access the read buffer
at the time to release the memory used by the messages. EndReadExclusiveClearAndFlip() at the end of its work, cleaning the read buffer and flipping write/read ones, so
now the write buffer is empty. Exclusive lock is unlocked after this.
- Unity.Logging.DispatchQueue.Sort of the second (read) buffer is done under an exclusive lock[2], since it modifies the list, so it is not safe to read it.
Another use case that is much slower - synchronous access. LockAndSortForSyncAccess(out UnsafeList<LogMessage>, out UnsafeList<LogMessage>) will put the queue under the exclusive lock[2] and return both buffers for read-write access.
When the access is finished EndLockAfterSyncAccess() call will clear both buffers and unlock the data structure.
This is used in the case when full synchronous flush is needed.Lock is used to control the thread-safe access for this data structure:
[1] Read-lock allows several threads to take it, but only if no exclusive lock is taken. Guarantees that no exclusive lock [2] will be taken during it. Read-lock is used in situations when it is ok for multiple threads to do some kind of access, like: add new elements (see Enqueue(PayloadHandle, Int64, LogLevel)), read simultaneously without modifications (see BeginRead(), EndRead()).
[2] Exclusive lock is used when only one thread can enter and no read-locks are taken. This lock is used to cleanup the memory of the messages (see BeginReadExclusive()) and then clear the read and swap the read and write buffers (see EndReadExclusiveClearAndFlip()).Note: While read buffer is in read-only BeginRead() -- EndRead() mode the write buffer still can be used to Enqueue(PayloadHandle, Int64, LogLevel) from multiple threads
FormatterStruct
HeaderData
Decodes payload for LogMessages
LogController
Burst-friendly backend for Logger that contains LoggerHandle, LogMemoryManager, DispatchQueue and is able to answer if this particular LogLevel is supported by this Logger.
LogController.SinkStruct
Burst-friendly way to represent a sink
LogDecorateScope
Disposable struct that adds Decorations to the logs in the scope, or to some particular log
LoggerHandle
Structure that contains unique identifier of Logger
LogMemoryManager
Interface for allocating and managing Payload buffers for LogMessage.
LogMemoryManagerParameters
Initialization parameters for LogMemoryManager.
LogMessage
The struct for dispatching and processing log messages.
LogWriterUtils
Parser logic
ParseSegment
Structure used in parsing strings. Contains offset and length.
PayloadHandle
Holds a 64-bit value that uniquely references an allocated memory block within LogMemoryManager.
PayloadLockContext
Holds a value to identify a specific "context" for a Payload buffer lock.
SpinLockExclusive
Burst-friendly synchronization primitive
SpinLockExclusive.ScopedLock
IDisposable scoped structure that holds SpinLockExclusive. Should be using with using
SpinLockReadWrite
Burst-friendly synchronization primitive that supports read lock and exclusive (write) lock
SpinLockReadWrite.ScopedExclusiveLock
IDisposable scoped structure that holds Unity.Logging.BurstSpinLockReadWrite in exclusive mode. Should be using with using
SpinLockReadWrite.ScopedReadLock
IDisposable scoped structure that holds Unity.Logging.BurstSpinLockReadWrite in read mode. Should be using with using
UnsafePayloadRingBuffer
Logging system's primary container for allocating Payload buffers.
Interfaces
IFormatter
Interface that describes how to convert some object context into string
ILoggableMirrorStruct
Interface that is used by Unity.Logging to understand how to convert a mirror structure into UnsafeText
ILoggableMirrorStruct<T>
Interface that is used by Unity.Logging to understand how to convert a mirror structure into UnsafeText. Low-level way to describe 'ToString'-like behavior for any type for Unity.Logging to use.
Enums
ArgumentInfo.DestructingType
Enum for the name - with @, with $ or without
ArgumentInfo.HoleType
Type of the hole
LogLevel
Log Level
LogWriterUtils.ContextWriteResult
Result values returned by an OutputWriteHandler implementer.
MessageParser.ParseContextResult
Parser state
PayloadReleaseResult
Result value returned when releasing Payload buffers.
SyncMode
How Logger should synchronise logging messages.
Async is usually faster than Sync, but can lead to lost messages.
FatalIsSync works like async for all types of messages but Fatal. It will flush all the message queue when Fatal message appears.
Delegates
LogWriterUtils.OutputWriterHandler
Defines a delegate to handle writing the field data for context data structs.
LogWriterUtils.OutputWriterLevelHandler
Defines a delegate to handle writing the LogLevel
LogWriterUtils.OutputWriterTimestampHandler
Defines a delegate to handle writing the timestamp