Skip to content

Commit

Permalink
Added filter to prevent useless Session is disconnected warning in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
JaiZed committed Dec 27, 2023
1 parent 7c40bfe commit 9e75acd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bazarr/app/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ def format(self, record):
def formatException(self, record):
return ''


class UnwantedWaitressMessageFilter(logging.Filter):
def filter(self, record):
if settings.general.debug == True:
# no filtering in debug mode
return True

unwantedMessages = [
"Exception while serving /api/socket.io/",
['Session is disconnected', 'Session not found' ],

"Exception while serving /api/socket.io/",
["'Session is disconnected'", "'Session not found'" ],

"Exception while serving /api/socket.io/",
['"Session is disconnected"', '"Session not found"' ]
]

wanted = True
listLength = len(unwantedMessages)
for i in range(0, listLength, 2):
if record.msg == unwantedMessages[i]:
exceptionTuple = record.exc_info
if exceptionTuple != None:
if str(exceptionTuple[1]) in unwantedMessages[i+1]:
wanted = False
break

return wanted


def configure_logging(debug=False):
warnings.simplefilter('ignore', category=ResourceWarning)
Expand Down Expand Up @@ -129,6 +159,7 @@ def configure_logging(debug=False):
logging.getLogger("ga4mp.ga4mp").setLevel(logging.ERROR)

logging.getLogger("waitress").setLevel(logging.ERROR)
logging.getLogger("waitress").addFilter(UnwantedWaitressMessageFilter())
logging.getLogger("knowit").setLevel(logging.CRITICAL)
logging.getLogger("enzyme").setLevel(logging.CRITICAL)
logging.getLogger("guessit").setLevel(logging.WARNING)
Expand Down

0 comments on commit 9e75acd

Please sign in to comment.