# python-vhost-logging **Repository Path**: mirrors_MadLittleMods/python-vhost-logging ## Basic Information - **Project Name**: python-vhost-logging - **Description**: Proof of concept for per-tenant logging in a multi-tenant/virtual hosting environment. - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-21 - **Last Updated**: 2026-02-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Per-tenant logging for vhosting in Python Proof of concept for per-tenant logging in a multi-tenant/virtual hosting environment. Allows for per-tenant logging configuration. Terminology: - shard: The overarching manager that can provision multiple server tenants. - tenant: A single server instance hosted by a shard, with its own configuration. You might also think of this as a "virtual host". ### Background The multi-server application example is based off the example in the [Python logging cookbook](https://docs.python.org/3/howto/logging-cookbook.html). The base example they give works to separate logs based on the server but does not allow per-server logging config. > For the purposes of illustration, say that you have different web applications, each > independent of the other but running in the same Python process and using a library > common to them. How can each of these applications have their own log, where all > logging messages from the library (and other request processing code) are directed to > the appropriate application’s log file, while including in the log additional > contextual information such as client IP, HTTP request method and client username? > > *-- https://docs.python.org/3/howto/logging-cookbook.html#use-of-contextvars* This demo expands on the idea to allow per-tenant logging configuration so each tenant can configure its own `formatters`, `filters`, `handler`, and log levels for the various `loggers`/`root`. ### Install dependencies ```shell poetry install ``` ### Run ```shell poetry run shard ``` ### Linting ```shell poetry run ./scripts-dev/lint.sh ``` ### Testing ```shell poetry run python -m unittest discover tests/ # Run a single test poetry run python -m unittest tests.test_logging_config.ConfigureLoggingForTenantCase.test_per_tenant_loggers ```