Skip to content

fix(bst): Do not alter logger in library mode, log to stderr not stdout#2085

Merged
effigies merged 3 commits intobids-standard:maint/1.10.0from
yarikoptic:bf-logger
Mar 13, 2025
Merged

fix(bst): Do not alter logger in library mode, log to stderr not stdout#2085
effigies merged 3 commits intobids-standard:maint/1.10.0from
yarikoptic:bf-logger

Conversation

@yarikoptic
Copy link
Copy Markdown
Collaborator

We tried to upgrade to use recent bidsschematools in dandi-cli (dandi/dandi-cli#1591) but tests started to fail since output was polluted with log messages from bidsschematools, which prompted me to look inside.

I have tried to keep my changes minimal (but did rename logger to lgr for consistency) and individual commits provide a little more information, but overall point - do not configure logger unless it is an "end user application". And it is typical for logging to just go into stderr to not interfere with potential "useful" output on stdout.

@yarikoptic yarikoptic added the schema-code Updates or changes to the code used to parse, filter, and render the schema. label Mar 13, 2025
@yarikoptic yarikoptic requested a review from erdalkaraca as a code owner March 13, 2025 02:02
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2025

Codecov Report

Attention: Patch coverage is 21.73913% with 18 lines in your changes missing coverage. Please review.

Project coverage is 82.92%. Comparing base (b842180) to head (b38ca9a).

Files with missing lines Patch % Lines
tools/schemacode/src/bidsschematools/__main__.py 0.00% 12 Missing ⚠️
tools/schemacode/src/bidsschematools/utils.py 45.45% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2085      +/-   ##
==========================================
- Coverage   83.49%   82.92%   -0.58%     
==========================================
  Files          17       17              
  Lines        1509     1511       +2     
==========================================
- Hits         1260     1253       -7     
- Misses        249      258       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@effigies

This comment was marked as resolved.

@effigies effigies changed the base branch from master to maint/1.10.0 March 13, 2025 12:19
Libraries should not set handlers or even change log level (by default).
It is up to the user-facing code (project using the library, e.g. CLI)
to set the logging etc. Otherwise libraries would interfere with desired
behaviors of the project, as they do now here with logging polluting stdout
of a tool which must produce yaml output
@effigies
Copy link
Copy Markdown
Collaborator

Thanks, if this works for your use case, that's great. I don't have a great feel for logging best practices for libraries vs apps, so I haven't imposed much of a structure here. As far as I'm concerned, you're welcome to refactor this entirely, if you have further suggestions.

Do you have a doc that you have written or use as a guideline? It would be nice to have a reference I can go back to.

Copy link
Copy Markdown
Collaborator

@effigies effigies left a comment

Choose a reason for hiding this comment

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

LGTM. Small nit.

@effigies effigies added the exclude-from-changelog This item will not feature in the automatically generated changelog label Mar 13, 2025
@effigies effigies changed the title [FIX] bidsschematools - do not alter logger in library mode, log to stderr not stdout fix(bst): Do not alter logger in library mode, log to stderr not stdout Mar 13, 2025
@effigies effigies merged commit 4f3ae8e into bids-standard:maint/1.10.0 Mar 13, 2025
2 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exclude-from-changelog This item will not feature in the automatically generated changelog schema-code Updates or changes to the code used to parse, filter, and render the schema.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants