This repository has been archived on 2023-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
automated-youtube-dl/server/logging.py

43 lines
1.3 KiB
Python

import logging
import re
import threading
# Universal formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Create a thread-local object
local = threading.local()
# def new_db_connection(thread: bool = True):
# if opts.mysql['host']:
# if thread:
# # Check if a connection already exists for the current thread
# if not hasattr(local, 'db'):
# # Create a new connection if it doesn't exist
# local.db = mysql.connector.connect(
# host=opts.mysql['host'],
# user=opts.mysql['user'],
# password=opts.mysql['password'],
# database=opts.mysql['database']
# )
# return local.db
# else:
# return mysql.connector.connect(
# host=opts.mysql['host'],
# user=opts.mysql['user'],
# password=opts.mysql['password'],
# database=opts.mysql['database']
# )
def print_without_paths(msg):
"""
Remove any filepaths or other stuff we don't want in the message.
"""
m = re.match(r'(^[^/]+(?:\\.[^/]*)*)', msg)
if m:
msg = m.group(1)
m1 = re.match(r'^(.*?): ', msg)
return msg.strip('to "').strip('to: ').strip()