Skip to content

Commit

Permalink
Update logger.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sexfrance authored Nov 10, 2024
1 parent fb85664 commit 35c8cb4
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions logmagix/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ def __init__(self, prefix: str | None = "discord.cyberious.xyz", level: LogLevel
self.level = level
self.log_file = log_file
if log_file:
# Create log directory if it doesn't exist
os.makedirs(os.path.dirname(log_file), exist_ok=True)
# Add initial log entry
self._write_to_log(f"=== Logging started at {datetime.datetime.now()} ===\n")

def _write_to_log(self, message: str) -> None:
if self.log_file:
try:
with open(self.log_file, 'a', encoding='utf-8') as f:
# Strip ANSI color codes for file logging
clean_message = self._strip_ansi(message)
f.write(clean_message + '\n')
except Exception as e:
Expand Down Expand Up @@ -101,8 +98,7 @@ def question(self, message: str, start: int = None, end: int = None) -> None:
question_message = f"{self.prefix}[{self.BRIGHT_MAGENTA}{time}{self.PINK}]{Fore.RESET} {self.PINK}[{Fore.BLUE}?{self.PINK}] -> {Fore.RESET} {self.CYAN}{message}{Fore.RESET}"
print(question_message, end='')
i = input()

# Log both the question and answer

if self.log_file:
self._write_to_log(f"{question_message}")
self._write_to_log(f"User Answer: {i}")
Expand Down Expand Up @@ -283,4 +279,4 @@ def _display_welcome(self, terminal_width, block_width):
Write.Print(f"{tilde_line_aligned}\n", Colors.red_to_blue, interval=0.000)

equals_line = "═" * terminal_width
Write.Print(f"{equals_line}\n", Colors.red_to_blue, interval=0.000)
Write.Print(f"{equals_line}\n", Colors.red_to_blue, interval=0.000)

0 comments on commit 35c8cb4

Please sign in to comment.