Skip to content

Commit

Permalink
Add log level configuration (#1156)
Browse files Browse the repository at this point in the history
* Add loglevel config

* Change order of fields

---------

Co-authored-by: John Grosh <john.a.grosh@gmail.com>
  • Loading branch information
MichailiK and jagrosh committed Mar 30, 2024
1 parent 801b376 commit b3ffbdb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/jagrosh/jmusicbot/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BotConfig
private final static String END_TOKEN = "/// END OF JMUSICBOT CONFIG ///";

private Path path = null;
private String token, prefix, altprefix, helpWord, playlistsFolder,
private String token, prefix, altprefix, helpWord, playlistsFolder, logLevel,
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds, aloneTimeUntilStop;
Expand Down Expand Up @@ -86,6 +86,7 @@ public void load()
songInGame = config.getBoolean("songinstatus");
npImages = config.getBoolean("npimages");
updatealerts = config.getBoolean("updatealerts");
logLevel = config.getString("loglevel");
useEval = config.getBoolean("eval");
maxSeconds = config.getLong("maxtime");
aloneTimeUntilStop = config.getLong("alonetimeuntilstop");
Expand Down Expand Up @@ -312,7 +313,12 @@ public boolean useUpdateAlerts()
{
return updatealerts;
}


public String getLogLevel()
{
return logLevel;
}

public boolean useEval()
{
return useEval;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/JMusicBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;

/**
*
Expand Down Expand Up @@ -82,6 +83,10 @@ private static void startBot()
if(!config.isValid())
return;
LOG.info("Loaded config from " + config.getConfigLocation());

// set log level from config
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(
Level.toLevel(config.getLogLevel(), Level.INFO));

// set up the listener
EventWaiter waiter = new EventWaiter();
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ aliases {
}


// This sets the logging verbosity.
// Available levels: off, error, warn, info, debug, trace, all
//
// It is recommended to leave this at info. Debug log levels might help with troubleshooting,
// but can contain sensitive data.

loglevel = info


// Transforms are used to modify specific play inputs and convert them to different kinds of inputs
// These are quite complicated to use, and have limited use-cases, but in theory allow for rough
// whitelists or blacklists, roundabout loading from some sources, and customization of how things are
Expand Down

0 comments on commit b3ffbdb

Please sign in to comment.