mirror of
https://github.com/9001/copyparty.git
synced 2026-06-20 21:22:26 -06:00
early logging
This commit is contained in:
parent
8c7cdf8583
commit
46bd386a55
|
|
@ -71,6 +71,7 @@ from .util import (
|
||||||
expand_osenv_s,
|
expand_osenv_s,
|
||||||
has_resource,
|
has_resource,
|
||||||
load_resource,
|
load_resource,
|
||||||
|
lprint,
|
||||||
min_ex,
|
min_ex,
|
||||||
pybin,
|
pybin,
|
||||||
read_utf8,
|
read_utf8,
|
||||||
|
|
@ -98,7 +99,6 @@ except:
|
||||||
HAVE_SSL = False
|
HAVE_SSL = False
|
||||||
|
|
||||||
u = unicode
|
u = unicode
|
||||||
printed: list[str] = []
|
|
||||||
zsid = uuid.uuid4().urn[4:]
|
zsid = uuid.uuid4().urn[4:]
|
||||||
|
|
||||||
CFG_DEF = [os.environ.get("PRTY_CONFIG", "")]
|
CFG_DEF = [os.environ.get("PRTY_CONFIG", "")]
|
||||||
|
|
@ -174,16 +174,6 @@ class BasicDodge11874(
|
||||||
super(BasicDodge11874, self).__init__(*args, **kwargs)
|
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:
|
def warn(msg: str) -> None:
|
||||||
lprint("\033[1mwarning:\033[0;33m {}\033[0m\n".format(msg))
|
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)
|
# signal.signal(signal.SIGINT, sighandler)
|
||||||
|
|
||||||
SvcHub(al, dal, argv, "".join(printed)).run()
|
SvcHub(al, dal, argv).run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ from .util import (
|
||||||
load_ipr,
|
load_ipr,
|
||||||
load_ipu,
|
load_ipu,
|
||||||
lock_file,
|
lock_file,
|
||||||
|
lprinted,
|
||||||
min_ex,
|
min_ex,
|
||||||
mp,
|
mp,
|
||||||
odfusion,
|
odfusion,
|
||||||
|
|
@ -127,7 +128,6 @@ class SvcHub(object):
|
||||||
args: argparse.Namespace,
|
args: argparse.Namespace,
|
||||||
dargs: argparse.Namespace,
|
dargs: argparse.Namespace,
|
||||||
argv: list[str],
|
argv: list[str],
|
||||||
printed: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.args = args
|
self.args = args
|
||||||
self.dargs = dargs
|
self.dargs = dargs
|
||||||
|
|
@ -210,15 +210,16 @@ class SvcHub(object):
|
||||||
self.log = self._log_enabled
|
self.log = self._log_enabled
|
||||||
|
|
||||||
if args.lo:
|
if args.lo:
|
||||||
self._setup_logfile(printed)
|
self._setup_logfile()
|
||||||
|
|
||||||
|
LOG[0] = self.log
|
||||||
|
lprinted[:] = []
|
||||||
|
|
||||||
lg = logging.getLogger()
|
lg = logging.getLogger()
|
||||||
lh = HLog(self.log)
|
lh = HLog(self.log)
|
||||||
lg.handlers = [lh]
|
lg.handlers = [lh]
|
||||||
lg.setLevel(logging.DEBUG)
|
lg.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
LOG[:] = [self.log]
|
|
||||||
|
|
||||||
self._check_env()
|
self._check_env()
|
||||||
|
|
||||||
if args.stackmon:
|
if args.stackmon:
|
||||||
|
|
@ -1367,7 +1368,7 @@ class SvcHub(object):
|
||||||
|
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
def _setup_logfile(self, printed: str) -> None:
|
def _setup_logfile(self) -> None:
|
||||||
base_fn = fn = sel_fn = self._logname()
|
base_fn = fn = sel_fn = self._logname()
|
||||||
do_xz = fn.lower().endswith(".xz")
|
do_xz = fn.lower().endswith(".xz")
|
||||||
if fn != self.args.lo:
|
if fn != self.args.lo:
|
||||||
|
|
@ -1407,7 +1408,7 @@ class SvcHub(object):
|
||||||
argv = ['"{}"'.format(x) for x in argv]
|
argv = ['"{}"'.format(x) for x in argv]
|
||||||
|
|
||||||
msg = "[+] opened logfile [{}]\n".format(fn)
|
msg = "[+] opened logfile [{}]\n".format(fn)
|
||||||
printed += msg
|
printed = "".join(lprinted) + msg
|
||||||
t = "t0: {:.3f}\nargv: {}\n\n{}"
|
t = "t0: {:.3f}\nargv: {}\n\n{}"
|
||||||
lh.write(t.format(self.E.t0, " ".join(argv), printed))
|
lh.write(t.format(self.E.t0, " ".join(argv), printed))
|
||||||
self.logf = lh
|
self.logf = lh
|
||||||
|
|
@ -1679,7 +1680,7 @@ class SvcHub(object):
|
||||||
def _set_next_day(self, dt: datetime) -> None:
|
def _set_next_day(self, dt: datetime) -> None:
|
||||||
if self.cday and self.logf and self.logf_base_fn != self._logname():
|
if self.cday and self.logf and self.logf_base_fn != self._logname():
|
||||||
self.logf.close()
|
self.logf.close()
|
||||||
self._setup_logfile("")
|
self._setup_logfile()
|
||||||
|
|
||||||
self.cday = dt.day
|
self.cday = dt.day
|
||||||
self.cmon = dt.month
|
self.cmon = dt.month
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,18 @@ def noop(*a, **ka):
|
||||||
pass
|
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:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue