Log PG environment variables when a PgBin runs

Useful for debugging situations like connecting to databases.

Co-authored-by: Sasha Krassovsky <sasha@neon.tech>
This commit is contained in:
Tristan Partin
2024-07-03 14:59:19 -05:00
committed by Alex Chi Z
parent 8d9b632f2a
commit 8328580dc2

View File

@@ -2883,6 +2883,13 @@ class PgBin:
env.update(env_add)
return env
def _log_env(self, env: dict[str, str]) -> None:
env_s = {}
for k, v in env.items():
if k.startswith("PG") and k != "PGPASSWORD":
env_s[k] = v
log.debug(f"Environment: {env_s}")
def run(
self,
command: List[str],
@@ -2905,6 +2912,7 @@ class PgBin:
self._fixpath(command)
log.info(f"Running command '{' '.join(command)}'")
env = self._build_env(env)
self._log_env(env)
subprocess.run(command, env=env, cwd=cwd, check=True)
def run_capture(
@@ -2925,6 +2933,7 @@ class PgBin:
self._fixpath(command)
log.info(f"Running command '{' '.join(command)}'")
env = self._build_env(env)
self._log_env(env)
base_path, _, _ = subprocess_capture(
self.log_dir,
command,