Skip to content

log hook messages to stderr #2293

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

Merged
merged 3 commits into from
Apr 30, 2025
Merged

log hook messages to stderr #2293

merged 3 commits into from
Apr 30, 2025

Conversation

minrk
Copy link
Member

@minrk minrk commented Apr 28, 2025

Describe your changes

  • use _log in run-hooks.sh, like start.sh (needs to redefine it for unnittests only, could split into a common utility file)
  • _log writes to stderr instead of stdout for easier output capture (piping, etc.)

In general, it's a good practice to avoid logging to stdout, since it means you can't capture command output with pipes, e.g.

docker run --rm -it quay.io/jupyter/base-notebook conda env export > base-env.yml

because it will include the 'uid: 1000`, etc. messages.

Checklist (especially for first-time contributors)

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests
  • I will try not to use force-push to make the review process easier for reviewers
  • I have updated the documentation for significant changes

I looked through the tests, and it's tricky because the tests run with tty: true, in which case docker merges stdout and stderr, so can't test the splitting is correct. Running with tty: false, e.g. docker run --rm -i pwd > stdout.txt 2>stderr.txt does the right thing in a manual test. I'm just not 100% sure of the best way to add a test case for that with the current infrastructure.

- use _log in run-hooks.sh (assumes run-hooks is sourced from start.sh, which is true, but is it safe?)
- log writes to stderr instead of stdout for easier output capture (piping, etc.)
@mathbunnyru
Copy link
Member

mathbunnyru commented Apr 29, 2025

I looked through the tests, and it's tricky because the tests run with tty: true, in which case docker merges stdout and stderr, so can't test the splitting is correct. Running with tty: false, e.g. docker run --rm -i pwd > stdout.txt 2>stderr.txt does the right thing in a manual test. I'm just not 100% sure of the best way to add a test case for that with the current infrastructure.

Hi @minrk, all our tests run fine with and without tty (I recently worked on that), but I enabled tty by default to have color logs and to spot errors easier.

The only exception where I had to disable it was here:

timeout=10, no_warnings=False, user="1010", command=["id"], tty=False

You can also disable it for your individual tests if needed.

returns (stdout, stderr) instead of merged stream
@minrk
Copy link
Member Author

minrk commented Apr 30, 2025

Thanks! I added a way to split stdout and stderr and some tests to exercise this.

Copy link
Member

@mathbunnyru mathbunnyru left a comment

Choose a reason for hiding this comment

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

Overall, looks great, asked to change 2 small things.

Copy link
Member

@mathbunnyru mathbunnyru left a comment

Choose a reason for hiding this comment

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

🚀
Please, squash-merge when CI is green

@mathbunnyru mathbunnyru merged commit 1eacd4e into jupyter:main Apr 30, 2025
69 checks passed
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