commit 60d32ed5f36dd478e7e91118d66acc9e4d2e2392
parent 2732c2740260aa38c2f5980c82d06baec6340a08
Author: ms <ms@taler.net>
Date: Thu, 13 Jan 2022 10:14:28 +0100
taler-local: fix logging
Diffstat:
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/bin/WIP/taler-local b/bin/WIP/taler-local
@@ -31,7 +31,7 @@ import random
import logging
import json
from os import listdir
-from os.path import isdir, join
+from os.path import isdir, join, basename
from pathlib import Path
from typing import List, Callable
from shutil import copy
@@ -493,7 +493,6 @@ def prepare(x_forwarded_host, x_forwarded_proto, postgres_db_name):
def fail(reason=None):
if reason:
print("ERROR:", reason)
- print(f"Logs in {LOG_DIR}")
exit(1)
def kill(proc):
@@ -762,7 +761,7 @@ def prepare(x_forwarded_host, x_forwarded_proto, postgres_db_name):
):
if len(cmd) == 0:
fail("Command to execute was given empty.")
- self.name = custom_name if custom_name else cmd[0]
+ self.name = custom_name if custom_name else basename(cmd[0])
self.cmd = cmd
self.capture_stdout = capture_stdout
self.log_dir = log_dir
@@ -771,9 +770,9 @@ def prepare(x_forwarded_host, x_forwarded_proto, postgres_db_name):
def run(self):
self.do()
return_code = self.handle.wait()
+ self.cleanup() # Mainly closes the log file.
if return_code != 0:
fail(f"Command {self.name} failed. Logs in {self.log_dir}")
- self.cleanup()
if self.capture_stdout:
return self.handle.communicate()[0].decode("utf-8").rstrip()
@@ -781,9 +780,8 @@ def prepare(x_forwarded_host, x_forwarded_proto, postgres_db_name):
return self.log_file.name
def cleanup(self):
- if not self.log_file.closed:
- self.log_file.flush()
- self.log_file.close()
+ self.log_file.flush()
+ self.log_file.close()
def do(self):
if not self.log_dir.is_dir():