Skip to content

Commit

Permalink
Disable in-memory logger if verbose logging is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Aug 24, 2024
1 parent e794869 commit 5bd4b82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Commands/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ public async Task Shell(CommandContext ctx, [RemainingText] string command)
[Command("logs")]
public async Task Logs(CommandContext ctx)
{
if (Program.cfgjson.LogLevel is Level.Verbose)
{
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.");
return;
}

await DiscordHelpers.SafeTyping(ctx.Channel);

string result = Regex.Replace(Program.outputCapture.ToString(), "ghp_[0-9a-zA-Z]{36}", "ghp_REDACTED").Replace(Environment.GetEnvironmentVariable("CLIPTOK_TOKEN"), "REDACTED");
Expand Down
4 changes: 3 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static async Task Main(string[] _)

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

Expand Down Expand Up @@ -119,6 +118,9 @@ static async Task Main(string[] _)
break;
}

if (cfgjson.LogLevel is not Level.Verbose)
loggerConfig.WriteTo.TextWriter(outputCapture, outputTemplate: logFormat);

if (cfgjson.LokiURL is not null && cfgjson.LokiServiceName is not null)
{
loggerConfig.WriteTo.GrafanaLoki(cfgjson.LokiURL, [new LokiLabel { Key = "app", Value = cfgjson.LokiServiceName }]);
Expand Down

0 comments on commit 5bd4b82

Please sign in to comment.