mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-15 12:41:38 +00:00
Added ANSI colors for log level formatting
This commit is contained in:
parent
00237b1784
commit
2210118596
@ -11,6 +11,13 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME)
|
|||||||
|
|
||||||
private static RustService? RUST_SERVICE;
|
private static RustService? RUST_SERVICE;
|
||||||
|
|
||||||
|
// ANSI color codes for log levels
|
||||||
|
private const string ANSI_RESET = "\x1b[0m";
|
||||||
|
private const string ANSI_GRAY = "\x1b[90m"; // Trace, Debug
|
||||||
|
private const string ANSI_GREEN = "\x1b[32m"; // Information
|
||||||
|
private const string ANSI_YELLOW = "\x1b[33m"; // Warning
|
||||||
|
private const string ANSI_RED = "\x1b[91m"; // Error, Critical
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the Rust service for logging events.
|
/// Sets the Rust service for logging events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -27,8 +34,9 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME)
|
|||||||
var logLevel = logEntry.LogLevel.ToString();
|
var logLevel = logEntry.LogLevel.ToString();
|
||||||
var category = logEntry.Category;
|
var category = logEntry.Category;
|
||||||
var exception = logEntry.Exception?.ToString();
|
var exception = logEntry.Exception?.ToString();
|
||||||
|
var colorCode = GetColorForLogLevel(logEntry.LogLevel);
|
||||||
|
|
||||||
textWriter.Write($"[{timestamp}] {logLevel} [{category}] {message}");
|
textWriter.Write($"{colorCode}[{timestamp}] {logLevel} [{category}]{ANSI_RESET} {message}");
|
||||||
if (exception is not null)
|
if (exception is not null)
|
||||||
textWriter.Write($" Exception: {exception}");
|
textWriter.Write($" Exception: {exception}");
|
||||||
|
|
||||||
@ -37,4 +45,15 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME)
|
|||||||
// Send log event to Rust via API (fire-and-forget):
|
// Send log event to Rust via API (fire-and-forget):
|
||||||
RUST_SERVICE?.LogEvent(timestamp, logLevel, category, message, exception);
|
RUST_SERVICE?.LogEvent(timestamp, logLevel, category, message, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetColorForLogLevel(LogLevel logLevel) => logLevel switch
|
||||||
|
{
|
||||||
|
LogLevel.Trace => ANSI_GRAY,
|
||||||
|
LogLevel.Debug => ANSI_GRAY,
|
||||||
|
LogLevel.Information => ANSI_GREEN,
|
||||||
|
LogLevel.Warning => ANSI_YELLOW,
|
||||||
|
LogLevel.Error => ANSI_RED,
|
||||||
|
LogLevel.Critical => ANSI_RED,
|
||||||
|
_ => ANSI_RESET
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user