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

libherokubuildpack: Fix colour resetting for the log_* macros #890

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Dec 10, 2024

This fixes some long-standing ANSI colour bugs with the log_header, log_error and log_warning macros.

Whilst we soon want to move away to more advanced logging libraries that use the new logging style, there are still many buildpacks using these macros which will benefit short term from these fixes (Procfile, Go, Node.js, JVM, Python, PHP, buildpacks-release-phase, buildpacks-frontend-web).

The logging macros would previously emit output roughly like:

<colour>
[Error: Foo]
<reset><colour>Message line one.
Message line two.

This was not only missing the final <reset>, but also didn't wrap each line individually with colour codes/resets.

This causes issues when lines end up prefixed - such as the Git remote: prefix, or when using Pack CLI locally with an untrusted build (which adds the colourised [builder] prefixes) or --timestamps mode.

For example in this:

remote: <colour>
remote: [Error: Foo]
remote: <reset><colour>Message line one.
remote: Message line two.

...several of the remote:s would inherit the colours.

Instead what we need is:

remote: <colour><reset>
remote: <colour>[Error: Foo]<reset>
remote: <colour>Message line one.<reset>
remote: <colour>Message line two.<reset>

Fixes #555.
Closes #844.
GUS-W-17400078.

@edmorley edmorley added bug Something isn't working libherokubuildpack labels Dec 10, 2024
@edmorley edmorley self-assigned this Dec 10, 2024
@edmorley
Copy link
Member Author

Before

before

After

after

@edmorley edmorley marked this pull request as ready for review December 10, 2024 00:08
@edmorley edmorley requested a review from a team as a code owner December 10, 2024 00:08
This fixes some long-standing ANSI colour bugs with the `log_header`,
`log_error` and `log_warning` macros. Whilst we soon want to move away
to more advanced logging libraries that use the new logging style, there
are still many buildpacks using these macros which will benefit short
term from these fixes (Procfile, Go, Node.js, JVM, Python, PHP,
buildpacks-release-phase, buildpacks-frontend-web).

The logging macros would previously emit output roughly like:

```
<colour>
[Error: Foo]
<reset><colour>Message line one.
Message line two.
```

This was not only missing the final `<reset>`, but also didn't wrap
each line individually with colour codes/resets.

This causes issues when lines end up prefixed - such as the Git
`remote:` prefix, or when using Pack CLI locally with an untrusted build
(which adds the colourised `[builder]` prefixes) or `--timestamps` mode.

For example in this:

```
remote: <colour>
remote: [Error: Foo]
remote: <reset><colour>Message line one.
remote: Message line two.
```

...several of the `remote:`s would inherit the colours.

Instead what we need is:

```
remote:
remote: <colour>[Error: Foo]<reset>
remote: <colour>Message line one.<reset>
remote: <colour>Message line two.<reset>
```

Fixes #555.
Closes #844.
GUS-W-17400078.
@edmorley edmorley force-pushed the edmorley/fix-log-styling branch from 4367854 to d33fe4e Compare December 10, 2024 00:11
@edmorley edmorley merged commit 4db7e33 into main Dec 10, 2024
4 checks passed
@edmorley edmorley deleted the edmorley/fix-log-styling branch December 10, 2024 10:40
heroku-linguist bot added a commit to heroku/buildpacks-python that referenced this pull request Dec 13, 2024
## heroku/python

### Fixed

- Fixed colour resetting for build output header, error and warning messages. ([#303](#303) / [heroku/libcnb.rs#890](heroku/libcnb.rs#890))
heroku-linguist bot added a commit to heroku/buildpacks-python that referenced this pull request Dec 13, 2024
## heroku/python

### Fixed

- Fixed colour resetting for build output header, error and warning messages. ([#303](#303) / [heroku/libcnb.rs#890](heroku/libcnb.rs#890))

Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
heroku-linguist bot added a commit to heroku/cnb-builder-images that referenced this pull request Dec 13, 2024
## heroku/python

### Fixed

- Fixed colour resetting for build output header, error and warning messages. ([#303](heroku/buildpacks-python#303) / [heroku/libcnb.rs#890](heroku/libcnb.rs#890))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libherokubuildpack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libherokubuildpack: Pack output eats log colors
2 participants