diff --git a/README.md b/README.md index 364df83..452ef87 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ botdarr: | Environment Variable | Description | Required | Default | | :---: | :---: | :---: | :---: | | DISCORD_TOKEN | The discord bot token (don't share) | yes - if you use discord | | -| DISCORD_CHANNELS | The actual discord channel(s) the bot lives in | yes - if you use discord | +| DISCORD_CHANNELS | The actual discord channel(s) names the bot has access to. If multiple channel names specified, separate via a comma | yes - if you use discord | | TELEGRAM_TOKEN | The telegram bot token (don't share) | yes - if you use telegram | | TELEGRAM_PRIVATE_CHANNELS | Your actual telegram channels your bot can respond in. This should be a list containing the name and id of the channel, i.e., CHANNEL_NAME:CHANNEL_ID to get the channel id, right click any post in private channel and copy post link you should see something like this, https://t.me/c/1408146664/63 the id is between c// example: plex-channel1:id1,plex-channel2:id2 | yes - if you use telegram | | TELEGRAM_PRIVATE_GROUPS | Your actual telegram groups your bot can respond in. This should be a list containing the name and id of the group, i.e., GROUP_NAME:GROUP_ID to get the channel id, right click any post in private group and copy post link (you need to enable message history for this) you should see something like this, https://t.me/c/1408146664/63 the id is between c// example: plex-group1:id1,plex-group2:id2 | yes - if you use telegram | @@ -178,6 +178,7 @@ botdarr: | COMMAND_PREFIX | The command prefix (default is !). Any prefix is allowed (but I haven't tested every single prefix in every client) | yes | ! | | STATUS_ENDPOINTS | Endpoints that can be used to return statuses via !status command. The endpoints are separated by a comma and each endpoint is in the following format - name:hostname:port | no | | | TIMEOUT | The connection/read timeout value (in milliseconds) for all outbound requests | no | 5000 | +| LOG_LEVEL | The log4j log level | no | info |
## Usage diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 6b0998b..da16c1d 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -54,6 +54,7 @@ if [ ! -e "$propertiesFile" ]; then [[ ! -z "${MAX_MOVIE_REQUESTS_PER_USER}" ]] && addConfiguration "max-movie-requests-per-user" "${MAX_MOVIE_REQUESTS_PER_USER}" "${propertiesFile}" [[ ! -z "${EXISTING_ITEM_PATHS_BLACKLIST}" ]] && addConfiguration "existing-item-paths-blacklist" "${EXISTING_ITEM_PATHS_BLACKLIST}" "${propertiesFile}" [[ ! -z "${STATUS_ENDPOINTS}" ]] && addConfiguration "status-endpoints" "${STATUS_ENDPOINTS}" "${propertiesFile}" + [[ ! -z "${LOG_LEVEL}" ]] && addConfiguration "log-level" "${LOG_LEVEL}" "${propertiesFile}" addConfiguration "max-downloads-to-show" "${MAX_DOWNLOADS_TO_SHOW:-20}" "${propertiesFile}" addConfiguration "max-results-to-show" "${MAX_RESULTS_TO_SHOW:-20}" "${propertiesFile}" diff --git a/sample.properties b/sample.properties index 32c6c3f..dbc7a6c 100644 --- a/sample.properties +++ b/sample.properties @@ -1,6 +1,8 @@ # Your bot token goes here (don't share) #discord-token= -# The actual discord channel(s) the bot lives in +# The actual discord channel(s) name the bot lives in +# This is the specific channel(s) name, not the channel id +# If you specify multiple channels, they should be separated by a column #discord-channels= # Your slack bot oauth authentication token @@ -88,4 +90,8 @@ existing-item-paths-blacklist= # Comma delimited Status endpoints (i.e., endpoints you want checked when the !status command is called) # i.e., some-name:hostname:port,some-other-name:hostname2:port -#status-endpoints= \ No newline at end of file +#status-endpoints= + +# The log4j log level (i.e., info, debug, trace, warn) +# This is info by default +#log-level= \ No newline at end of file diff --git a/src/main/java/com/botdarr/Config.java b/src/main/java/com/botdarr/Config.java index 441c404..3f900e7 100644 --- a/src/main/java/com/botdarr/Config.java +++ b/src/main/java/com/botdarr/Config.java @@ -5,8 +5,12 @@ import com.botdarr.clients.matrix.MatrixBootstrap; import com.botdarr.clients.slack.SlackBootstrap; import com.botdarr.clients.telegram.TelegramBootstrap; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.LoggerConfig; import org.apache.logging.log4j.util.Strings; import java.io.FileInputStream; @@ -14,6 +18,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.*; +import java.util.function.BiConsumer; import static com.botdarr.commands.StatusCommand.*; @@ -36,6 +41,14 @@ private Config() { properties = new Properties(); properties.load(input); + String logLevel = properties.getProperty(Constants.LOG_LEVEL); + if (!Strings.isEmpty(logLevel)) { + LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + Configuration config = ctx.getConfiguration(); + config.getLoggers().forEach((s, loggerConfig) -> loggerConfig.setLevel(Level.valueOf(logLevel))); + ctx.updateLoggers(); + } + List availableBootstraps = Arrays.asList( new DiscordBootstrap(), new MatrixBootstrap(), @@ -85,7 +98,7 @@ private Config() { LOGGER.warn("Lidarr commands are not enabled, make sure you set the lidarr url, path, token, default profile"); } - String configuredPrefix = properties.getProperty(Config.Constants.COMMAND_PREFIX); + String configuredPrefix = properties.getProperty(Constants.COMMAND_PREFIX); if (!Strings.isEmpty(configuredPrefix)) { chatClientBootstrap.validatePrefix(configuredPrefix); } @@ -387,6 +400,11 @@ public static final class Constants { * Connection/read timeouts for all outbound requests */ public static final String TIMEOUT = "timeout"; + + /** + * Config for the log level + */ + public static final String LOG_LEVEL = "log-level"; } private static String propertiesPath = "config/properties"; diff --git a/src/main/java/com/botdarr/clients/discord/DiscordChatClient.java b/src/main/java/com/botdarr/clients/discord/DiscordChatClient.java index a387110..5b21b6e 100644 --- a/src/main/java/com/botdarr/clients/discord/DiscordChatClient.java +++ b/src/main/java/com/botdarr/clients/discord/DiscordChatClient.java @@ -6,6 +6,7 @@ import com.google.common.collect.Sets; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.TextChannel; +import org.apache.logging.log4j.LogManager; import java.util.*; import java.util.List; @@ -32,9 +33,11 @@ private void sendMessages(MessageSender messageSender, String channelName) { Set supportedDiscordChannels = Sets.newHashSet(Splitter.on(',').trimResults().split(Config.getProperty(Config.Constants.DISCORD_CHANNELS))); for (TextChannel textChannel : jda.getTextChannels()) { if (!supportedDiscordChannels.contains(textChannel.getName())) { + LogManager.getLogger("com.botdarr.clients.discord").warn("Channel " + textChannel.getName() + " is not configured to receive messages"); continue; } if (channelName != null && !channelName.equalsIgnoreCase(textChannel.getName())) { + LogManager.getLogger("com.botdarr.clients.discord").debug("Channel " + textChannel.getName() + " doesn't match target channel " + channelName); continue; } messageSender.send(textChannel); diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 3884b9b..86f2a61 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -5.3.3 \ No newline at end of file +5.3.4 \ No newline at end of file