@@ -16,13 +16,11 @@ def __init__(self, extra=None):
16
16
logging .basicConfig (
17
17
format = "%(message)s" ,
18
18
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
+ )],
26
24
)
27
25
self .logger = logging .getLogger ("nxc" )
28
26
self .extra = extra
@@ -40,30 +38,21 @@ def format(self, msg, *args, **kwargs): # noqa: A003
40
38
if self .extra is None :
41
39
return f"{ msg } " , kwargs
42
40
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 :
44
42
self .extra ["module_name" ] = self .extra ["module_name" ][:8 ] + "..."
45
43
46
44
# If the logger is being called when hooking the 'options' module function
47
45
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 )
52
47
53
48
# If the logger is being called from nxcServer
54
49
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 )
59
51
60
52
# If the logger is being called from a protocol
61
53
module_name = colored (self .extra ["module_name" ], "cyan" , attrs = ["bold" ]) if "module_name" in self .extra else colored (self .extra ["protocol" ], "blue" , attrs = ["bold" ])
62
54
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 )
67
56
68
57
def display (self , msg , * args , ** kwargs ):
69
58
"""Display text to console, formatted for nxc"""
@@ -104,17 +93,7 @@ def log_console_to_file(self, text, *args, **kwargs):
104
93
if len (self .logger .handlers ):
105
94
try :
106
95
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 ))
118
97
except Exception as e :
119
98
self .logger .fail (f"Issue while trying to custom print handler: { e } " )
120
99
else :
0 commit comments