Untitled conversation
- Usercode
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
# main.py
import os
from logging import getLogger
from logging.config import dictConfig
import discord
from discord.ext import commands
# Logging
logging_settings = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"color": {
"()": "colorlog.ColoredFormatter",
"format": "%(log_color)s%(asctime)s %(name)s:%(lineno)d %(funcName)s [%(levelname)s]:%(reset)s %(message)s",
"log_colors": {
"DEBUG": "white",
"INFO": "green",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "red,bg_white"
},
"style": "%"
},
"simple": {
"format": "%(asctime)s %(name)s:%(lineno)d %(funcName)s [%(levelname)s]: %(message)s"
}
},
"handlers": {
"consoleHandler": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "color",
"stream": "ext://sys.stdout"
},
"fileHandler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "simple",
"filename": "application.log",
"maxBytes": 10485760,
"backupCount": 5,
"encoding": "utf-8"
}
},
"root": {
"level": "DEBUG",
"handlers": ["consoleHandler", "fileHandler"]
}
}
dictConfig(logging_settings)
logger = getLogger(__name__)
"D:\LLM API\Nyabi\venv\Scripts\python.exe" "D:\LLM API\Nyabi\main.py"
2025-05-19 21:24:32,388 discord.client:318 __init__ [WARNING]: PyNaCl is not installed, voice will NOT be supported
2025-05-19 21:24:32,391 discord.client:643 login [INFO]: logging in using static token
[2025-05-19 21:24:32] [INFO ] discord.client: logging in using static token
2025-05-19 21:24:33,801 discord.gateway:562 received_message [INFO]: Shard ID None has connected to Gateway (Session ID: 061ea72f2210795798de7da89203a05b).
[2025-05-19 21:24:33] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 061ea72f2210795798de7da89203a05b).
2025-05-19 21:24:35,809 src.cogs.commands:13 __init__ [INFO]: hi from CommandsCog!
2025-05-19 21:24:36,191 __main__:77 on_ready [INFO]: Successfully logged in as Nyabi#3449
discord.py側のログを自身のフォーマットに統一し、現在の二重のログを止めたいとき、ベストな方法は?
この状況を解決するためのベストプラクティスは以下のようになります:
import logging
import discord
from logging.config import dictConfig
# 既存のlogging_settingsはそのまま維持
# discord.pyのロガーを取得し、既存の設定を上書き
discord_logger = logging.getLogger('discord')
discord_logger.handlers = [] # 既存のハンドラをクリア
discord_logger.propagate = False # ルートロガーへの伝播を防止
# ルートロガーの設定を更新
logging_settings['root']['handlers'] = ['consoleHandler', 'fileHandler']
# ロギング設定を適用
dictConfig(logging_settings)
# これで discord.py のログが重複せず、統一されたフォーマットで出力されます
主なポイント:
discord_logger.handlers = [] で既存のハンドラを削除discord_logger.propagate = False で重複ログを防止これにより:
追加のヒント:
colorlog を使用しているので、pip install colorlog を忘れずに