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

improvement(core): better action lifecycle logs #5428

Merged
merged 2 commits into from Nov 20, 2023
Merged

Conversation

eysi09
Copy link
Collaborator

@eysi09 eysi09 commented Nov 16, 2023

What this PR does / why we need it:

This commits adds more logging to the action lifecycle. That is logs about getting status of a given action, the results, next steps, etc.

The logging is done in the task decorators that are also used for emitting events.

The goal is obviously to make the logs more informative but also more consistent.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Here's a screenshot of the new logs. Note that the screenshot uses different colors to what we currently have so that the change is more visible. But we'll make those color changes in a separate PR though.

Screenshot 2023-11-16 at 23 54 26

@eysi09 eysi09 requested a review from thsig November 16, 2023 14:34
if (!msg) {
return ""
}
// For log levels higher than "info" we print the log level name.
Copy link
Collaborator Author

@eysi09 eysi09 Nov 16, 2023

Choose a reason for hiding this comment

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

I moved the log level name to the log line proper.

So now it's:

section => [level name] message

as opposed to:

section [level name] => message

@eysi09 eysi09 marked this pull request as draft November 16, 2023 15:02
@eysi09 eysi09 force-pushed the action-log-improvements branch 8 times, most recently from 5533a26 to c8b42ec Compare November 16, 2023 22:56
/**
* A map of all the colors we use to render text in the terminal.
*/
const theme = {
primary: chalk.grey as unknown as Styles,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was just plain wrong so I removed it.

`${styles.primary("[debug]")} ${styles.primary("hello world")}\n`
)
})
it("should print the log level if it's higher then 'info' after the section if there is one", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed this behaviour so we can remove this test. There's already a test case for the "new" behaviour.

@eysi09 eysi09 marked this pull request as ready for review November 16, 2023 23:04
willRerun: boolean
}) {
if (result.state === "ready") {
const readyStr = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this code could use some extracting of those string maps to the outer scope and adding a few line breaks for clarity.

@@ -492,6 +512,19 @@ export function emitProcessingEvents<
const actionKind = this.action.kind.toLowerCase() as Lowercase<A["kind"]>
const eventName = actionKindToEventNameMap[actionKind]
const startedAt = new Date().toISOString()
const log = this.log.createLog()
const version = this.action.versionString()
const verb = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This mapping here should also probably live outside of the function.

Since they're all always using the same indexing over Build, Deploy etc, we can probably do something like

const PROCESSING_EVENTS_LOG_STRINGS = {
  Build: {
    verb: "Building",
    ready: "built",
    run: "will be built",
    rerun: "re-build",
  },
...
}

@eysi09
Copy link
Collaborator Author

eysi09 commented Nov 17, 2023

Thanks for the review @TimBeyer! I originally co-located these map with the log lines because I kept tweaking it and it made things more visible.

But I agree that your suggestion is cleaner, addressed in the latest commit.

This commits adds more logging to the action lifecycle. That is logs
about getting status of a given action, the results, next steps, etc.

The logging is done in the task decorators that are also used for
emitting events.

The goal is obviously to make the logs more informative but also more
consistent.

Furthermore, this commit fixes the type for the `styles` map which were
way off. This means you can "break out" of the map and call all chalk
methods when chaining and it would be nice to narrow that down. But
we're going for loose and correct for now.
@eysi09 eysi09 added this pull request to the merge queue Nov 20, 2023
Merged via the queue into main with commit 65653b9 Nov 20, 2023
45 checks passed
@eysi09 eysi09 deleted the action-log-improvements branch November 20, 2023 13:04
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.

None yet

3 participants