kaxil commented on code in PR #55581:
URL: https://github.com/apache/airflow/pull/55581#discussion_r2349711713
##########
shared/logging/src/airflow_shared/logging/percent_formatter.py:
##########
@@ -96,17 +86,48 @@ class PercentFormatRender(ConsoleRenderer):
_fmt: str
+ # From
https://github.com/python/cpython/blob/v3.12.11/Lib/logging/__init__.py#L563-L587
+ callsite_parameters: ClassVar[dict[str, CallsiteParameter]] = {
+ "pathname": CallsiteParameter.PATHNAME,
+ "filename": CallsiteParameter.FILENAME,
+ "module": CallsiteParameter.MODULE,
+ "lineno": CallsiteParameter.LINENO,
+ "funcName": CallsiteParameter.FUNC_NAME,
+ "thread": CallsiteParameter.THREAD,
+ "threadName": CallsiteParameter.THREAD_NAME,
+ "process": CallsiteParameter.PROCESS,
+ # This one isn't listed in the docs until 3.14, but it's worked for a
long time
+ "processName": CallsiteParameter.PROCESS_NAME,
+ }
+
special_keys = {
- "pathname",
- "lineno",
- "func_name",
"event",
"name",
"logger",
"logger_name",
"timestamp",
"level",
- }
+ } | set(map(operator.attrgetter("value"), callsite_parameters.values()))
+
+ @classmethod
+ def callsite_params_from_fmt_string(cls, fmt: str) ->
collections.abc.Iterable[CallsiteParameter]:
+ # Pattern based on
https://github.com/python/cpython/blob/v3.12.11/Lib/logging/__init__.py#L441,
but
+ # with added grouping, and comments to aid clarity, even if we don't
care about anything beyond the
+ # mapping key
+ pattern = re.compile(
+ r"""
+ %\( (?P<key> \w+ ) \) # The mapping key (in parenthesis. The
bit we care about)
+ [#0+ -]* # Conversion flags
+ (?: \*|\d+ )? # Minimum field width
+ (?: \. (?: \* | \d+ ) )? # Precision (floating point)
+ [diouxefgcrsa%] # Conversion type
+ """,
+ re.I | re.X,
+ )
Review Comment:
Does this have any impact if there are tons of logs .. regex on each --
possibly not but checking
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]