Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use module-specific logger in library code instead of root logger #337

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions splunklib/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
except ImportError as e:
from xml.parsers.expat import ExpatError as ParseError

logger = logging.getLogger(__name__)

__all__ = [
"AuthenticationError",
Expand All @@ -70,7 +71,7 @@ def new_f(*args, **kwargs):
start_time = datetime.now()
val = f(*args, **kwargs)
end_time = datetime.now()
logging.debug("Operation took %s", end_time-start_time)
logger.debug("Operation took %s", end_time-start_time)
return val
return new_f

Expand Down Expand Up @@ -618,7 +619,7 @@ def delete(self, path_segment, owner=None, app=None, sharing=None, **query):
"""
path = self.authority + self._abspath(path_segment, owner=owner,
app=app, sharing=sharing)
logging.debug("DELETE request to %s (body: %s)", path, repr(query))
logger.debug("DELETE request to %s (body: %s)", path, repr(query))
response = self.http.delete(path, self._auth_headers, **query)
return response

Expand Down Expand Up @@ -681,7 +682,7 @@ def get(self, path_segment, owner=None, app=None, headers=None, sharing=None, **

path = self.authority + self._abspath(path_segment, owner=owner,
app=app, sharing=sharing)
logging.debug("GET request to %s (body: %s)", path, repr(query))
logger.debug("GET request to %s (body: %s)", path, repr(query))
all_headers = headers + self.additional_headers + self._auth_headers
response = self.http.get(path, all_headers, **query)
return response
Expand Down Expand Up @@ -754,7 +755,7 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *
headers = []

path = self.authority + self._abspath(path_segment, owner=owner, app=app, sharing=sharing)
logging.debug("POST request to %s (body: %s)", path, repr(query))
logger.debug("POST request to %s (body: %s)", path, repr(query))
all_headers = headers + self.additional_headers + self._auth_headers
response = self.http.post(path, all_headers, **query)
return response
Expand Down Expand Up @@ -822,7 +823,7 @@ def request(self, path_segment, method="GET", headers=None, body="",
+ self._abspath(path_segment, owner=owner,
app=app, sharing=sharing)
all_headers = headers + self.additional_headers + self._auth_headers
logging.debug("%s request to %s (headers: %s, body: %s)",
logger.debug("%s request to %s (headers: %s, body: %s)",
method, path, str(all_headers), repr(body))
response = self.http.request(path,
{'method': method,
Expand Down
8 changes: 5 additions & 3 deletions splunklib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
namespace)
from .data import record

logger = logging.getLogger(__name__)

__all__ = [
"connect",
"NotSupportedError",
Expand Down Expand Up @@ -1444,7 +1446,7 @@ def iter(self, offset=0, count=None, pagesize=None, **kwargs):
if pagesize is None or N < pagesize:
break
offset += N
logging.debug("pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s", pagesize, fetched, offset, N, kwargs)
logger.debug("pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s", pagesize, fetched, offset, N, kwargs)

# kwargs: count, offset, search, sort_dir, sort_key, sort_mode
def list(self, count=None, **kwargs):
Expand Down Expand Up @@ -2517,9 +2519,9 @@ def list(self, *kinds, **kwargs):
kinds = self.kinds
if len(kinds) == 1:
kind = kinds[0]
logging.debug("Inputs.list taking short circuit branch for single kind.")
logger.debug("Inputs.list taking short circuit branch for single kind.")
path = self.kindpath(kind)
logging.debug("Path for inputs: %s", path)
logger.debug("Path for inputs: %s", path)
try:
path = UrlEncoded(path, skip_encode=True)
response = self.get(path, **kwargs)
Expand Down
7 changes: 5 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from __future__ import absolute_import
from tests import testlib
import logging
logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler())

import splunklib.client as client

Expand All @@ -37,9 +39,9 @@ def setUp(self):
# than entities like indexes, this is okay.
self.app_name = testlib.tmpname()
self.app = self.service.apps.create(self.app_name)
logging.debug("Creating app %s", self.app_name)
logger.debug("Creating app %s", self.app_name)
else:
logging.debug("App %s already exists. Skipping creation.", self.app_name)
logger.debug("App %s already exists. Skipping creation.", self.app_name)
if self.service.restart_required:
self.service.restart(120)
return
Expand Down Expand Up @@ -94,6 +96,7 @@ def test_delete(self):

def test_package(self):
p = self.app.package()
logger.debug('package(name=%s, path=%s, url=%s)', p.name, p.path, p.url)
self.assertEqual(p.name, self.app_name)
self.assertTrue(p.path.endswith(self.app_name + '.spl'))
self.assertTrue(p.url.endswith(self.app_name + '.spl'))
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ deps = pytest

distdir = build
commands =
{env:TOXBUILD:python -m pytest --junitxml=test-reports/junit-{envname}.xml --cov --cov-config=.coveragerc} {posargs}
{env:TOXBUILD:python -m pytest -s --junitxml=test-reports/junit-{envname}.xml --cov --cov-config=.coveragerc} {posargs}

[testenv:clean]
deps = coverage
Expand Down