Skip to content

Fix debug logging policy: per-archive control via TAP.conf, not server env var - #41

Open
museleie wants to merge 4 commits into
developfrom
fix/debug-config-policy
Open

museleie wants to merge 4 commits into
developfrom
fix/debug-config-policy

Conversation

@museleie

@museleie museleie commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

TAP_DEBUG=1 was the only way to enable debug logging. Setting it on the server wrote a debug file for every archive on the host, before the config was even read. If TAP.conf was missing or broken, a file still appeared in /tmp. There was no way to turn debug on for one archive and not another.

There were also six places in the code that passed debug=1 hardcoded, so those code paths always ran in debug mode regardless of what the config said.

What this does

Each archive now controls debug via its own TAP.conf:

[WEB]
DEBUG = 1

The /tmp/tap_<pid>.debug file is only created after the config loads and confirms DEBUG = 1 for that archive. Only the string 1 turns it on.

TAP_DEBUG=1 still works but is now a startup diagnostic only. It buffers log records in memory until the config loads. If the config says DEBUG = 1, those early records get written into the debug file. If the config says DEBUG = 0, they are discarded. If the config fails to load at all (missing file, bad format), the buffer goes to stderr (the web server error log) instead of creating a /tmp file.

Archives still on the 1.x [webserver] layout get DEBUG translated to [WEB] automatically on read, same as the other keys.

The six hardcoded debug=1 kwargs were replaced with debug=self.debug or removed where the callee ignores the argument.

Tests

29 regression tests in tests/test_debug_policy.py. They cover all four combinations of TAP_DEBUG and config DEBUG, the pre-config failure path (buffer to stderr, no file created), config parsing edge cases, and that a form field in a request cannot enable debug. The 1.x migration path has its own test in test_compat_config.py.

Upgrading

Debug is off by default. Existing deployments do not need to change anything.

To enable debug for an archive, add DEBUG = 1 to its [WEB] section. If you were using TAP_DEBUG=1 to get per-request debug files, use DEBUG = 1 in TAP.conf instead. TAP_DEBUG no longer writes files.

…DEBUG

TAP_DEBUG was an all-or-nothing server env var — turning it on wrote debug
files for every archive on the host. We needed per-archive control so each
deployment can opt in independently via its own TAP.conf.

configparam reads DEBUG from [WEB] and exposes it as debug_flag. Only the
string '1' enables it, same strictness as TAP_DEBUG.

compat adds DEBUG to _WEB_KEYS so existing 1.x configs with [webserver] DEBUG
keep working after upgrade without needing a manual edit.
…DEBUG=1

TAP_DEBUG=1 used to call logging.basicConfig(filename=...) on startup, so a
debug file appeared for every archive before the config was even read. If
TAP.conf was missing or broken, a file was still created.

Now TAP_DEBUG buffers log records in memory until the config loads. If
DEBUG=1 in that archive's TAP.conf the buffer replays into the file. If the
config says DEBUG=0 the buffer is discarded. If config loading fails, the
buffer flushes to stderr (web server error log) instead — no file.

Also removed debug=1 hardcoded at six call sites that were switching debug on
regardless of what the config said. The leftover **kwargs on
__executeSql__ from that cleanup was removed too.
The debug file must only appear when the archive's TAP.conf says DEBUG=1.
TAP_DEBUG alone must never create one, and a failed config load must not
either. These tests nail down those boundaries so they don't regress quietly.

Covers the four TAP_DEBUG/DEBUG combinations, what ends up in the file vs
stderr, the 1.x config migration path, and that a form field in a request
can't turn debug on.

clean_root_logger in conftest.py tears down any handlers Tap attaches so
tests don't bleed into each other.
Added a Debug Logging section to configure.rst. Operators would have no way
to know the DEBUG key exists otherwise.

configure.rst was referring to the env var as TAP_CONFIG. The correct name
is TAP_CONF. Easy to miss when you're looking for the wrong thing.

MIGRATING.md left DEBUG out of the 1.x-to-3.x key table, making it look
like it wasn't carried forward on upgrade.

Added a commented DEBUG=0 line to TAP.conf and the test fixture so the key
is discoverable without reading the source.
@museleie museleie self-assigned this Nov 20, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant