PHP 8.5.2
Preview: logging.py Size: 1.41 KB
//lib/python3/dist-packages/apport/logging.py

"""Legacy logging functions."""

import os
import sys
import time
import typing


def log(message, timestamp=False):
    """Log the given string to stdout. Prepend timestamp if requested."""
    if timestamp:
        sys.stdout.write(f"{time.strftime('%x %X')}: ")
    print(message)


def fatal(msg: str, *args: typing.Any) -> typing.NoReturn:
    """Print out an error message and exit the program."""
    error(msg, *args)
    sys.exit(1)


def error(msg, *args):
    """Print out an error message."""
    if sys.stderr:
        sys.stderr.write("ERROR: ")
        sys.stderr.write(msg % args)
        sys.stderr.write("\n")


def warning(msg, *args):
    """Print out an warning message."""
    if sys.stderr:
        sys.stderr.write("WARNING: ")
        sys.stderr.write(msg % args)
        sys.stderr.write("\n")


def memdbg(checkpoint):
    """Print current memory usage.

    This is only done if $APPORT_MEMDEBUG is set.
    """
    if "APPORT_MEMDEBUG" not in os.environ or not sys.stderr:
        return

    memstat = {}
    with open("/proc/self/status", encoding="utf-8") as status_file:
        for line in status_file:
            if line.startswith("Vm"):
                (field, size, _) = line.split()
                memstat[field[:-1]] = int(size) / 1024.0

    sys.stderr.write(
        f"Size: {memstat['VmSize']:.1f} MB, RSS: {memstat['VmRSS']:.1f} MB,"
        f" Stk: {memstat['VmStk']:.1f} MB @ {checkpoint}\n"
    )

Directory Contents

Dirs: 3 × Files: 11

Name Size Perms Modified Actions
- drwxr-xr-x 2026-01-08 12:56:21
Edit Download
- drwxr-xr-x 2026-01-08 12:56:21
Edit Download
- drwxr-xr-x 2026-01-08 12:56:21
Edit Download
34.17 KB lrw-r--r-- 2024-04-18 12:31:35
Edit Download
21.90 KB lrw-r--r-- 2025-07-08 14:50:50
Edit Download
35.42 KB lrw-r--r-- 2025-07-08 14:50:50
Edit Download
1.41 KB lrw-r--r-- 2024-04-18 12:31:35
Edit Download
12.81 KB lrw-r--r-- 2024-04-18 12:31:35
Edit Download
74.28 KB lrw-r--r-- 2025-07-08 14:50:50
Edit Download
2.30 KB lrw-r--r-- 2025-07-08 14:50:50
Edit Download
12.72 KB lrw-r--r-- 2025-07-08 14:50:50
Edit Download
77.96 KB lrw-r--r-- 2025-07-08 14:50:50
Edit Download
933 B lrw-r--r-- 2024-04-18 12:31:35
Edit Download
657 B lrw-r--r-- 2024-04-18 12:31:35
Edit Download

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