Skip to content

fix: duplicated debug output #521

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

Merged
merged 2 commits into from
Oct 21, 2022
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

### Features
1. [#510](https://github.com/influxdata/influxdb-client-python/pull/510): Allow to use client's optional configs for initialization from file or environment properties
2. [#509](https://github.com/influxdata/influxdb-client-python/pull/509): MTLS support for the InfluxDB Python client
1. [#509](https://github.com/influxdata/influxdb-client-python/pull/509): MTLS support for the InfluxDB Python client

### Bug Fixes
1. [#512](https://github.com/influxdata/influxdb-client-python/pull/512): Exception propagation for asynchronous `QueryApi` [async/await]
1. [#518](https://github.com/influxdata/influxdb-client-python/pull/518): Parsing query response with two-bytes UTF-8 character [async/await]
1. [#521](https://github.com/influxdata/influxdb-client-python/pull/521): Duplicated `debug` output

## 1.33.0 [2022-09-29]

Expand Down
5 changes: 4 additions & 1 deletion influxdb_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def debug(self, value):
for name, logger in self.loggers.items():
logger.setLevel(logging.DEBUG)
if name == 'influxdb_client.client.http':
logger.addHandler(logging.StreamHandler(sys.stdout))
# makes sure to do not duplicate stdout handler
if not any(map(lambda h: isinstance(h, logging.StreamHandler) and h.stream == sys.stdout,
logger.handlers)):
logger.addHandler(logging.StreamHandler(sys.stdout))
# we use 'influxdb_client.client.http' logger instead of this
# httplib.HTTPConnection.debuglevel = 1
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_InfluxDBClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ def test_redacted_auth_header(self):

self.assertIn("Authorization: ***", log_stream.getvalue())

def test_duplicate_debug_logging_handler(self):
logging.getLogger('influxdb_client.client.http').handlers.clear()
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
logger = logging.getLogger('influxdb_client.client.http')
self.assertEqual(1, len(logger.handlers))

def test_custom_debug_logging_handler(self):
logging.getLogger('influxdb_client.client.http').addHandler(logging.FileHandler('logs.log'))
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
logger = logging.getLogger('influxdb_client.client.http')
self.assertEqual(2, len(logger.handlers))


class ServerWithSelfSingedSSL(http.server.SimpleHTTPRequestHandler):
def _set_headers(self):
Expand Down