Added a logging filter to suppress logs containing a specific string.
This commit is contained in:
@@ -19,19 +19,22 @@ client = OpenAI()
|
|||||||
GPT_4O = "gpt-4o"
|
GPT_4O = "gpt-4o"
|
||||||
GPT_4O_MINI = "gpt-4o-mini"
|
GPT_4O_MINI = "gpt-4o-mini"
|
||||||
|
|
||||||
class NoDebugFilter(logging.Filter):
|
class StringFilter(logging.Filter):
|
||||||
def filter(self, record):
|
def __init__(self, string_to_filter):
|
||||||
return "DEBUG" not in record.getMessage()
|
super().__init__()
|
||||||
|
self.string_to_filter = string_to_filter
|
||||||
|
|
||||||
# Set up logging to console and file with filter
|
def filter(self, record):
|
||||||
|
return self.string_to_filter not in record.getMessage()
|
||||||
|
|
||||||
|
string_to_filter = 'unwanted_string' # Change this to the specific string you want to filter out
|
||||||
|
|
||||||
|
# Set up logging to console and file
|
||||||
logging.basicConfig(level=logging.INFO, handlers=[
|
logging.basicConfig(level=logging.INFO, handlers=[
|
||||||
logging.StreamHandler(),
|
logging.StreamHandler(),
|
||||||
logging.FileHandler('logs/output.log', mode='a')
|
logging.FileHandler('logs/output.log', mode='a')
|
||||||
])
|
])
|
||||||
|
logging.getLogger().addFilter(StringFilter(string_to_filter))
|
||||||
# Add filter to the handlers
|
|
||||||
for handler in logging.getLogger().handlers:
|
|
||||||
handler.addFilter(NoDebugFilter())
|
|
||||||
|
|
||||||
# Set up Telegram bot
|
# Set up Telegram bot
|
||||||
TELEGRAM_BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
|
TELEGRAM_BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
|
||||||
|
|||||||
Reference in New Issue
Block a user