Skip to content

feat: Redirect tracing in rust to python logging - #2523

Draft
pavelzw wants to merge 34 commits into
conda:mainfrom
pavelzw:logging-py-rattler
Draft

feat: Redirect tracing in rust to python logging#2523
pavelzw wants to merge 34 commits into
conda:mainfrom
pavelzw:logging-py-rattler

Conversation

@pavelzw

@pavelzw pavelzw commented Jun 19, 2026

Copy link
Copy Markdown
Member

Description

Fixes #{issue}

How Has This Been Tested?

pixi run python foo.py and

# foo.py
from rattler.package_streaming import fetch_raw_package_file_from_url
from rattler import Client, setup_logging
import asyncio

import logging

FORMAT = "%(levelname)s %(name)s %(asctime)-15s %(filename)s:%(lineno)d %(message)s"
logging.basicConfig(format=FORMAT)
logging.getLogger().setLevel(logging.INFO)
logging.getLogger("rattler.rattler_package_streaming").setLevel(logging.DEBUG)

setup_logging()


async def main():
    foo = await fetch_raw_package_file_from_url(
        Client(),
        "https://prefix.dev/conda-forge/noarch/polars-1.41.2-pyh58ad624_0.conda",
        "site-packages/polars/__init__.py",
    )
    print(foo[:20])


asyncio.run(main())

alternatively, something like this if you want to use loguru instead of logging

Details
import asyncio
import logging
import sys

from loguru import logger

from rattler import Client, setup_logging
from rattler.package_streaming import fetch_raw_package_file_from_url


class LoguruHandler(logging.Handler):
    def emit(self, record: logging.LogRecord) -> None:
        try:
            level = logger.level(record.levelname).name
        except ValueError:
            level = record.levelno

        logger.opt(depth=6, exception=record.exc_info).log(level, record.getMessage())


logger.remove()
logger.add(sys.stderr, level="DEBUG")

rattler_logger = logging.getLogger("rattler")
rattler_logger.handlers.clear()
rattler_logger.addHandler(LoguruHandler())
rattler_logger.setLevel(logging.DEBUG)
rattler_logger.propagate = False


setup_logging()


async def main():
    foo = await fetch_raw_package_file_from_url(
        Client(),
        "https://prefix.dev/conda-forge/noarch/polars-1.41.2-pyh58ad624_0.conda",
        "site-packages/polars/__init__.py",
    )
    print(foo[:20])


asyncio.run(main())

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: Codex

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added sufficient tests to cover my changes.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants