@@ -73,26 +73,28 @@ async def watch(self):
73
73
for change in event :
74
74
if plugin := find_plugin_by_file (change [1 ]):
75
75
if plugin .is_static :
76
- logger ( "INFO" , f"Plugin <y>{ plugin .id !r} </y> is static, ignored." )
76
+ logger . opt ( colors = True ). info ( f"Plugin <y>{ plugin .id !r} </y> is static, ignored." )
77
77
continue
78
- logger ( "INFO" , f"Detected change in <blue>{ plugin .id !r} </blue>, reloading..." )
78
+ logger . opt ( colors = True ). info ( f"Detected change in <blue>{ plugin .id !r} </blue>, reloading..." )
79
79
pid = plugin .id
80
80
del plugin
81
81
unload_plugin (pid )
82
82
if plugin := load_plugin (pid ):
83
- logger ( "INFO" , f"Reloaded <blue>{ plugin .id !r} </blue>" )
83
+ logger . opt ( colors = True ). info ( f"Reloaded <blue>{ plugin .id !r} </blue>" )
84
84
del plugin
85
85
else :
86
- logger ( "ERROR" , f"Failed to reload <blue>{ pid !r} </blue>" )
86
+ logger . opt ( colors = True ). error ( f"Failed to reload <blue>{ pid !r} </blue>" )
87
87
self .fail [change [1 ]] = pid
88
88
elif change [1 ] in self .fail :
89
- logger ("INFO" , f"Detected change in { change [1 ]!r} which failed to reload, retrying..." )
89
+ logger .opt (colors = True ).info (
90
+ f"Detected change in { change [1 ]!r} which failed to reload, retrying..."
91
+ )
90
92
if plugin := load_plugin (self .fail [change [1 ]]):
91
- logger ( "INFO" , f"Reloaded <blue>{ plugin .id !r} </blue>" )
93
+ logger . opt ( colors = True ). info ( f"Reloaded <blue>{ plugin .id !r} </blue>" )
92
94
del plugin
93
95
del self .fail [change [1 ]]
94
96
else :
95
- logger ( "ERROR" , f"Failed to reload <blue>{ self .fail [change [1 ]]!r} </blue>" )
97
+ logger . opt ( colors = True ). error ( f"Failed to reload <blue>{ self .fail [change [1 ]]!r} </blue>" )
96
98
97
99
async def watch_config (self ):
98
100
file = EntariConfig .instance .path .resolve ()
@@ -108,21 +110,20 @@ async def watch_config(self):
108
110
):
109
111
print (change )
110
112
continue
111
- logger ( "INFO" , f"Detected change in { change [1 ]!r} , reloading config..." )
113
+ logger . opt ( colors = True ). info ( f"Detected change in { change [1 ]!r} , reloading config..." )
112
114
113
115
old_basic = EntariConfig .instance .basic .copy ()
114
116
old_plugin = EntariConfig .instance .plugin .copy ()
115
117
EntariConfig .instance .reload ()
116
118
for key in old_basic :
117
119
if key in EntariConfig .instance .basic and old_basic [key ] != EntariConfig .instance .basic [key ]:
118
- logger (
119
- "DEBUG" ,
120
+ logger .opt (colors = True ).debug (
120
121
f"Basic config <y>{ key !r} </y> changed from <r>{ old_basic [key ]!r} </r> "
121
122
f"to <g>{ EntariConfig .instance .basic [key ]!r} </g>" ,
122
123
)
123
124
await es .publish (ConfigReload ("basic" , key , EntariConfig .instance .basic [key ], old_basic [key ]))
124
125
for key in set (EntariConfig .instance .basic ) - set (old_basic ):
125
- logger ( "DEBUG" , f"Basic config <y>{ key !r} </y> appended" )
126
+ logger . opt ( colors = True ). debug ( f"Basic config <y>{ key !r} </y> appended" )
126
127
await es .publish (ConfigReload ("basic" , key , EntariConfig .instance .basic [key ]))
127
128
for plugin_name in old_plugin :
128
129
if plugin_name .startswith ("$" ) or plugin_name .startswith ("~" ):
@@ -132,11 +133,10 @@ async def watch_config(self):
132
133
if plugin := find_plugin (pid ):
133
134
del plugin
134
135
unload_plugin (pid )
135
- logger ( "INFO" , f"Disposed plugin <blue>{ pid !r} </blue>" )
136
+ logger . opt ( colors = True ). info ( f"Disposed plugin <blue>{ pid !r} </blue>" )
136
137
continue
137
138
if old_plugin [plugin_name ] != EntariConfig .instance .plugin [plugin_name ]:
138
- logger (
139
- "DEBUG" ,
139
+ logger .opt (colors = True ).debug (
140
140
f"Plugin <y>{ plugin_name !r} </y> config changed from <r>{ old_plugin [plugin_name ]!r} </r> "
141
141
f"to <g>{ EntariConfig .instance .plugin [plugin_name ]!r} </g>" ,
142
142
)
@@ -146,25 +146,27 @@ async def watch_config(self):
146
146
allow , deny , only_filter = detect_filter_change (old_conf , new_conf )
147
147
plugin .update_filter (allow , deny )
148
148
if only_filter :
149
- logger ( "DEBUG" , f"Plugin <y>{ pid !r} </y> config only changed filter." )
149
+ logger . opt ( colors = True ). debug ( f"Plugin <y>{ pid !r} </y> config only changed filter." )
150
150
continue
151
151
res = await es .post (
152
152
ConfigReload ("plugin" , plugin_name , new_conf , old_conf ),
153
153
)
154
154
if res and res .value :
155
- logger ( "DEBUG" , f"Plugin <y>{ pid !r} </y> config change handled by itself." )
155
+ logger . opt ( colors = True ). debug ( f"Plugin <y>{ pid !r} </y> config change handled by itself." )
156
156
continue
157
- logger ("INFO" , f"Detected config of <blue>{ pid !r} </blue> changed, reloading..." )
157
+ logger .opt (colors = True ).info (
158
+ f"Detected config of <blue>{ pid !r} </blue> changed, reloading..."
159
+ )
158
160
plugin_file = str (plugin .module .__file__ )
159
161
unload_plugin (plugin_name )
160
162
if plugin := load_plugin (plugin_name , new_conf ):
161
- logger ( "INFO" , f"Reloaded <blue>{ plugin .id !r} </blue>" )
163
+ logger . opt ( colors = True ). info ( f"Reloaded <blue>{ plugin .id !r} </blue>" )
162
164
del plugin
163
165
else :
164
- logger ( "ERROR" , f"Failed to reload <blue>{ plugin_name !r} </blue>" )
166
+ logger . opt ( colors = True ). error ( f"Failed to reload <blue>{ plugin_name !r} </blue>" )
165
167
self .fail [plugin_file ] = pid
166
168
else :
167
- logger ( "INFO" , f"Detected <blue>{ pid !r} </blue> appended, loading..." )
169
+ logger . opt ( colors = True ). info ( f"Detected <blue>{ pid !r} </blue> appended, loading..." )
168
170
load_plugin (plugin_name , new_conf )
169
171
if new := (set (EntariConfig .instance .plugin ) - set (old_plugin )):
170
172
for plugin_name in new :
0 commit comments