Skip to content

New output formats#146

Draft
DrJosh9000 wants to merge 9 commits into
mainfrom
plain-with-timestamps
Draft

New output formats#146
DrJosh9000 wants to merge 9 commits into
mainfrom
plain-with-timestamps

Conversation

@DrJosh9000
Copy link
Copy Markdown
Contributor

@DrJosh9000 DrJosh9000 commented May 6, 2024

This adds two new flags:

  • --format, which can be one of html, plain, json, or json-plain, and
  • --timestamp-format, which controls the output format of timestamps in plain mode

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}

@DrJosh9000 DrJosh9000 force-pushed the plain-with-timestamps branch 2 times, most recently from 77eb235 to 73493ce Compare May 7, 2024 01:35
@DrJosh9000 DrJosh9000 changed the title WIP: Plain output format, optional timestamps Plain output format, optional timestamps May 7, 2024
@DrJosh9000 DrJosh9000 marked this pull request as ready for review May 7, 2024 02:04
@DrJosh9000 DrJosh9000 force-pushed the plain-with-timestamps branch from 7bae2ad to 86a933a Compare June 11, 2024 00:45
@DrJosh9000 DrJosh9000 changed the title Plain output format, optional timestamps New output formats Jun 12, 2024
@dabarrell
Copy link
Copy Markdown

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

@DrJosh9000
Copy link
Copy Markdown
Contributor Author

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

Added to the description.

@DrJosh9000 DrJosh9000 requested a review from a team June 12, 2024 06:42
@DrJosh9000 DrJosh9000 marked this pull request as draft September 16, 2024 23:27
@DrJosh9000 DrJosh9000 removed the request for review from a team September 16, 2024 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants