mirror of
https://github.com/9001/copyparty.git
synced 2026-04-12 23:32:32 -06:00
Removed color codes from log file
no ugly escape codes in logs :>
This commit is contained in:
parent
6eb4f0ad9c
commit
1c474fef16
|
|
@ -2047,6 +2047,20 @@ def run_argparse(
|
|||
|
||||
|
||||
def main(argv: Optional[list[str]] = None) -> None:
|
||||
## if ever want to use logging
|
||||
# import re, logging
|
||||
# COLOR_RE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
|
||||
# def clean(msg: str):
|
||||
# return COLOR_RE.sub('', msg)
|
||||
# orig_fac = logging.getLogRecordFactory()
|
||||
# def logger_fac(*args, **kwargs):
|
||||
# record = orig_fac(*args, **kwargs)
|
||||
# print("Boing!")
|
||||
# if (isinstance(record.msg, str)):
|
||||
# record.msg = clean(record.msg)
|
||||
# return record
|
||||
# logging.setLogRecordFactory(logger_fac)
|
||||
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
|
||||
|
|
|
|||
|
|
@ -1372,6 +1372,19 @@ class SvcHub(object):
|
|||
|
||||
lh = codecs.open(fn, "w", encoding="utf-8", errors="replace")
|
||||
|
||||
# Patch the opened log file write method
|
||||
orig_w = getattr(lh, "write")
|
||||
|
||||
def patched_write(data: str):
|
||||
try:
|
||||
clean = self.clean(data)
|
||||
except:
|
||||
clean = data
|
||||
return orig_w(clean)
|
||||
|
||||
setattr(lh, "write", patched_write)
|
||||
# lh.write = patched_write #type: ignore
|
||||
|
||||
if getattr(self.args, "free_umask", False):
|
||||
os.fchmod(lh.fileno(), 0o644)
|
||||
|
||||
|
|
@ -1389,6 +1402,11 @@ class SvcHub(object):
|
|||
self.logf_base_fn = base_fn
|
||||
print(msg, end="")
|
||||
|
||||
# https://regex101.com/r/96ZckU/1
|
||||
COLOR_RE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
|
||||
def clean(self, msg: str):
|
||||
return self.COLOR_RE.sub('', msg)
|
||||
|
||||
def run(self) -> None:
|
||||
self.tcpsrv.run()
|
||||
if getattr(self.args, "z_chk", 0) and (
|
||||
|
|
|
|||
43
docs/colors.txt
Normal file
43
docs/colors.txt
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
\033[0;1m
|
||||
\033[0;7m
|
||||
|
||||
\033[0;32m
|
||||
\033[0;33m
|
||||
\033[0;35m
|
||||
\033[0;36m
|
||||
\033[0;40m
|
||||
\033[0;47m
|
||||
\033[0;90m
|
||||
|
||||
\033[1;30m
|
||||
\033[1;31m
|
||||
\033[1;35m
|
||||
|
||||
\033[30;47m
|
||||
|
||||
\033[07m (same as \033[7m)
|
||||
|
||||
\033[0m
|
||||
\033[1m
|
||||
\033[7m
|
||||
\033[27m
|
||||
\033[31m
|
||||
\033[32m
|
||||
\033[33m
|
||||
\033[34m
|
||||
\033[35m
|
||||
\033[36m
|
||||
\033[44m
|
||||
\033[45m
|
||||
\033[90m
|
||||
\033[94m
|
||||
\033[97m
|
||||
|
||||
| Code type | Range |
|
||||
| ---------- | ------- |
|
||||
| Reset | `0` |
|
||||
| Bold | `1` |
|
||||
| Inverse | `7` |
|
||||
| Foreground | `30–37` |
|
||||
| Background | `40–47` |
|
||||
| Bright FG | `90–97` |
|
||||
|
|
@ -491,6 +491,12 @@ mostly fine on android, but still haven't find a way to massage iphones into be
|
|||
|
||||
can be reproduced with `--no-sendfile --s-wr-sz 8192 --s-wr-slp 0.3 --rsp-slp 6` and then play a collection of small audio files with the screen off, `ffmpeg -i track01.cdda.flac -c:a libopus -b:a 128k -segment_time 12 -f segment smol-%02d.opus`
|
||||
|
||||
## grabing colors
|
||||
to grab all color codes (ANSII escape seq) from the source (`../copyparty/`) (optional)
|
||||
|
||||
```bash
|
||||
grep -roIE '\\033\[([0-9]{1,3};)?[0-9]{1,3}m' | sort -t ':' -k2 | cut -d ':' -f2 | sort -u
|
||||
```
|
||||
|
||||
## discarded ideas
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue