early logging

This commit is contained in:
ed 2026-04-23 19:26:39 +00:00
parent 8c7cdf8583
commit 46bd386a55
3 changed files with 22 additions and 20 deletions

View file

@ -71,6 +71,7 @@ from .util import (
expand_osenv_s,
has_resource,
load_resource,
lprint,
min_ex,
pybin,
read_utf8,
@ -98,7 +99,6 @@ except:
HAVE_SSL = False
u = unicode
printed: list[str] = []
zsid = uuid.uuid4().urn[4:]
CFG_DEF = [os.environ.get("PRTY_CONFIG", "")]
@ -174,16 +174,6 @@ class BasicDodge11874(
super(BasicDodge11874, self).__init__(*args, **kwargs)
def lprint(*a: Any, **ka: Any) -> None:
eol = ka.pop("end", "\n")
txt: str = " ".join(unicode(x) for x in a) + eol
printed.append(txt)
if not VT100:
txt = RE_ANSI.sub("", txt)
print(txt, end="", **ka)
def warn(msg: str) -> None:
lprint("\033[1mwarning:\033[0;33m {}\033[0m\n".format(msg))
@ -2303,7 +2293,7 @@ def main(argv: Optional[list[str]] = None) -> None:
# signal.signal(signal.SIGINT, sighandler)
SvcHub(al, dal, argv, "".join(printed)).run()
SvcHub(al, dal, argv).run()
if __name__ == "__main__":

View file

@ -75,6 +75,7 @@ from .util import (
load_ipr,
load_ipu,
lock_file,
lprinted,
min_ex,
mp,
odfusion,
@ -127,7 +128,6 @@ class SvcHub(object):
args: argparse.Namespace,
dargs: argparse.Namespace,
argv: list[str],
printed: str,
) -> None:
self.args = args
self.dargs = dargs
@ -210,15 +210,16 @@ class SvcHub(object):
self.log = self._log_enabled
if args.lo:
self._setup_logfile(printed)
self._setup_logfile()
LOG[0] = self.log
lprinted[:] = []
lg = logging.getLogger()
lh = HLog(self.log)
lg.handlers = [lh]
lg.setLevel(logging.DEBUG)
LOG[:] = [self.log]
self._check_env()
if args.stackmon:
@ -1367,7 +1368,7 @@ class SvcHub(object):
return fn
def _setup_logfile(self, printed: str) -> None:
def _setup_logfile(self) -> None:
base_fn = fn = sel_fn = self._logname()
do_xz = fn.lower().endswith(".xz")
if fn != self.args.lo:
@ -1407,7 +1408,7 @@ class SvcHub(object):
argv = ['"{}"'.format(x) for x in argv]
msg = "[+] opened logfile [{}]\n".format(fn)
printed += msg
printed = "".join(lprinted) + msg
t = "t0: {:.3f}\nargv: {}\n\n{}"
lh.write(t.format(self.E.t0, " ".join(argv), printed))
self.logf = lh
@ -1679,7 +1680,7 @@ class SvcHub(object):
def _set_next_day(self, dt: datetime) -> None:
if self.cday and self.logf and self.logf_base_fn != self._logname():
self.logf.close()
self._setup_logfile("")
self._setup_logfile()
self.cday = dt.day
self.cmon = dt.month

View file

@ -62,7 +62,18 @@ def noop(*a, **ka):
pass
LOG = [print]
def lprint(*a: Any, **ka: Any) -> None:
eol = ka.pop("end", "\n")
txt = " ".join(unicode(x) for x in a) + eol
lprinted.append(txt)
if not VT100 and "\033" in txt:
txt = RE_ANSI.sub("", txt)
print(txt, end="", **ka)
lprinted: list[str] = []
LOG: list[Callable[[Any], None]] = [lprint]
try: