buildkite / terminal-to-html

Converts arbitrary shell output (with ANSI) into beautifully rendered HTML
http://buildkite.github.io/terminal-to-html
MIT License
642 stars 45 forks source link

New output formats #146

Open DrJosh9000 opened 2 months ago

DrJosh9000 commented 2 months ago

This adds two new flags:

html is what we do today, and remains the default. plain is useful for a human investigating logs in a text editor, where ANSI escape sequences would get in the way. json and json-plain structure each line as a JSON object, which is more easily consumed by machine, keeping the line content and line metadata (timestamp) separate.

Since removing all ANSI escapes in plain mode would drop timestamp codes, it makes sense to have a way to optionally include the timestamps in plain output, with some configurable formatting. Hence --timestamp-format.

There's a case for making --timestamp-format have useful effects when using html format, but this requires a bit of thought (both the timestamp format itself, and the XML processing instruction "element" containing it, should be configurable).


Example outputs

cat fixtures/playwright.sh.raw | terminal-to-html --format=plain
(no timestamp)  $ npx playwright test --config=app/tests/e2e/config/playwright.config.prod.ts --project=chromium -g c1
2024-01-30T11:38:37.741+11:00   Starting the run with 8 tests
2024-01-30T11:38:37.741+11:00
2024-01-30T11:38:37.741+11:00   Running 8 tests using 1 worker, shard 1 of 2
2024-01-30T11:38:37.741+11:00
2024-01-30T11:38:49.98+11:00      ✓  1 [chromium] › c1/default/checkout.spec.ts:3:5 › checkout default flow (11.7s)
2024-01-30T11:39:04.169+11:00     ✓  2 [chromium] › c1/default/checkout.spec.ts:40:5 › checkout default flow with phone number (14.2s)
2024-01-30T11:39:16.277+11:00     ✓  3 [chromium] › c1/default/checkout.spec.ts:77:5 › checkout default flow with digital product (12.1s)
2024-01-30T11:39:25.823+11:00     ✓  4 [chromium] › c1/default/checkout.spec.ts:109:5 › checkout default flow with free digital product (9.5s)
2024-01-30T11:39:37.303+11:00     ✓  5 [chromium] › c1/default/checkout.spec.ts:133:5 › checkout default flow with free physical product (11.6s)
2024-01-30T11:39:53.194+11:00     ✓  6 [chromium] › c1/default/checkout.spec.ts:162:5 › checkout default flow with a manual payment (15.9s)
2024-01-30T11:40:05.691+11:00     ✓  7 [chromium] › c1/default/checkout.spec.ts:197:5 › checkout default flow with a custom payment (12.5s)
2024-01-30T11:40:05.691+11:00     -  8 [chromium] › c1/default/duplicate-tabs.spec.ts:4:6 › checkout with duplicate tabs
2024-01-30T11:40:05.691+11:00   Finished test run: passed
2024-01-30T11:40:05.958+11:00
2024-01-30T11:40:05.958+11:00     1 skipped
2024-01-30T11:40:05.958+11:00     7 passed (1.6m)
2024-01-30T11:40:05.978+11:00
(no timestamp)  Done in 96.34s.

cat fixtures/weather.sh.raw | terminal-to-html --format=plain
(no timestamp)  Weather for City: Berlin, Germany
(no timestamp)
(no timestamp)        .-.      Moderate or heavy rain with thunder
(no timestamp)       (   ).    2 – 6 °C
(no timestamp)      (___(__)   → 21 km/h
(no timestamp)     ‚‘⚡‘‚⚡‚‘    8 km
(no timestamp)     ‚’‚’⚡’‚’    2.4 mm

cat fixtures/playwright.sh.raw | terminal-to-html --format=json
{"content":"$ npx playwright test --config=app\u0026#47;tests\u0026#47;e2e\u0026#47;config\u0026#47;playwright.config.prod.ts --project=chromium -g c1","metadata":null}
{"content":"Starting the run with 8 tests","metadata":{"bk":{"t":"1706575117741"}}}
{"content":"\u0026nbsp;","metadata":{"bk":{"t":"1706575117741"}}}
{"content":"Running 8 tests using 1 worker, shard 1 of 2","metadata":{"bk":{"t":"1706575117741"}}}
{"content":"\u0026nbsp;","metadata":{"bk":{"t":"1706575117741"}}}
{"content":"  ✓  1 [chromium] › c1\u0026#47;default\u0026#47;checkout.spec.ts:3:5 › checkout default flow (11.7s)","metadata":{"bk":{"t":"1706575129980"}}}
{"content":"  ✓  2 [chromium] › c1\u0026#47;default\u0026#47;checkout.spec.ts:40:5 › checkout default flow with phone number (14.2s)","metadata":{"bk":{"t":"1706575144169"}}}
{"content":"  ✓  3 [chromium] › c1\u0026#47;default\u0026#47;checkout.spec.ts:77:5 › checkout default flow with digital product (12.1s)","metadata":{"bk":{"t":"1706575156277"}}}
{"content":"  ✓  4 [chromium] › c1\u0026#47;default\u0026#47;checkout.spec.ts:109:5 › checkout default flow with free digital product (9.5s)","metadata":{"bk":{"t":"1706575165823"}}}
{"content":"  ✓  5 [chromium] › c1\u0026#47;default\u0026#47;checkout.spec.ts:133:5 › checkout default flow with free physical product (11.6s)","metadata":{"bk":{"t":"1706575177303"}}}
{"content":"  ✓  6 [chromium] › c1\u0026#47;default\u0026#47;checkout.spec.ts:162:5 › checkout default flow with a manual payment (15.9s)","metadata":{"bk":{"t":"1706575193194"}}}
{"content":"  ✓  7 [chromium] › c1\u0026#47;default\u0026#47;checkout.spec.ts:197:5 › checkout default flow with a custom payment (12.5s)","metadata":{"bk":{"t":"1706575205691"}}}
{"content":"  -  8 [chromium] › c1\u0026#47;default\u0026#47;duplicate-tabs.spec.ts:4:6 › checkout with duplicate tabs","metadata":{"bk":{"t":"1706575205691"}}}
{"content":"Finished test run: passed","metadata":{"bk":{"t":"1706575205691"}}}
{"content":"\u0026nbsp;","metadata":{"bk":{"t":"1706575205958"}}}
{"content":"  1 skipped","metadata":{"bk":{"t":"1706575205958"}}}
{"content":"  7 passed (1.6m)","metadata":{"bk":{"t":"1706575205958"}}}
{"content":"\u0026nbsp;","metadata":{"bk":{"t":"1706575205978"}}}
{"content":"Done in 96.34s.","metadata":null}

cat fixtures/weather.sh.raw | terminal-to-html --format=json
{"content":"Weather for City: Berlin, Germany","metadata":null}
{"content":"\u0026nbsp;","metadata":null}
{"content":" \u003cspan class=\"term-fgx240 term-fg1\"\u003e     .-.     \u003c/span\u003e Moderate or heavy rain with thunder","metadata":null}
{"content":" \u003cspan class=\"term-fgx240 term-fg1\"\u003e    (   ).   \u003c/span\u003e \u003cspan class=\"term-fgx49\"\u003e2\u003c/span\u003e – \u003cspan class=\"term-fgx47\"\u003e6\u003c/span\u003e °C","metadata":null}
{"content":" \u003cspan class=\"term-fgx240 term-fg1\"\u003e   (___(__)  \u003c/span\u003e \u003cspan class=\"term-fg1\"\u003e→\u003c/span\u003e \u003cspan class=\"term-fgx214\"\u003e21\u003c/span\u003e km\u0026#47;h","metadata":null}
{"content":" \u003cspan class=\"term-fgx21 term-fg1\"\u003e  ‚‘\u003c/span\u003e\u003cspan class=\"term-fgx228 term-fg1 term-fg5\"\u003e⚡\u003c/span\u003e\u003cspan class=\"term-fgx21 term-fg1\"\u003e‘‚\u003c/span\u003e\u003cspan class=\"term-fgx228 term-fg1 term-fg5\"\u003e⚡\u003c/span\u003e\u003cspan class=\"term-fgx21 term-fg1\"\u003e‚‘   \u003c/span\u003e 8 km","metadata":null}
{"content":" \u003cspan class=\"term-fgx21 term-fg1\"\u003e  ‚’‚’\u003c/span\u003e\u003cspan class=\"term-fgx228 term-fg1 term-fg5\"\u003e⚡\u003c/span\u003e\u003cspan class=\"term-fgx21 term-fg1\"\u003e’‚’   \u003c/span\u003e 2.4 mm","metadata":null}
dabarrell commented 3 weeks ago

@DrJosh9000 Mind including some example of the json log output here?

DrJosh9000 commented 3 weeks ago

@DrJosh9000 Mind including some example of the json log output here?

Added to the description.