Add option to disable connection logging

Was previously disabled by default, now enabled by default.
This commit is contained in:
Noi 2023-05-27 18:46:28 -07:00
parent b0b39bbd0b
commit 0944177897
2 changed files with 22 additions and 12 deletions

View file

@ -38,6 +38,11 @@ class Configuration {
/// Amount of time to wait between background task runs within each shard.
/// </summary>
public int BackgroundInterval { get; }
/// <summary>
/// Gets whether to show common connect/disconnect events and other related messages.
/// This is disabled in the public instance, but it's worth keeping enabled in self-hosted bots.
/// </summary>
public bool LogConnectionStatus { get; }
public Configuration() {
var args = CommandLineParameters.Parse(Environment.GetCommandLineArgs());
@ -89,6 +94,7 @@ class Configuration {
StatusInterval = ReadConfKey<int?>(jc, nameof(StatusInterval), false) ?? 90;
MaxConcurrentOperations = ReadConfKey<int?>(jc, nameof(MaxConcurrentOperations), false) ?? 4;
BackgroundInterval = ReadConfKey<int?>(jc, nameof(BackgroundInterval), false) ?? 60;
LogConnectionStatus = ReadConfKey<bool?>(jc, nameof(LogConnectionStatus), false) ?? true;
}
private static T? ReadConfKey<T>(JObject jc, string key, [DoesNotReturnIf(true)] bool failOnEmpty) {

View file

@ -72,23 +72,27 @@ public sealed class ShardInstance : IDisposable {
private Task Client_Log(LogMessage arg) {
// Suppress certain messages
if (arg.Message != null) {
switch (arg.Message) {
case "Connecting":
case "Connected":
case "Ready":
case "Disconnecting":
case "Disconnected":
case "Resumed previous session":
case "Failed to resume previous session":
case "Serializer Error": // The exception associated with this log appears a lot as of v3.2-ish
return Task.CompletedTask;
if (!_manager.Config.LogConnectionStatus) {
switch (arg.Message) {
case "Connecting":
case "Connected":
case "Ready":
case "Disconnecting":
case "Disconnected":
case "Resumed previous session":
case "Failed to resume previous session":
case "Serializer Error": // The exception associated with this log appears a lot as of v3.2-ish
return Task.CompletedTask;
}
}
Log("Discord.Net", $"{arg.Severity}: {arg.Message}");
}
if (arg.Exception != null) {
if (arg.Exception is GatewayReconnectException
|| arg.Exception.Message == "WebSocket connection was closed") return Task.CompletedTask;
if (!_manager.Config.LogConnectionStatus) {
if (arg.Exception is GatewayReconnectException || arg.Exception.Message == "WebSocket connection was closed")
return Task.CompletedTask;
}
Log("Discord.Net exception", arg.Exception.ToString());
}