logs.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """``hermes logs`` subcommand parser."""
  2. from __future__ import annotations
  3. import argparse
  4. from typing import Callable
  5. def build_logs_parser(subparsers, *, cmd_logs: Callable) -> None:
  6. """Attach the ``logs`` subcommand to ``subparsers``."""
  7. logs_parser = subparsers.add_parser(
  8. "logs",
  9. help="View and filter Hermes log files",
  10. description="View, tail, and filter agent.log / errors.log / gateway.log / gui.log / desktop.log / update.log / desktop-update-handoff.log",
  11. formatter_class=argparse.RawDescriptionHelpFormatter,
  12. epilog="""\
  13. Examples:
  14. hermes logs Show last 50 lines of agent.log
  15. hermes logs -f Follow agent.log in real time
  16. hermes logs errors Show last 50 lines of errors.log
  17. hermes logs gateway -n 100 Show last 100 lines of gateway.log
  18. hermes logs gui -f Follow gui.log in real time
  19. hermes logs desktop -f Follow desktop.log (Electron app boot/backend)
  20. hermes logs update Show last 50 lines of update.log (hermes update mirror)
  21. hermes logs handoff Show last 50 lines of desktop-update-handoff.log
  22. hermes logs --level WARNING Only show WARNING and above
  23. hermes logs --session abc123 Filter by session ID
  24. hermes logs --component tools Only show tool-related lines
  25. hermes logs --since 1h Lines from the last hour
  26. hermes logs --since 30m -f Follow, starting from 30 min ago
  27. hermes logs list List available log files with sizes
  28. """)
  29. logs_parser.add_argument(
  30. "log_name",
  31. nargs="?",
  32. default="agent",
  33. help="Log to view: agent (default), errors, gateway, gui, desktop, update, handoff, or 'list' to show available files",
  34. )
  35. logs_parser.add_argument(
  36. "-n", "--lines", type=int, default=50, help="Number of lines to show (default: 50)")
  37. logs_parser.add_argument(
  38. "-f", "--follow", action="store_true", help="Follow the log in real time (like tail -f)")
  39. logs_parser.add_argument(
  40. "--level", metavar="LEVEL", help="Minimum log level to show (DEBUG, INFO, WARNING, ERROR)")
  41. logs_parser.add_argument(
  42. "--session", metavar="ID", help="Filter lines containing this session ID substring")
  43. logs_parser.add_argument(
  44. "--since", metavar="TIME", help="Show lines since TIME ago (e.g. 1h, 30m, 2d)")
  45. logs_parser.add_argument(
  46. "--component", metavar="NAME",
  47. help="Filter by component: gateway, agent, tools, cli, cron, gui")
  48. logs_parser.set_defaults(func=cmd_logs)