@@ -81,11 +81,24 @@ class StructuredLogLevel(Enum):
81
81
ERROR = logging .ERROR
82
82
83
83
84
+ class StructuredLogCategory (Enum ):
85
+ """
86
+ This is used to categorise the errors mainly based on the biggest impact area
87
+ This is to be used to help in self-serve understand the impact of any log entry
88
+ More enums to be added as logs are updated to be self-serve
89
+ """
90
+
91
+ LINEAGE = "LINEAGE"
92
+ USAGE = "USAGE"
93
+ PROFILING = "PROFILING"
94
+
95
+
84
96
@dataclass
85
97
class StructuredLogEntry (Report ):
86
98
title : Optional [str ]
87
99
message : str
88
100
context : LossyList [str ]
101
+ log_category : Optional [StructuredLogCategory ] = None
89
102
90
103
91
104
@dataclass
@@ -108,16 +121,20 @@ def report_log(
108
121
exc : Optional [BaseException ] = None ,
109
122
log : bool = False ,
110
123
stacklevel : int = 1 ,
124
+ log_category : Optional [StructuredLogCategory ] = None ,
111
125
) -> None :
112
126
"""
113
- Report a user-facing warning for the ingestion run.
127
+ Report a user-facing log for the ingestion run.
114
128
115
129
Args:
116
130
level: The level of the log entry.
117
131
message: The main message associated with the report entry. This should be a human-readable message.
118
132
title: The category / heading to present on for this message in the UI.
119
133
context: Additional context (e.g. where, how) for the log entry.
120
134
exc: The exception associated with the event. We'll show the stack trace when in debug mode.
135
+ log_category: The type of the log entry. This is used to categorise the log entry.
136
+ log: Whether to log the entry to the console.
137
+ stacklevel: The stack level to use for the log entry.
121
138
"""
122
139
123
140
# One for this method, and one for the containing report_* call.
@@ -160,6 +177,7 @@ def report_log(
160
177
title = title ,
161
178
message = message ,
162
179
context = context_list ,
180
+ log_category = log_category ,
163
181
)
164
182
else :
165
183
if context is not None :
@@ -219,9 +237,19 @@ def report_warning(
219
237
context : Optional [str ] = None ,
220
238
title : Optional [LiteralString ] = None ,
221
239
exc : Optional [BaseException ] = None ,
240
+ log_category : Optional [StructuredLogCategory ] = None ,
222
241
) -> None :
242
+ """
243
+ See docs of StructuredLogs.report_log for details of args
244
+ """
223
245
self ._structured_logs .report_log (
224
- StructuredLogLevel .WARN , message , title , context , exc , log = False
246
+ StructuredLogLevel .WARN ,
247
+ message ,
248
+ title ,
249
+ context ,
250
+ exc ,
251
+ log = False ,
252
+ log_category = log_category ,
225
253
)
226
254
227
255
def warning (
@@ -231,9 +259,19 @@ def warning(
231
259
title : Optional [LiteralString ] = None ,
232
260
exc : Optional [BaseException ] = None ,
233
261
log : bool = True ,
262
+ log_category : Optional [StructuredLogCategory ] = None ,
234
263
) -> None :
264
+ """
265
+ See docs of StructuredLogs.report_log for details of args
266
+ """
235
267
self ._structured_logs .report_log (
236
- StructuredLogLevel .WARN , message , title , context , exc , log = log
268
+ StructuredLogLevel .WARN ,
269
+ message ,
270
+ title ,
271
+ context ,
272
+ exc ,
273
+ log = log ,
274
+ log_category = log_category ,
237
275
)
238
276
239
277
def report_failure (
@@ -243,9 +281,19 @@ def report_failure(
243
281
title : Optional [LiteralString ] = None ,
244
282
exc : Optional [BaseException ] = None ,
245
283
log : bool = True ,
284
+ log_category : Optional [StructuredLogCategory ] = None ,
246
285
) -> None :
286
+ """
287
+ See docs of StructuredLogs.report_log for details of args
288
+ """
247
289
self ._structured_logs .report_log (
248
- StructuredLogLevel .ERROR , message , title , context , exc , log = log
290
+ StructuredLogLevel .ERROR ,
291
+ message ,
292
+ title ,
293
+ context ,
294
+ exc ,
295
+ log = log ,
296
+ log_category = log_category ,
249
297
)
250
298
251
299
def failure (
@@ -255,9 +303,19 @@ def failure(
255
303
title : Optional [LiteralString ] = None ,
256
304
exc : Optional [BaseException ] = None ,
257
305
log : bool = True ,
306
+ log_category : Optional [StructuredLogCategory ] = None ,
258
307
) -> None :
308
+ """
309
+ See docs of StructuredLogs.report_log for details of args
310
+ """
259
311
self ._structured_logs .report_log (
260
- StructuredLogLevel .ERROR , message , title , context , exc , log = log
312
+ StructuredLogLevel .ERROR ,
313
+ message ,
314
+ title ,
315
+ context ,
316
+ exc ,
317
+ log = log ,
318
+ log_category = log_category ,
261
319
)
262
320
263
321
def info (
@@ -267,9 +325,19 @@ def info(
267
325
title : Optional [LiteralString ] = None ,
268
326
exc : Optional [BaseException ] = None ,
269
327
log : bool = True ,
328
+ log_category : Optional [StructuredLogCategory ] = None ,
270
329
) -> None :
330
+ """
331
+ See docs of StructuredLogs.report_log for details of args
332
+ """
271
333
self ._structured_logs .report_log (
272
- StructuredLogLevel .INFO , message , title , context , exc , log = log
334
+ StructuredLogLevel .INFO ,
335
+ message ,
336
+ title ,
337
+ context ,
338
+ exc ,
339
+ log = log ,
340
+ log_category = log_category ,
273
341
)
274
342
275
343
@contextlib .contextmanager
@@ -279,6 +347,7 @@ def report_exc(
279
347
title : Optional [LiteralString ] = None ,
280
348
context : Optional [str ] = None ,
281
349
level : StructuredLogLevel = StructuredLogLevel .ERROR ,
350
+ log_category : Optional [StructuredLogCategory ] = None ,
282
351
) -> Iterator [None ]:
283
352
# Convenience method that helps avoid boilerplate try/except blocks.
284
353
# TODO: I'm not super happy with the naming here - it's not obvious that this
@@ -287,7 +356,12 @@ def report_exc(
287
356
yield
288
357
except Exception as exc :
289
358
self ._structured_logs .report_log (
290
- level , message = message , title = title , context = context , exc = exc
359
+ level ,
360
+ message = message ,
361
+ title = title ,
362
+ context = context ,
363
+ exc = exc ,
364
+ log_category = log_category ,
291
365
)
292
366
293
367
def __post_init__ (self ) -> None :
0 commit comments