Skip to content

Commit b3ffbdb

Browse files
MichailiKjagrosh
andauthored
Add log level configuration (#1156)
* Add loglevel config * Change order of fields --------- Co-authored-by: John Grosh <john.a.grosh@gmail.com>
1 parent 801b376 commit b3ffbdb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/main/java/com/jagrosh/jmusicbot/BotConfig.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class BotConfig
3939
private final static String END_TOKEN = "/// END OF JMUSICBOT CONFIG ///";
4040

4141
private Path path = null;
42-
private String token, prefix, altprefix, helpWord, playlistsFolder,
42+
private String token, prefix, altprefix, helpWord, playlistsFolder, logLevel,
4343
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji;
4444
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
4545
private long owner, maxSeconds, aloneTimeUntilStop;
@@ -86,6 +86,7 @@ public void load()
8686
songInGame = config.getBoolean("songinstatus");
8787
npImages = config.getBoolean("npimages");
8888
updatealerts = config.getBoolean("updatealerts");
89+
logLevel = config.getString("loglevel");
8990
useEval = config.getBoolean("eval");
9091
maxSeconds = config.getLong("maxtime");
9192
aloneTimeUntilStop = config.getLong("alonetimeuntilstop");
@@ -312,7 +313,12 @@ public boolean useUpdateAlerts()
312313
{
313314
return updatealerts;
314315
}
315-
316+
317+
public String getLogLevel()
318+
{
319+
return logLevel;
320+
}
321+
316322
public boolean useEval()
317323
{
318324
return useEval;

src/main/java/com/jagrosh/jmusicbot/JMusicBot.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
3939
import org.slf4j.Logger;
4040
import org.slf4j.LoggerFactory;
41+
import ch.qos.logback.classic.Level;
4142

4243
/**
4344
*
@@ -82,6 +83,10 @@ private static void startBot()
8283
if(!config.isValid())
8384
return;
8485
LOG.info("Loaded config from " + config.getConfigLocation());
86+
87+
// set log level from config
88+
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(
89+
Level.toLevel(config.getLogLevel(), Level.INFO));
8590

8691
// set up the listener
8792
EventWaiter waiter = new EventWaiter();

src/main/resources/reference.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ aliases {
182182
}
183183

184184

185+
// This sets the logging verbosity.
186+
// Available levels: off, error, warn, info, debug, trace, all
187+
//
188+
// It is recommended to leave this at info. Debug log levels might help with troubleshooting,
189+
// but can contain sensitive data.
190+
191+
loglevel = info
192+
193+
185194
// Transforms are used to modify specific play inputs and convert them to different kinds of inputs
186195
// These are quite complicated to use, and have limited use-cases, but in theory allow for rough
187196
// whitelists or blacklists, roundabout loading from some sources, and customization of how things are

0 commit comments

Comments
 (0)