Skip to content

Commit d4f7df9

Browse files
authored
fix: duplicated debug output (influxdata#521)
1 parent fab076c commit d4f7df9

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
### Features
77
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
8-
2. [#509](https://github.com/influxdata/influxdb-client-python/pull/509): MTLS support for the InfluxDB Python client
8+
1. [#509](https://github.com/influxdata/influxdb-client-python/pull/509): MTLS support for the InfluxDB Python client
99

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

1415
## 1.33.0 [2022-09-29]
1516

influxdb_client/configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ def debug(self, value):
171171
for name, logger in self.loggers.items():
172172
logger.setLevel(logging.DEBUG)
173173
if name == 'influxdb_client.client.http':
174-
logger.addHandler(logging.StreamHandler(sys.stdout))
174+
# makes sure to do not duplicate stdout handler
175+
if not any(map(lambda h: isinstance(h, logging.StreamHandler) and h.stream == sys.stdout,
176+
logger.handlers)):
177+
logger.addHandler(logging.StreamHandler(sys.stdout))
175178
# we use 'influxdb_client.client.http' logger instead of this
176179
# httplib.HTTPConnection.debuglevel = 1
177180
else:

tests/test_InfluxDBClient.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,20 @@ def test_redacted_auth_header(self):
391391

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

394+
def test_duplicate_debug_logging_handler(self):
395+
logging.getLogger('influxdb_client.client.http').handlers.clear()
396+
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
397+
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
398+
logger = logging.getLogger('influxdb_client.client.http')
399+
self.assertEqual(1, len(logger.handlers))
400+
401+
def test_custom_debug_logging_handler(self):
402+
logging.getLogger('influxdb_client.client.http').addHandler(logging.FileHandler('logs.log'))
403+
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
404+
self.influxdb_client = InfluxDBClient("http://localhost", "my-token", debug=True)
405+
logger = logging.getLogger('influxdb_client.client.http')
406+
self.assertEqual(2, len(logger.handlers))
407+
394408

395409
class ServerWithSelfSingedSSL(http.server.SimpleHTTPRequestHandler):
396410
def _set_headers(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy