Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANSI Control Sequence parsing and Project Log timestamps #105

Merged
merged 2 commits into from
Oct 7, 2023
Merged

ANSI Control Sequence parsing and Project Log timestamps #105

merged 2 commits into from
Oct 7, 2023

Conversation

tlmii
Copy link
Member

@tlmii tlmii commented Oct 6, 2023

The primary purpose of this PR is enabling ANSI Control Sequence parsing to pass colors through from project logs to the log viewer. It does a few other things along the way, so here's the rundown:

  1. Logs are HTML Encoded before being sent to the browser, other than the spans that are added as part of the ANSI parsing
  2. The current "theme" of the log colors is based on the default Windows Terminal colors scheme. Fairly easy to change it if we want something else
  3. Enabling the colors to be passed through during output redirection is enabled via an environment variable injected into each project when it is run
  4. Since we're enabling colors, we also went ahead and enabled timestamps, and specified a format that (roughly) matches what the container logs output so that they're comparable
  5. When parsing the ANSI Control Sequences we try to just drop any sequences we recognize don't handle. It's possible we will get some feedback that we missed a class of common sequences that we need to detect and drop.

The formatting of project logs with timestamps enabled looks off. It's clear that lines 2-n of each log entry were indented based on the info/warn/dbug/etc messages in line 1 but NOT anticipating the timestamps. We may want to consider adjusting the indentation ourselves in this case, but I'll save that for another PR after feedback (need to see what would happen with the docker logs in the same scenario as well).

Resolves https://github.com/dotnet/aspire-private-planning/issues/664 and resolves https://github.com/dotnet/aspire-private-planning/issues/610

@tlmii
Copy link
Member Author

tlmii commented Oct 6, 2023

Screenshot:
image

Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Co-authored-by: David Fowler <davidfowl@gmail.com>
@tlmii tlmii merged commit d0bc7ca into dotnet:main Oct 7, 2023
4 checks passed
@tlmii tlmii deleted the dev/ansi-parsing branch October 7, 2023 03:41
// Enable Simple Console Logger Formatting with a UTC timestamp similar to RFC3339Nano that Docker generates
context.EnvironmentVariables["LOGGING__CONSOLE__FORMATTERNAME"] = "simple";
context.EnvironmentVariables["LOGGING__CONSOLE__FORMATTEROPTIONS__TIMESTAMPFORMAT"] = "yyyy-MM-dd'T'HH:mm:ss.ffffff'Z' ";
context.EnvironmentVariables["LOGGING__CONSOLE__FORMATTEROPTIONS__USEUTCTIMESTAMP"] = "true";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this configurable? I would rather see the time stamps in my own time zone when running locally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same, it should be local

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was my intention that it'd be configurable eventually. I just started off for this PR with matching the docker logs (RFC3339 and UTC, which doesn't appear to be configurable) since it seemed being able to compare timestamps would be useful. I filed #115 to track making the project logs timestamp format/tz configurable.

@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants