From f923cd2c50fe4e66622776d993535ab8332d596c Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 15 Apr 2018 21:55:08 +0300 Subject: [PATCH] Replace print with logging --- README.md | 20 ++++++++++++++++++++ pylast/__init__.py | 6 +++++- tests/test_track.py | 1 - 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f50cc15..31b717c 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/pylast/__init__.py b/pylast/__init__.py index 3b9b0c1..839f6a5 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -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 = {} diff --git a/tests/test_track.py b/tests/test_track.py index efa0812..bb34f56 100755 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -140,7 +140,6 @@ class TestPyLastTrack(PyLastTestCase): # Act album = track.get_album() - print(album) # Assert self.assertEqual(str(album), "Nirvana - Nevermind")