Replace print with logging

This commit is contained in:
Hugo 2018-04-15 21:55:08 +03:00
parent cef02d0700
commit f923cd2c50
3 changed files with 25 additions and 2 deletions

View file

@ -115,3 +115,23 @@ coverage report # for command-line report
coverage html # for HTML report
open htmlcov/index.html
```
Logging
-------
To enable from your own code:
```python
import logging
import pylast
logging.basicConfig(level=logging.DEBUG)
network = pylast.LastFMNetwork(...)
```
To enable from pytest:
```sh
pytest -k test_album_search_images --log-cli-level debug
```

View file

@ -23,6 +23,7 @@
from xml.dom import minidom, Node
import collections
import hashlib
import logging
import shelve
import six
import ssl
@ -110,6 +111,9 @@ SCROBBLE_MODE_SKIPPED = "S"
# Python >3.4 and >2.7.9 has sane defaults
SSL_CONTEXT = ssl.create_default_context()
logger = logging.getLogger(__name__)
logging.getLogger(__name__).addHandler(logging.NullHandler())
class _Network(object):
"""
@ -732,7 +736,7 @@ class _Request(object):
"""Representing an abstract web service operation."""
def __init__(self, network, method_name, params=None):
print(method_name)
logger.debug(method_name)
if params is None:
params = {}

View file

@ -140,7 +140,6 @@ class TestPyLastTrack(PyLastTestCase):
# Act
album = track.get_album()
print(album)
# Assert
self.assertEqual(str(album), "Nirvana - Nevermind")