Skip to content

Commit 00fadcb

Browse files
committed
Used module-specific logger in splunklib code instead of root logger
1 parent 56c108b commit 00fadcb

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

splunklib/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@
1616

1717
from __future__ import absolute_import
1818
from splunklib.six.moves import map
19+
import logging
20+
21+
# To enable debug logs, set the level to 'logging.DEBUG'
22+
logging.basicConfig(level=logging.WARNING)
23+
1924
__version_info__ = (1, 6, 18)
2025
__version__ = ".".join(map(str, __version_info__))

splunklib/binding.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
except ImportError as e:
4848
from xml.parsers.expat import ExpatError as ParseError
4949

50+
logger = logging.getLogger(__name__)
5051

5152
__all__ = [
5253
"AuthenticationError",
@@ -68,7 +69,7 @@ def new_f(*args, **kwargs):
6869
start_time = datetime.now()
6970
val = f(*args, **kwargs)
7071
end_time = datetime.now()
71-
logging.debug("Operation took %s", end_time-start_time)
72+
logger.debug("Operation took %s", end_time-start_time)
7273
return val
7374
return new_f
7475

@@ -616,7 +617,7 @@ def delete(self, path_segment, owner=None, app=None, sharing=None, **query):
616617
"""
617618
path = self.authority + self._abspath(path_segment, owner=owner,
618619
app=app, sharing=sharing)
619-
logging.debug("DELETE request to %s (body: %s)", path, repr(query))
620+
logger.debug("DELETE request to %s (body: %s)", path, repr(query))
620621
response = self.http.delete(path, self._auth_headers, **query)
621622
return response
622623

@@ -679,7 +680,7 @@ def get(self, path_segment, owner=None, app=None, headers=None, sharing=None, **
679680

680681
path = self.authority + self._abspath(path_segment, owner=owner,
681682
app=app, sharing=sharing)
682-
logging.debug("GET request to %s (body: %s)", path, repr(query))
683+
logger.debug("GET request to %s (body: %s)", path, repr(query))
683684
all_headers = headers + self.additional_headers + self._auth_headers
684685
response = self.http.get(path, all_headers, **query)
685686
return response
@@ -757,7 +758,7 @@ def post(self, path_segment, owner=None, app=None, sharing=None, headers=None, *
757758
headers = []
758759

759760
path = self.authority + self._abspath(path_segment, owner=owner, app=app, sharing=sharing)
760-
logging.debug("POST request to %s (body: %s)", path, repr(query))
761+
logger.debug("POST request to %s (body: %s)", path, repr(query))
761762
all_headers = headers + self.additional_headers + self._auth_headers
762763
response = self.http.post(path, all_headers, **query)
763764
return response
@@ -826,7 +827,7 @@ def request(self, path_segment, method="GET", headers=None, body={},
826827
app=app, sharing=sharing)
827828

828829
all_headers = headers + self.additional_headers + self._auth_headers
829-
logging.debug("%s request to %s (headers: %s, body: %s)",
830+
logger.debug("%s request to %s (headers: %s, body: %s)",
830831
method, path, str(all_headers), repr(body))
831832

832833
if body:

splunklib/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
namespace)
7676
from .data import record
7777

78+
logger = logging.getLogger(__name__)
79+
7880
__all__ = [
7981
"connect",
8082
"NotSupportedError",
@@ -1476,7 +1478,7 @@ def iter(self, offset=0, count=None, pagesize=None, **kwargs):
14761478
if pagesize is None or N < pagesize:
14771479
break
14781480
offset += N
1479-
logging.debug("pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s", pagesize, fetched, offset, N, kwargs)
1481+
logger.debug("pagesize=%d, fetched=%d, offset=%d, N=%d, kwargs=%s", pagesize, fetched, offset, N, kwargs)
14801482

14811483
# kwargs: count, offset, search, sort_dir, sort_key, sort_mode
14821484
def list(self, count=None, **kwargs):
@@ -2545,9 +2547,9 @@ def list(self, *kinds, **kwargs):
25452547
kinds = self.kinds
25462548
if len(kinds) == 1:
25472549
kind = kinds[0]
2548-
logging.debug("Inputs.list taking short circuit branch for single kind.")
2550+
logger.debug("Inputs.list taking short circuit branch for single kind.")
25492551
path = self.kindpath(kind)
2550-
logging.debug("Path for inputs: %s", path)
2552+
logger.debug("Path for inputs: %s", path)
25512553
try:
25522554
path = UrlEncoded(path, skip_encode=True)
25532555
response = self.get(path, **kwargs)

0 commit comments

Comments
 (0)