33from logging .handlers import RotatingFileHandler
44import os .path
55import sys
6- import re
76from nxc .console import nxc_console
87from nxc .paths import NXC_PATH
98from termcolor import colored
@@ -43,7 +42,7 @@ def create_temp_logger(caller_frame, formatted_text, args, kwargs):
4342 temp_logger = logging .getLogger ("temp" )
4443 formatter = logging .Formatter ("%(message)s" , datefmt = "[%X]" )
4544 handler = SmartDebugRichHandler (formatter = formatter )
46- handler .handle (LogRecord (temp_logger .name , logging .INFO , caller_frame .f_code .co_filename , caller_frame .f_lineno , formatted_text , args , kwargs , caller_frame = caller_frame ))
45+ handler .handle (LogRecord (temp_logger .name , logging .INFO , caller_frame .f_code .co_filename , caller_frame .f_lineno , formatted_text , args , None , caller_frame = caller_frame ))
4746
4847
4948class SmartDebugRichHandler (RichHandler ):
@@ -56,9 +55,6 @@ def __init__(self, formatter=None, *args, **kwargs):
5655
5756 def emit (self , record ):
5857 """Overrides the emit method of the RichHandler class so we can set the proper pathname and lineno"""
59- # for some reason in RDP, the exc_text is None which leads to a KeyError in Python logging
60- record .exc_text = record .getMessage () if record .exc_text is None else record .exc_text
61-
6258 if hasattr (record , "caller_frame" ):
6359 frame_info = inspect .getframeinfo (record .caller_frame )
6460 record .pathname = frame_info .filename
@@ -93,6 +89,7 @@ def __init__(self, extra=None):
9389 rich_tracebacks = True ,
9490 tracebacks_show_locals = False
9591 )],
92+ encoding = "utf-8"
9693 )
9794 self .logger = logging .getLogger ("nxc" )
9895 self .extra = extra
@@ -176,7 +173,7 @@ def log_console_to_file(self, text, *args, **kwargs):
176173 self .logger .fail (f"Issue while trying to custom print handler: { e } " )
177174
178175 def add_file_log (self , log_file = None ):
179- file_formatter = TermEscapeCodeFormatter ("%(asctime)s | %(filename)s:%(lineno)s - %(levelname)s - %(message)s" , datefmt = "%Y-%m-%d %H:%M:%S" )
176+ file_formatter = logging . Formatter ("%(asctime)s | %(filename)s:%(lineno)s - %(levelname)s - %(message)s" , datefmt = "%Y-%m-%d %H:%M:%S" )
180177 output_file = self .init_log_file () if log_file is None else log_file
181178 file_creation = False
182179
@@ -208,17 +205,5 @@ def init_log_file():
208205 )
209206
210207
211- class TermEscapeCodeFormatter (logging .Formatter ):
212- """A class to strip the escape codes for logging to files"""
213-
214- def __init__ (self , fmt = None , datefmt = None , style = "%" , validate = True ):
215- super ().__init__ (fmt , datefmt , style , validate )
216-
217- def format (self , record ): # noqa: A003
218- escape_re = re .compile (r"\x1b\[[0-9;]*m" )
219- record .msg = re .sub (escape_re , "" , str (record .msg ))
220- return super ().format (record )
221-
222-
223208# initialize the logger for all of nxc - this is imported everywhere
224209nxc_logger = NXCAdapter ()
0 commit comments