Skip to content

Commit

Permalink
Add independant log level for Discord clients in Discord server confi…
Browse files Browse the repository at this point in the history
…gs (#228)
  • Loading branch information
versx authored Mar 18, 2022
1 parent fdb366d commit 01ee20f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/config/discords.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ Copy your Discord specific configs to the `bin/discords` folder and reference th
}
},
// Icon style for postings from Discord server.
"iconStyle": "Default"
"iconStyle": "Default",
// Discord client log level, only change if debugging an issue with Discord (default: 4 aka Error)
"logLevel": 4
}
```
3 changes: 2 additions & 1 deletion examples/discords/discord1.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@
"channelId": 0
}
},
"iconStyle": "Default"
"iconStyle": "Default",
"logLevel": 4
}
3 changes: 2 additions & 1 deletion examples/discords/discord2.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@
"channelId": 0
}
},
"iconStyle": "Default"
"iconStyle": "Default",
"logLevel": 4
}
9 changes: 9 additions & 0 deletions src/Configuration/DiscordServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Linq;
using System.Text.Json.Serialization;

using Microsoft.Extensions.Logging;

using WhMgr.Services.Geofence;

/// <summary>
Expand Down Expand Up @@ -94,12 +96,19 @@ public class DiscordServerConfig
[JsonPropertyName("iconStyle")]
public string IconStyle { get; set; } = "Default";

/// <summary>
/// Gets or sets the DiscordClient minimum log level to use for the DSharpPlus
/// internal logger (separate from the main logs)
/// </summary>
public LogLevel LogLevel { get; set; }

/// <summary>
/// Instantiate a new <see cref="DiscordServerConfig"/> class
/// </summary>
public DiscordServerConfig()
{
//Locale = "en";
LogLevel = LogLevel.Error;
}

public void LoadGeofences()
Expand Down
3 changes: 2 additions & 1 deletion src/Services/Discord/DiscordClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public static DiscordClient CreateDiscordClient(DiscordServerConfig config, ISer
{
AutoReconnect = true,
AlwaysCacheMembers = true,
// REVIEW: Hmm maybe we should compress the whole stream instead of just payload.
GatewayCompressionLevel = GatewayCompressionLevel.Payload,
Token = config.Bot?.Token,
TokenType = TokenType.Bot,
MinimumLogLevel = Microsoft.Extensions.Logging.LogLevel.Error,
MinimumLogLevel = config.LogLevel,
Intents = DiscordIntents.DirectMessages
| DiscordIntents.DirectMessageTyping
| DiscordIntents.GuildEmojis
Expand Down

0 comments on commit 01ee20f

Please sign in to comment.