Skip to content

Commit c7164b6

Browse files
committed
Formating
1 parent e583d5f commit c7164b6

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

nxc/logger.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ def parse_debug_args():
2222
args, _ = debug_parser.parse_known_args()
2323
return args
2424

25+
2526
def setup_debug_logging():
2627
debug_args = parse_debug_args()
2728
root_logger = logging.getLogger("root")
28-
29+
2930
if debug_args.verbose:
3031
nxc_logger.logger.setLevel(logging.INFO)
3132
root_logger.setLevel(logging.INFO)
@@ -35,7 +36,7 @@ def setup_debug_logging():
3536
else:
3637
nxc_logger.logger.setLevel(logging.ERROR)
3738
root_logger.setLevel(logging.ERROR)
38-
39+
3940

4041
def create_temp_logger(caller_frame, formatted_text, args, kwargs):
4142
"""Create a temporary logger for emitting a log where we need to override the calling file & line number, since these are obfuscated"""
@@ -47,22 +48,24 @@ def create_temp_logger(caller_frame, formatted_text, args, kwargs):
4748

4849
class SmartDebugRichHandler(RichHandler):
4950
"""Custom logging handler for when we want to log normal messages to DEBUG and not double log"""
51+
5052
def __init__(self, formatter=None, *args, **kwargs):
5153
super().__init__(*args, **kwargs)
5254
if formatter is not None:
5355
self.setFormatter(formatter)
54-
56+
5557
def emit(self, record):
5658
"""Overrides the emit method of the RichHandler class so we can set the proper pathname and lineno"""
5759
# for some reason in RDP, the exc_text is None which leads to a KeyError in Python logging
5860
record.exc_text = record.getMessage() if record.exc_text is None else record.exc_text
59-
61+
6062
if hasattr(record, "caller_frame"):
6163
frame_info = inspect.getframeinfo(record.caller_frame)
6264
record.pathname = frame_info.filename
6365
record.lineno = frame_info.lineno
6466
super().emit(record)
6567

68+
6669
def no_debug(func):
6770
"""Stops logging non-debug messages when we are in debug mode
6871
It creates a temporary logger and logs the message to the console and file
@@ -72,7 +75,7 @@ def no_debug(func):
7275
def wrapper(self, msg, *args, **kwargs):
7376
if self.logger.getEffectiveLevel() >= logging.INFO:
7477
return func(self, msg, *args, **kwargs)
75-
else:
78+
else:
7679
formatted_text = Text.from_ansi(self.format(msg, *args, **kwargs)[0])
7780
caller_frame = inspect.currentframe().f_back
7881
create_temp_logger(caller_frame, formatted_text, args, kwargs)
@@ -95,7 +98,7 @@ def __init__(self, extra=None):
9598
self.logger = logging.getLogger("nxc")
9699
self.extra = extra
97100
self.output_file = None
98-
101+
99102
logging.getLogger("impacket").disabled = True
100103
logging.getLogger("pypykatz").disabled = True
101104
logging.getLogger("minidump").disabled = True
@@ -204,7 +207,7 @@ def init_log_file():
204207
datetime.now().strftime("%Y-%m-%d"),
205208
f"log_{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}.log",
206209
)
207-
210+
208211

209212
class TermEscapeCodeFormatter(logging.Formatter):
210213
"""A class to strip the escape codes for logging to files"""

0 commit comments

Comments
 (0)