PHP 8.5.2
Preview: _util.py Size: 1.34 KB
//lib/python3/dist-packages/twisted/logger/_util.py

# -*- test-case-name: twisted.logger.test.test_util -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Logging utilities.
"""

from typing import List

from ._interfaces import LogTrace
from ._logger import Logger


def formatTrace(trace: LogTrace) -> str:
    """
    Format a trace (that is, the contents of the C{log_trace} key of a log
    event) as a visual indication of the message's propagation through various
    observers.

    @param trace: the contents of the C{log_trace} key from an event.

    @return: A multi-line string with indentation and arrows indicating the
        flow of the message through various observers.
    """

    def formatWithName(obj: object) -> str:
        if hasattr(obj, "name"):
            return f"{obj} ({obj.name})"
        else:
            return f"{obj}"

    result = []
    lineage: List[Logger] = []

    for parent, child in trace:
        if not lineage or lineage[-1] is not parent:
            if parent in lineage:
                while lineage[-1] is not parent:
                    lineage.pop()

            else:
                if not lineage:
                    result.append(f"{formatWithName(parent)}\n")

                lineage.append(parent)

        result.append("  " * len(lineage))
        result.append(f"-> {formatWithName(child)}\n")

    return "".join(result)

Directory Contents

Dirs: 2 × Files: 17

Name Size Perms Modified Actions
test DIR
- drwxr-xr-x 2026-01-08 12:56:22
Edit Download
- drwxr-xr-x 2026-01-08 12:56:23
Edit Download
1.49 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
624 B lrw-r--r-- 2024-08-27 10:30:39
Edit Download
2.28 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
6.71 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
4.88 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
13.16 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
8.43 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
2.29 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
4.44 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
8.21 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
5.12 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
2.89 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
9.75 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
3.17 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
4.42 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.34 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
3.29 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).