From 6e77c4f214c9d8a258c1e39c465cc63fc1912850 Mon Sep 17 00:00:00 2001
From: Zoƫ Liebersbach <13294419+zliebersbach@users.noreply.github.com>
Date: Fri, 31 May 2024 15:29:32 +1000
Subject: Add option to disable console log colors
---
src/slskd/Core/Options.cs | 9 +++++++++
src/slskd/Program.cs | 2 ++
2 files changed, 11 insertions(+)
(limited to 'src')
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;
+
+ ///
+ /// Gets a value indicating whether console logs should be colorized.
+ ///
+ [Argument(default, "no-color")]
+ [EnvironmentVariable("NO_COLOR")]
+ [Description("disable console log colors")]
+ [RequiresRestart]
+ public bool Color { get; init; } = true;
}
///
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(
--
cgit v1.2.3
From c5410c9b22bbd16e0b72873b81dfff4e37e1281d Mon Sep 17 00:00:00 2001
From: JP Dillingham
Date: Sun, 23 Jun 2024 18:07:47 -0500
Subject: Color -> NoColor
---
src/slskd/Core/Options.cs | 4 ++--
src/slskd/Program.cs | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'src')
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 8aa915fc..cad58817 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -1296,13 +1296,13 @@ namespace slskd
public bool Disk { get; init; } = false;
///
- /// Gets a value indicating whether console logs should be colorized.
+ /// Gets a value indicating whether to suppress colorization of console logs.
///
[Argument(default, "no-color")]
[EnvironmentVariable("NO_COLOR")]
[Description("disable console log colors")]
[RequiresRestart]
- public bool Color { get; init; } = true;
+ public bool NoColor { get; init; } = false;
}
///
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index deae45e8..8e236652 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -974,7 +974,7 @@ namespace slskd
.Enrich.WithProperty("ProcessId", ProcessId)
.Enrich.FromLogContext()
.WriteTo.Console(
- theme: OptionsAtStartup.Logger.Color ? SystemConsoleTheme.Literate : ConsoleTheme.None,
+ theme: OptionsAtStartup.Logger.NoColor ? 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(
--
cgit v1.2.3
From 92823a70694e2dda9b3a5225be5b708e0ef230fd Mon Sep 17 00:00:00 2001
From: JP Dillingham
Date: Sun, 23 Jun 2024 18:43:36 -0500
Subject: docs, add NO_COLOR support
---
config/slskd.example.yml | 4 ++--
docs/config.md | 17 +++++++++++------
src/slskd/Program.cs | 2 +-
3 files changed, 14 insertions(+), 9 deletions(-)
(limited to 'src')
diff --git a/config/slskd.example.yml b/config/slskd.example.yml
index c537229b..5f028582 100644
--- a/config/slskd.example.yml
+++ b/config/slskd.example.yml
@@ -170,8 +170,8 @@
# incomplete: 43200 # 30 days
# logs: 259200 # 180 days
# logger:
-# no_disk: false
-# no_color: true
+# disk: false
+# no_color: false
# loki: ~
# metrics:
# enabled: false
diff --git a/docs/config.md b/docs/config.md
index a772238c..57e8eeb4 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -1001,9 +1001,16 @@ The instance name uniquely identifies the running instance of the application. I
instance_name: default
```
-## Loggers
+## Logging Options and Configurable Loggers
-By default, the application logs to console and to disk (`/logs` in the application directory); disk logging can be disabled.
+By default, the application logs to console with colors enabled. Logging to disk is optional, and if enabled, logs will be written to `/logs` in the application directory.
+
+Console colors can be disabled via typical application configuration described below, or by setting the environment variable `NO_COLOR` in accordance with https://no-color.org/.
+
+| Command Line | Environment Variable | Description |
+| ------------------ | ------------------------------ | ---------------------------------- |
+| `--disk-logger` | `SLSKD_DISK_LOGGER` | Enable logging to disk |
+| `--no-color` | `SLSKD_NO_COLOR` or `NO_COLOR` | Disable console log colors |
Logs can optionally be forwarded to external services, and the targets can be expanded to any service supported by a [Serilog Sink](https://github.com/serilog/serilog/wiki/Provided-Sinks). Support for targets is added on an as-needed basis and within reason.
@@ -1012,15 +1019,13 @@ The current list of available targets is:
| Command Line | Environment Variable | Description |
| ------------------ | -------------------------- | ---------------------------------- |
| `--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
+ disk: false
+ no_color: false
```
## Metrics
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 8e236652..d47d3d91 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -974,7 +974,7 @@ namespace slskd
.Enrich.WithProperty("ProcessId", ProcessId)
.Enrich.FromLogContext()
.WriteTo.Console(
- theme: OptionsAtStartup.Logger.NoColor ? ConsoleTheme.None : SystemConsoleTheme.Literate,
+ 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(
--
cgit v1.2.3