Skip to content

Commit 5bd4b82

Browse files
committed
Disable in-memory logger if verbose logging is enabled
1 parent e794869 commit 5bd4b82

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Commands/Debug.cs

+6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ public async Task Shell(CommandContext ctx, [RemainingText] string command)
168168
[Command("logs")]
169169
public async Task Logs(CommandContext ctx)
170170
{
171+
if (Program.cfgjson.LogLevel is Level.Verbose)
172+
{
173+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Verbose logging is enabled, so the in-memory logger is disabled. Please access the logs through another method.");
174+
return;
175+
}
176+
171177
await DiscordHelpers.SafeTyping(ctx.Channel);
172178

173179
string result = Regex.Replace(Program.outputCapture.ToString(), "ghp_[0-9a-zA-Z]{36}", "ghp_REDACTED").Replace(Environment.GetEnvironmentVariable("CLIPTOK_TOKEN"), "REDACTED");

Program.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ static async Task Main(string[] _)
7979

8080
var loggerConfig = new LoggerConfiguration()
8181
.WriteTo.Console(outputTemplate: logFormat, theme: AnsiConsoleTheme.Literate)
82-
.WriteTo.TextWriter(outputCapture, outputTemplate: logFormat)
8382
.WriteTo.DiscordSink(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, outputTemplate: logFormat)
8483
.Filter.ByExcluding(log => { return log.ToString().Contains("DSharpPlus.Exceptions.NotFoundException: Not found: NotFound"); });
8584

@@ -119,6 +118,9 @@ static async Task Main(string[] _)
119118
break;
120119
}
121120

121+
if (cfgjson.LogLevel is not Level.Verbose)
122+
loggerConfig.WriteTo.TextWriter(outputCapture, outputTemplate: logFormat);
123+
122124
if (cfgjson.LokiURL is not null && cfgjson.LokiServiceName is not null)
123125
{
124126
loggerConfig.WriteTo.GrafanaLoki(cfgjson.LokiURL, [new LokiLabel { Key = "app", Value = cfgjson.LokiServiceName }]);

0 commit comments

Comments
 (0)