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
[ENH] implement logger for first_level_from_bids #3702
base: main
Are you sure you want to change the base?
Conversation
logging.basicConfig(level=logging.ERROR) | ||
logger = logging.getLogger(name="nilearn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially create a function nilearn/_utils/logger.py ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually there is one 😆 it's used in a few modules but not consistently. it should probably be removed as part of a larger change if we replace current print calls with logging
@@ -1527,8 +1511,7 @@ def _make_bids_files_filter( | |||
if extra_filter and supported_filters: | |||
for filter_ in extra_filter: | |||
if filter_[0] not in supported_filters: | |||
if verbose: | |||
warn( | |||
logger.warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should warning be handled by the logger as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC the warning reports an error that the application developer should correct, so IMO and my understanding of the logging module's documentation it should be a warning (not a logging event), and wether we use logging or not it shouldn't be controlled by the verbose parameter
👋 @Remi-Gau Thanks for creating a PR! Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft. Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.
For new features:
For bug fixes:
We will review it as quick as possible, feel free to ping us with questions if needed. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3702 +/- ##
==========================================
- Coverage 91.40% 91.38% -0.02%
==========================================
Files 133 133
Lines 15536 15552 +16
Branches 3225 3225
==========================================
+ Hits 14200 14212 +12
- Misses 784 787 +3
- Partials 552 553 +1 ☔ View full report in Codecov by Sentry. |
@jeromedockes this is just a quick dirty example of how things could look like with a logger. Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I didn't realise implement a logger meant start using the logging
standard library module. I think it's a good idea, but then we would probably want to use it consistently throughout the library and plan it a bit more... there is some discussion to be had as some people find logging
confusing, and we should read through related scikit-learn discussions (linked below).
and maybe wait for the formatting stuff to be over so we don't have too many widespread changes going on at the same time
for the specific case of 1st level from bids, I wonder if we should have a class to have fewer functions with a lot of parameters, and a way to store some info like the discovered files and produce reports?
logging.basicConfig(level=logging.ERROR) | ||
logger = logging.getLogger(name="nilearn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually there is one 😆 it's used in a few modules but not consistently. it should probably be removed as part of a larger change if we replace current print calls with logging
@@ -49,6 +49,11 @@ | |||
from sklearn.cluster import KMeans | |||
|
|||
|
|||
import logging | |||
|
|||
logging.basicConfig(level=logging.ERROR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory libraries are not supposed to mess with the logging configuration, and definitely not add any handlers to the root logger (doc), as that is left up to the application... I guess current joblib/scikit-learn/nilearn approach of verbose
and print
is quite far from the standard library logging
module's philosophy, and it might be worth reading the related discussions in related scikit-learn issues: roadmap, 6929, 78
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also the default handlers writes to stderr while the rest of nilearn messages made with print would go to stdout, it would be a bit weird to have just the first_level_model_from_bids output go to a different stream
@@ -1154,12 +1161,12 @@ def _report_found_files( | |||
Only one filter per field allowed. | |||
|
|||
""" | |||
print( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the only thing that is controlled by the verbose parameter in our case?
@@ -1527,8 +1511,7 @@ def _make_bids_files_filter( | |||
if extra_filter and supported_filters: | |||
for filter_ in extra_filter: | |||
if filter_[0] not in supported_filters: | |||
if verbose: | |||
warn( | |||
logger.warning( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC the warning reports an error that the application developer should correct, so IMO and my understanding of the logging module's documentation it should be a warning (not a logging event), and wether we use logging or not it shouldn't be controlled by the verbose parameter
yeah the "should we use a more systematic and planned approach to this?" was in the back of my mind and hence why I prefer to draft things here to get early feedback. Do you think I should maybe rename the issue #3686 to reflect a potential bigger scope for this?
thanks: will have a look
Agreed
Will look into this as well. |
Closes #3686
Changes proposed in this pull request: