aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-06-23 18:51:27 -0500
committerGitHub <noreply@github.com>2024-06-23 18:51:27 -0500
commit1e33bcab3788bb93361bab0bba6a72277285591d (patch)
tree55b51bb500d56aa8ba97278cae96fc01056f4b57 /src
parent96f3dafb1cff11275cecd7139993710ed7e3f8ca (diff)
parent5ee509263e5cbd327108c3604dd41910cdfa87c6 (diff)
downloadslskd-1e33bcab3788bb93361bab0bba6a72277285591d.tar.gz
Merge pull request #1155 from slskd/colors
Add the ability to disable console log coloring
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Options.cs9
-rw-r--r--src/slskd/Program.cs2
2 files changed, 11 insertions, 0 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 05174031..cad58817 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -1294,6 +1294,15 @@ namespace slskd
[Description("enable logging to disk")]
[RequiresRestart]
public bool Disk { get; init; } = false;
+
+ /// <summary>
+ /// Gets a value indicating whether to suppress colorization of console logs.
+ /// </summary>
+ [Argument(default, "no-color")]
+ [EnvironmentVariable("NO_COLOR")]
+ [Description("disable console log colors")]
+ [RequiresRestart]
+ public bool NoColor { get; init; } = false;
}
/// <summary>
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 81554b62..d47d3d91 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -52,6 +52,7 @@ namespace slskd
using Serilog;
using Serilog.Events;
using Serilog.Sinks.Grafana.Loki;
+ using Serilog.Sinks.SystemConsole.Themes;
using slskd.Authentication;
using slskd.Configuration;
using slskd.Core.API;
@@ -973,6 +974,7 @@ namespace slskd
.Enrich.WithProperty("ProcessId", ProcessId)
.Enrich.FromLogContext()
.WriteTo.Console(
+ theme: (OptionsAtStartup.Logger.NoColor || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NO_COLOR"))) ? ConsoleTheme.None : SystemConsoleTheme.Literate,
outputTemplate: (OptionsAtStartup.Debug ? "[{SourceContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Async(config =>
config.Conditional(