Skip to content

Commit

Permalink
change logging output
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroquinc committed Feb 23, 2025
1 parent 52aee37 commit 74a5b14
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions utils/custom_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@
import json
from pathlib import Path
import sys
from datetime import datetime

LOG_LEVEL = 'DEBUG'
discord_logger = None

def create_logger():
"""
Creates and configures a logger with specified log level and formats for console and file logging.
Args:
None
Returns:
None
Raises:
None
"""
logs_path = Path('logs')
logs_path.mkdir(exist_ok=True)
log_format = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level}</level> | <level>{message}</level>" if LOG_LEVEL != 'DEBUG' else "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level}</level> | <red>{file}</red> | <yellow>{function}</yellow> | <level>{message}</level>"
logger.add(sys.stdout, level=LOG_LEVEL, colorize=True, format=log_format)
logger.add(logs_path / 'trophycord.log', level=LOG_LEVEL, colorize=True, format=log_format)
today = datetime.now().strftime("%Y-%m-%d")

# Correct format string - ANSI codes REMOVED:
log_format = "<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level}</level> | <cyan>{file}</cyan> | <yellow>{function}</yellow> | <magenta>{module}</magenta> | <level>{message}</level>" # % removed

logger.add(
logs_path / f"{today}-trophycord.log",
level=LOG_LEVEL,
format=log_format,
# colorize=True, # Add this back if you want loguru to handle colors. Remove for plain text
)
logger.add(
sys.stdout,
level=LOG_LEVEL,
format=log_format,
colorize=True, # Colorize for console output
)

def switch_logger():
"""
Expand Down

0 comments on commit 74a5b14

Please sign in to comment.