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側のログが二重になっていたり、なっていなかったりする。この一貫性のなさの原因は?
ログが二重になったり、ならなかったりする原因は、discord.pyが独自のロギング設定を持っていることと、あなたのコードでのロギング設定が競合していることです。
具体的には:
dictConfigを使って全体のロギング設定を上書きしていますが、これがdiscord.pyのロガー設定と部分的に競合していますこの問題を解決するには、discord.pyのロギング設定を尊重しつつ、あなたのアプリケーション固有のロガーだけを設定するか、または明示的にdiscord.pyのロガーも含めた統一的な設定を行うとよいでしょう。
Would you like me to explain how to fix this issue in more detail?
discord.py側が変なことをしているからこうなっているなら、問題は放置でいい。こっちが間違っているのなら直す。どう?
discord.pyは特に変なことはしていません。これはPythonのロギングシステムの一般的な動作です。
あなたのコードではrootロガーを設定していますが、これはすべてのロガー(discord.pyのロガーを含む)の親になります。一方、discord.pyも独自にロガーを設定しています。
問題を簡単に修正するなら、あなたのアプリケーション専用のロガーだけを設定して、discord.pyのロガーはそのままにするのが良いでしょう。具体的には、rootロガーではなく、あなたのアプリケーション名前空間のロガーだけを設定します。
放置しても機能的な問題はありませんが、ログが二重に出力されると読みにくくなります。修正するのがおすすめです。