Skip to content

Commit

Permalink
Add back logback filter
Browse files Browse the repository at this point in the history
  • Loading branch information
MichailiK committed Apr 22, 2024
1 parent 55e4bcc commit 5c21773
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/java/com/jagrosh/jmusicbot/utils/LogBackTurboFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 John Grosh <john.a.grosh@gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jagrosh.jmusicbot.utils;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.turbo.TurboFilter;
import ch.qos.logback.core.spi.FilterReply;
import org.slf4j.Marker;

/**
* A TurboFilter, currently only used to suppress specific log messages from libraries.
*
* @author Michaili K. <git@michaili.dev>
*/
public class LogBackTurboFilter extends TurboFilter
{
@Override
public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t)
{
// Suppresses the auth token warning from the YoutubeAudioSourceManager
// https://github.com/jagrosh/MusicBot/pull/1490#issuecomment-1974070225
if (logger.getName().equals("com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAccessTokenTracker")
&& format.equals("YouTube auth tokens can't be retrieved because email and password is not set in YoutubeAudioSourceManager, age restricted videos will throw exceptions.")
) {
return FilterReply.DENY;
}

return FilterReply.NEUTRAL;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
<appender-ref ref="Simple"/>
</root>

<turboFilter class="com.jagrosh.jmusicbot.utils.LogBackTurboFilter" />

</configuration>

0 comments on commit 5c21773

Please sign in to comment.