@@ -180,24 +180,28 @@ def get_dialect(cls, jobhash: int) -> InputDialect:
180180class TraceWarning :
181181 """
182182 Keep track of warnings to allow accumulated warning at the end of a run
183- Usage :
183+ Example :
184184
185185 w = TraceWarning(
186186 name="MyWarning",
187187 text="This stage has detected {d[count]} issues with max {d[max]}.",
188188 data={"count": 0, "max": 0.0},
189189 update_fn={"count": int.__add__, "max": max},
190- autolog=True
190+ autolog=True,
191+ is_error=True,
191192 )
192193
193194 name: a key that can be used to manage multiple warnings in e.g. a dictionary
194195 text: the warning text with variables (always us 'd' as the dictionary name)
195196 data: dictionary with entries that match the text variables
196197 update_fn: functions to run when the update function is called with data
197- autolog: automatically print the warning at destruction time
198+ autolog: automatically print the warning at destruction time (default)
199+ is_error: print the summary warning as ERROR level and not as WARN (default)
198200
199201 Whenever a warning should be added:
202+
200203 w.update({"count": 1, "max": 100.0})
204+
201205 this calls the preset update_fn for each item to update the values
202206 if update_fn is e.g. int.__add__, then the new_val entry for count will be increased by 1
203207
@@ -213,14 +217,16 @@ def __init__(
213217 text : str ,
214218 data : dict [str , any ],
215219 update_fn : dict [str , callable ] = {},
216- auto_log : bool = True ):
220+ auto_log : bool = True ,
221+ is_error : bool = False ):
217222 self .occurred = False
218223 self .name = name
219224 # format-string with {d[key]} placeholders
220225 self .text : str = text
221226 self .args_list : dict [str , any ] = {k : v for k , v in data .items ()}
222227 self .update_fn : dict [str , callable ] = {k : v for k , v in update_fn .items ()}
223228 self .auto_log = auto_log
229+ self .warn_level = aiulog .WARN if not is_error else aiulog .ERROR
224230
225231 text_keys = re .findall (r"{d\[([.\w]+)\]}" , self .text )
226232 if len (text_keys ) != len (self .args_list ):
@@ -249,7 +255,7 @@ def __init__(
249255
250256 def __del__ (self ) -> None :
251257 if self .auto_log is True and self .has_warning ():
252- aiulog .log (aiulog . WARN , self )
258+ aiulog .log (self . warn_level , self )
253259
254260 def get_name (self ) -> str :
255261 return self .name
0 commit comments