Replies: 7 comments 9 replies
-
Chat GPT‑4o recommends:
This is making a log file but there are some issues because of colorlog where its adding ANSI escape codes to the log file. |
Beta Was this translation helpful? Give feedback.
-
Chat GPT‑4o:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
fixing log duplicate in console import logging
from colorlog import ColoredFormatter
# Logging configuration
LOG_LEVEL = logging.DEBUG
LOGFORMAT_CONSOLE = "%(log_color)s[Master HamsterKombat Bot]%(reset)s[%(log_color)s%(levelname)s%(reset)s] %(asctime)s %(log_color)s%(message)s%(reset)s"
LOGFORMAT_FILE = "[Master HamsterKombat Bot][%(levelname)s] %(asctime)s %(message)s"
# Create a logger
log = logging.getLogger("pythonConfig")
log.setLevel(LOG_LEVEL)
# Console handler
console_handler = logging.StreamHandler()
console_handler.setLevel(LOG_LEVEL)
console_handler.setFormatter(ColoredFormatter(LOGFORMAT_CONSOLE, "%Y-%m-%d %H:%M:%S"))
# File handler for logging to a file
file_handler = logging.FileHandler("output.log")
file_handler.setLevel(LOG_LEVEL)
file_handler.setFormatter(logging.Formatter(LOGFORMAT_FILE, "%Y-%m-%d %H:%M:%S"))
# Add handlers to the logger
log.addHandler(console_handler)
log.addHandler(file_handler)
# End of logging configuration
# Test logging
log.error(f"Log test") |
Beta Was this translation helpful? Give feedback.
-
If anyone wants local logging use main.py in my test branch. |
Beta Was this translation helpful? Give feedback.
-
Moved to #301. |
Beta Was this translation helpful? Give feedback.
-
Logging code still doesn't create a log file.
Beta Was this translation helpful? Give feedback.
All reactions