After moving machines and updating things, I noticed that when I use Spotipy it breaks any sort of logging that I've been doing. This is basic example where if I don't import Spotipy, everything works as expected, but if I do it does not log. This is in Python 3.8.2
```python
import logging
import spotipy
logging.basicConfig(level=logging.DEBUG)
mylogger = logging.getLogger(__name__)
handler = logging.FileHandler('test.log', mode='w')
formatter = logging.Formatter('''%(asctime)s -
%(name)s - %(levelname)s - %(message)s''')
handler.setFormatter(formatter)
mylogger.addHandler(handler)
mylogger.info('test')```
It seems the regression was caused in c6de8dc7131e5165b5d9cf2c266444a6f2b6c68d. I'm not sure why this change would break logging.
It looks like external scripts are unable to override this logging configuration which has once been set in spotipy.
I will have a look this week. I initially added https://github.com/plamere/spotipy/commit/c6de8dc7131e5165b5d9cf2c266444a6f2b6c68d because tests were failing. Perhaps I should just have added logging.basicConfig() in the tests rather than in the code? The thing is that it should also work for anyone without specifying logging.basicConfig() in their code
I was just about to file a bug about this, but generally libraries should not initialize the logging system. That should be left to the underlying application that is using the library. Libraries like requests and psycopg2 follow this pattern.
As far as tests failing, the tests seemed to have been passing when I submitted the work for my PR to add the logging here. So if they were breaking it might have been something else that was added with later changes. But I just pulled down the latest code down and the tests seem to pass. Should be safe to remove.
Alright I found that this error only happens with python2
test_track_bad_id (integration.test_user_endpoints.SpotipyLibraryApiTests) ... No handlers could be found for logger "spotipy.client"
ok
but it's all good with python3
test_track_bad_id (integration.test_user_endpoints.SpotipyLibraryApiTests) ... HTTP Error for GET to https://api.spotify.com/v1/tracks/BadID123 returned 400 due to invalid id
ok
So let's not worry about it unless someone complains about it. I'm going to merge your PR now @Beahmer89, thanks for that! also thanks for reporting @zambam5
Released in 2.12.0, @zambam5 feel free to upgrade
huh, thats crazy that that only happens in python2. Interesting find @stephanebruckert! I was only running my tests in python3, but will have to mess around with a python2.7 env.