Skip to content

Commit

Permalink
Remove in-memory logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Nov 3, 2024
1 parent 14460d6 commit d4ba0c4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
17 changes: 1 addition & 16 deletions Commands/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,7 @@ 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");

if (Environment.GetEnvironmentVariable("CLIPTOK_ANTIPHISHING_ENDPOINT") is not null)
{
result = result.Replace(Environment.GetEnvironmentVariable("CLIPTOK_ANTIPHISHING_ENDPOINT"), "REDACTED");
}

await ctx.RespondAsync(await StringHelpers.CodeOrHasteBinAsync(result));
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command has been removed! Please find logs through other means.");
}

[Command("dumpwarnings"), Description("Dump all warning data. EXTREMELY computationally expensive, use with caution.")]
Expand Down
7 changes: 0 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class Program : BaseCommandModule
public static Random rand = new();
public static HasteBinClient hasteUploader;

public static StringBuilder outputStringBuilder = new(16, 200000000);
public static StringWriter outputCapture;

static public readonly HttpClient httpClient = new();

public static List<ServerApiResponseJson> serverApiList = new();
Expand All @@ -77,7 +74,6 @@ public static void UpdateLists()
static async Task Main(string[] _)
{
Console.OutputEncoding = Encoding.UTF8;
outputCapture = new(outputStringBuilder);

httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var logFormat = "[{Timestamp:yyyy-MM-dd HH:mm:ss zzz}] [{Level}] {Message}{NewLine}{Exception}";
Expand Down Expand Up @@ -125,9 +121,6 @@ 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 d4ba0c4

Please sign in to comment.