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 のログをカスタムのフォーマットに統一し、二重のログ出力を止めるには、Discord.py のロガーを直接設定する必要があります。以下は、Discord.py のロガーをカスタムの設定に合わせる方法です。
まず、Discord.py のロガーを設定して、二重のログ出力を止めます。これには、Discord.py のロガーを取得し、ハンドラーをクリアして、新しいハンドラーを追加する必要があります。
以下は、Discord.py のロガーを設定し、二重のログ出力を止めるためのコードです。
# main.py
import os
from logging import getLogger, getLoggerClass, Logger
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__)
# Clear existing handlers and add new handlers to discord loggers
discord_logger = getLogger('discord')
discord_logger.handlers.clear()
for handler in logger.handlers:
discord_logger.addHandler(handler)
# Ensure all child loggers of discord are also updated
for name in getLoggerClass().root.manager.loggerDict:
if name.startswith('discord'):
child_logger = getLogger(name)
child_logger.handlers.clear()
for handler in logger.handlers:
child_logger.addHandler(handler)
# Your bot code
intents = discord.Intents.default()
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
logger.info(f'Successfully logged in as {bot.user}')
# Run the bot
bot.run(os.getenv('DISCORD_TOKEN'))
discord ロガーとその子ロガーから既存のハンドラーをクリアします。discord ロガーとその子ロガーに追加します。これにより、Discord.py のログもカスタムのフォーマットに統一され、二重のログ出力が止まります。