@@ -16,13 +16,11 @@ def __init__(self, extra=None):
1616 logging .basicConfig (
1717 format = "%(message)s" ,
1818 datefmt = "[%X]" ,
19- handlers = [
20- RichHandler (
21- console = nxc_console ,
22- rich_tracebacks = True ,
23- tracebacks_show_locals = False ,
24- )
25- ],
19+ handlers = [RichHandler (
20+ console = nxc_console ,
21+ rich_tracebacks = True ,
22+ tracebacks_show_locals = False
23+ )],
2624 )
2725 self .logger = logging .getLogger ("nxc" )
2826 self .extra = extra
@@ -40,30 +38,21 @@ def format(self, msg, *args, **kwargs): # noqa: A003
4038 if self .extra is None :
4139 return f"{ msg } " , kwargs
4240
43- if "module_name" in self .extra and len (self .extra ["module_name" ]) > 8 :
41+ if "module_name" in self .extra and len (self .extra ["module_name" ]) > 11 :
4442 self .extra ["module_name" ] = self .extra ["module_name" ][:8 ] + "..."
4543
4644 # If the logger is being called when hooking the 'options' module function
4745 if len (self .extra ) == 1 and ("module_name" in self .extra ):
48- return (
49- f"{ colored (self .extra ['module_name' ], 'cyan' , attrs = ['bold' ]):<64} { msg } " ,
50- kwargs ,
51- )
46+ return (f"{ colored (self .extra ['module_name' ], 'cyan' , attrs = ['bold' ]):<64} { msg } " , kwargs )
5247
5348 # If the logger is being called from nxcServer
5449 if len (self .extra ) == 2 and ("module_name" in self .extra ) and ("host" in self .extra ):
55- return (
56- f"{ colored (self .extra ['module_name' ], 'cyan' , attrs = ['bold' ]):<24} { self .extra ['host' ]:<39} { msg } " ,
57- kwargs ,
58- )
50+ return (f"{ colored (self .extra ['module_name' ], 'cyan' , attrs = ['bold' ]):<24} { self .extra ['host' ]:<39} { msg } " , kwargs )
5951
6052 # If the logger is being called from a protocol
6153 module_name = colored (self .extra ["module_name" ], "cyan" , attrs = ["bold" ]) if "module_name" in self .extra else colored (self .extra ["protocol" ], "blue" , attrs = ["bold" ])
6254
63- return (
64- f"{ module_name :<24} { self .extra ['host' ]:<15} { self .extra ['port' ]:<6} { self .extra ['hostname' ] if self .extra ['hostname' ] else 'NONE' :<16} { msg } " ,
65- kwargs ,
66- )
55+ return (f"{ module_name :<24} { self .extra ['host' ]:<15} { self .extra ['port' ]:<6} { self .extra ['hostname' ] if self .extra ['hostname' ] else 'NONE' :<16} { msg } " , kwargs )
6756
6857 def display (self , msg , * args , ** kwargs ):
6958 """Display text to console, formatted for nxc"""
@@ -104,17 +93,7 @@ def log_console_to_file(self, text, *args, **kwargs):
10493 if len (self .logger .handlers ):
10594 try :
10695 for handler in self .logger .handlers :
107- handler .handle (
108- LogRecord (
109- "nxc" ,
110- 20 ,
111- "" ,
112- kwargs ,
113- msg = text ,
114- args = args ,
115- exc_info = None ,
116- )
117- )
96+ handler .handle (LogRecord ("nxc" , 20 , "" , kwargs , msg = text , args = args , exc_info = None ))
11897 except Exception as e :
11998 self .logger .fail (f"Issue while trying to custom print handler: { e } " )
12099 else :
0 commit comments