Class UnityConsoleFormatter
Implements ILogger to output log entries to the Unity Editor console. Also implements IConsoleFormatter to support direct colored output via Log.WritePartsToConsole. Supports Unity rich text coloring.
public class UnityConsoleFormatter : IConsoleFormatter
- Inheritance
-
UnityConsoleFormatter
- Implements
- Inherited Members
Constructors
UnityConsoleFormatter(Dictionary<LogLevel, string>, bool)
Initializes a new instance of the UnityConsoleFormatter with specified log level colors.
public UnityConsoleFormatter(Dictionary<LogLevel, string> logLevelColors, bool includeTimestamps)
Parameters
logLevelColorsDictionary<LogLevel, string>A dictionary mapping LogLevels to Unity rich text color strings.
includeTimestampsboolIf true, timestamps will be included in the formatted output.
Methods
WriteColoredParts(LogLevel, string, int, params (string color, string text)[])
Writes a message to the Unity console composed of multiple colored parts. Implements IConsoleFormatter.WriteColoredParts.
public void WriteColoredParts(LogLevel level, string source, int columnWidth = 0, params (string color, string text)[] parts)
Parameters
levelLogLevelThe log level for this message (used for a prefix, not for direct coloring of parts).
sourcestringThe source of the log message.
columnWidthintOptional. The minimum width for each text segment. Text will be padded if shorter. Use 0 or negative for no padding.
parts(string color, string text)[]An array of tuples, where each tuple contains a color (hex or named) and the text for that part.
WriteStructuredLog(LogEntry)
Formats and writes a structured log entry to the Unity console, mimicking the columnar layout of ConsoleFormatter.
public void WriteStructuredLog(LogEntry entry)
Parameters
entryLogEntryThe log entry to format and write.