|
17 | 17 | from itertools import combinations |
18 | 18 |
|
19 | 19 | import flux |
| 20 | +from flux.eventlog import EventLogFormatter |
20 | 21 | from flux.hostlist import Hostlist |
21 | 22 | from flux.idset import IDset |
22 | 23 | from flux.resource import ( |
@@ -720,38 +721,47 @@ def emit_R(args): |
720 | 721 | print(rset.encode()) |
721 | 722 |
|
722 | 723 |
|
723 | | -def print_events(events, follow, wait): |
| 724 | +def print_events(events, follow, wait, evf): |
724 | 725 | if not events and not follow and not wait: |
725 | 726 | return False |
726 | 727 | for entry in events: |
727 | | - print(json.dumps(entry)) |
| 728 | + print(evf.format(entry)) |
728 | 729 | if wait and entry["name"] == wait: |
729 | 730 | return False |
730 | 731 | return True |
731 | 732 |
|
732 | 733 |
|
733 | | -def eventlog_continuation(f, follow, wait): |
| 734 | +def eventlog_continuation(f, follow, wait, evf): |
734 | 735 | try: |
735 | 736 | payload = f.get() |
736 | 737 | except OSError as exc: |
737 | 738 | if exc.errno != errno.ENODATA: |
738 | 739 | raise |
739 | 740 | payload = None |
740 | | - if not payload or not print_events(payload["events"], follow, wait): |
| 741 | + if not payload or not print_events(payload["events"], follow, wait, evf): |
741 | 742 | f.flux_handle.reactor_stop() |
742 | 743 | else: |
743 | 744 | f.reset() |
744 | 745 |
|
745 | 746 |
|
746 | 747 | def eventlog(args): |
747 | 748 | """Show the resource eventlog""" |
| 749 | + if args.human: |
| 750 | + args.format = "text" |
| 751 | + args.time_format = "human" |
| 752 | + if args.color is None: |
| 753 | + args.color = "auto" |
| 754 | + |
748 | 755 | h = flux.Flux() |
| 756 | + evf = EventLogFormatter( |
| 757 | + format=args.format, timestamp_format=args.time_format, color=args.color |
| 758 | + ) |
749 | 759 | f = h.rpc( |
750 | 760 | "resource.journal", |
751 | 761 | nodeid=0, |
752 | 762 | flags=flux.constants.FLUX_RPC_STREAMING, |
753 | 763 | ) |
754 | | - f.then(eventlog_continuation, args.follow, args.wait) |
| 764 | + f.then(eventlog_continuation, args.follow, args.wait, evf) |
755 | 765 | h.reactor_run() |
756 | 766 |
|
757 | 767 |
|
@@ -1047,6 +1057,36 @@ def main(): |
1047 | 1057 | eventlog_parser = subparsers.add_parser( |
1048 | 1058 | "eventlog", formatter_class=flux.util.help_formatter() |
1049 | 1059 | ) |
| 1060 | + eventlog_parser.add_argument( |
| 1061 | + "-f", |
| 1062 | + "--format", |
| 1063 | + default="text", |
| 1064 | + metavar="FORMAT", |
| 1065 | + choices=["text", "json"], |
| 1066 | + help="Specify output format: text, json", |
| 1067 | + ) |
| 1068 | + eventlog_parser.add_argument( |
| 1069 | + "-T", |
| 1070 | + "--time-format", |
| 1071 | + default="raw", |
| 1072 | + metavar="FORMAT", |
| 1073 | + choices=["raw", "iso", "offset", "human", "reltime"], |
| 1074 | + help="Specify time format: raw, iso, offset, human", |
| 1075 | + ) |
| 1076 | + eventlog_parser.add_argument( |
| 1077 | + "-H", "--human", action="store_true", help="Display human-readable output." |
| 1078 | + ) |
| 1079 | + eventlog_parser.add_argument( |
| 1080 | + "-L", |
| 1081 | + "--color", |
| 1082 | + type=str, |
| 1083 | + metavar="WHEN", |
| 1084 | + choices=["never", "always", "auto"], |
| 1085 | + nargs="?", |
| 1086 | + const="always", |
| 1087 | + default="auto", |
| 1088 | + help="Use color; WHEN can be 'never', 'always', or 'auto' (default)", |
| 1089 | + ) |
1050 | 1090 | eventlog_parser.add_argument( |
1051 | 1091 | "-F", |
1052 | 1092 | "--follow", |
|
0 commit comments