(args: list[str])
| 813 | |
| 814 | |
| 815 | def _cmd_logs(args: list[str]) -> None: |
| 816 | flags, _ = _parse_flags(args, {"limit": True, "follow": False}) |
| 817 | limit = int(flags.get("limit", 50)) |
| 818 | follow = bool(flags.get("follow")) |
| 819 | |
| 820 | if not _LOG_FILE.exists(): |
| 821 | print(" No log file found") |
| 822 | print(" Start the proxy in background: uncommon-route serve --daemon") |
| 823 | return |
| 824 | |
| 825 | if follow: |
| 826 | print(f" Tailing {_LOG_FILE} (Ctrl+C to stop)") |
| 827 | try: |
| 828 | with open(_LOG_FILE) as f: |
| 829 | f.seek(0, 2) |
| 830 | while True: |
| 831 | line = f.readline() |
| 832 | if line: |
| 833 | print(line, end="") |
| 834 | else: |
| 835 | time.sleep(0.3) |
| 836 | except KeyboardInterrupt: |
| 837 | pass |
| 838 | return |
| 839 | |
| 840 | lines = _LOG_FILE.read_text().splitlines() |
| 841 | for line in lines[-limit:]: |
| 842 | print(line) |
| 843 | |
| 844 | |
| 845 | _ANSI_RESET = "\x1b[0m" |
nothing calls this directly
no test coverage detected