aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZoë Liebersbach <13294419+zliebersbach@users.noreply.github.com>2024-05-31 15:29:32 +1000
committerZoë Liebersbach <13294419+zliebersbach@users.noreply.github.com>2024-05-31 15:29:32 +1000
commit6e77c4f214c9d8a258c1e39c465cc63fc1912850 (patch)
tree73fc1816a37c9e145bfed4f017bb9f9246369ea5
parentb33449b0282d7f466be22570c26e9e3c982b888a (diff)
downloadslskd-6e77c4f214c9d8a258c1e39c465cc63fc1912850.tar.gz
Add option to disable console log colors
-rw-r--r--config/slskd.example.yml1
-rw-r--r--docs/config.md2
-rw-r--r--src/slskd/Core/Options.cs9
-rw-r--r--src/slskd/Program.cs2
4 files changed, 14 insertions, 0 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml
index 2552e081..d55bfd45 100644
--- a/config/slskd.example.yml
+++ b/config/slskd.example.yml
@@ -171,6 +171,7 @@
# logs: 259200 # 180 days
# logger:
# disk: true
+# color: true
# loki: ~
# metrics:
# enabled: false
diff --git a/docs/config.md b/docs/config.md
index 87fb916b..82a5c734 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -1013,12 +1013,14 @@ The current list of available targets is:
| ------------------ | -------------------------- | ---------------------------------- |
| `--loki` | `SLSKD_LOKI` | The URL to a Grafana Loki instance |
| `--no-disk-logger` | `SLSKD_NO_DISK_LOGGER` | Disable logging to disk |
+| `--no-color` | `SLSKD_NO_COLOR` | Disable console log colors |
#### **YAML**
```yaml
logger:
loki: ~
disk: true
+ color: true
```
## Metrics
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 1b049ae1..a8c3b029 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -1294,6 +1294,15 @@ namespace slskd
[Description("disable logging to disk")]
[RequiresRestart]
public bool Disk { get; init; } = true;
+
+ /// <summary>
+ /// Gets a value indicating whether console logs should be colorized.
+ /// </summary>
+ [Argument(default, "no-color")]
+ [EnvironmentVariable("NO_COLOR")]
+ [Description("disable console log colors")]
+ [RequiresRestart]
+ public bool Color { get; init; } = true;
}
/// <summary>
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 27cbfc6f..496ac0a9 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;
@@ -977,6 +978,7 @@ namespace slskd
.Enrich.WithProperty("ProcessId", ProcessId)
.Enrich.FromLogContext()
.WriteTo.Console(
+ theme: OptionsAtStartup.Logger.Color ? SystemConsoleTheme.Literate : ConsoleTheme.None,
outputTemplate: (OptionsAtStartup.Debug ? "[{SourceContext}] " : string.Empty) + "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Async(config =>
config.Conditional(