mirror of
https://github.com/9001/copyparty.git
synced 2026-02-21 01:40:39 +10:00
add --flo (logfile format)
This commit is contained in:
@@ -1637,6 +1637,7 @@ def add_logging(ap):
|
||||
ap2 = ap.add_argument_group("logging options")
|
||||
ap2.add_argument("-q", action="store_true", help="quiet; disable most STDOUT messages")
|
||||
ap2.add_argument("-lo", metavar="PATH", type=u, default="", help="logfile; use .txt for plaintext or .xz for compressed. Example: \033[32mcpp-%%Y-%%m%%d-%%H%%M%%S.txt.xz\033[0m (NB: some errors may appear on STDOUT only)")
|
||||
ap2.add_argument("--flo", metavar="N", type=int, default=1, help="log format for \033[33m-lo\033[0m; [\033[32m1\033[0m]=classic/colors, [\033[32m2\033[0m]=no-color")
|
||||
ap2.add_argument("--no-ansi", action="store_true", default=not VT100, help="disable colors; same as environment-variable NO_COLOR")
|
||||
ap2.add_argument("--ansi", action="store_true", help="force colors; overrides environment-variable NO_COLOR")
|
||||
ap2.add_argument("--no-logflush", action="store_true", help="don't flush the logfile after each write; tiny bit faster")
|
||||
|
||||
@@ -124,6 +124,7 @@ class SvcHub(object):
|
||||
self.argv = argv
|
||||
self.E: EnvParams = args.E
|
||||
self.no_ansi = args.no_ansi
|
||||
self.flo = args.flo
|
||||
self.tz = UTC if args.log_utc else None
|
||||
self.logf: Optional[typing.TextIO] = None
|
||||
self.logf_base_fn = ""
|
||||
@@ -1571,21 +1572,38 @@ class SvcHub(object):
|
||||
dt.microsecond // self.log_div,
|
||||
)
|
||||
|
||||
if c and not self.args.no_ansi:
|
||||
if isinstance(c, int):
|
||||
if self.flo == 1:
|
||||
fmt = "@%s [%-21s] %s\n"
|
||||
if not c:
|
||||
if "\033" in msg:
|
||||
msg += "\033[0m"
|
||||
elif isinstance(c, int):
|
||||
msg = "\033[3%sm%s\033[0m" % (c, msg)
|
||||
elif "\033" not in c:
|
||||
msg = "\033[%sm%s\033[0m" % (c, msg)
|
||||
else:
|
||||
msg = "%s%s\033[0m" % (c, msg)
|
||||
|
||||
if "\033" in src:
|
||||
src += "\033[0m"
|
||||
if "\033" in src:
|
||||
src += "\033[0m"
|
||||
else:
|
||||
if not c:
|
||||
fmt = "@%s LOG [%-21s] %s\n"
|
||||
elif c == 1:
|
||||
fmt = "@%s CRIT [%-21s] %s\n"
|
||||
elif c == 3:
|
||||
fmt = "@%s WARN [%-21s] %s\n"
|
||||
elif c == 6:
|
||||
fmt = "@%s BTW [%-21s] %s\n"
|
||||
else:
|
||||
fmt = "@%s LOG [%-21s] %s\n"
|
||||
|
||||
if "\033" in msg:
|
||||
msg += "\033[0m"
|
||||
if "\033" in src:
|
||||
src = RE_ANSI.sub("", src)
|
||||
if "\033" in msg:
|
||||
msg = RE_ANSI.sub("", msg)
|
||||
|
||||
self.logf.write("@%s [%-21s] %s\n" % (ts, src, msg))
|
||||
self.logf.write(fmt % (ts, src, msg))
|
||||
if not self.args.no_logflush:
|
||||
self.logf.flush()
|
||||
|
||||
@@ -1615,9 +1633,10 @@ class SvcHub(object):
|
||||
if self.logf:
|
||||
self.logf.write(zs)
|
||||
|
||||
fmt = "\033[36m%s \033[33m%-21s \033[0m%s\n"
|
||||
if self.no_ansi:
|
||||
if c == 1:
|
||||
if not c:
|
||||
fmt = "%s %-21s LOG: %s\n"
|
||||
elif c == 1:
|
||||
fmt = "%s %-21s CRIT: %s\n"
|
||||
elif c == 3:
|
||||
fmt = "%s %-21s WARN: %s\n"
|
||||
@@ -1625,12 +1644,16 @@ class SvcHub(object):
|
||||
fmt = "%s %-21s BTW: %s\n"
|
||||
else:
|
||||
fmt = "%s %-21s LOG: %s\n"
|
||||
|
||||
if "\033" in msg:
|
||||
msg = RE_ANSI.sub("", msg)
|
||||
if "\033" in src:
|
||||
src = RE_ANSI.sub("", src)
|
||||
elif c:
|
||||
if isinstance(c, int):
|
||||
else:
|
||||
fmt = "\033[36m%s \033[33m%-21s \033[0m%s\n"
|
||||
if not c:
|
||||
pass
|
||||
elif isinstance(c, int):
|
||||
msg = "\033[3%sm%s\033[0m" % (c, msg)
|
||||
elif "\033" not in c:
|
||||
msg = "\033[%sm%s\033[0m" % (c, msg)
|
||||
|
||||
Reference in New Issue
Block a user