Skip to content

Commit a645cd3

Browse files
chore: fulfill requirements for PR
1 parent 95f6ba0 commit a645cd3

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44
1. [#412](https://github.com/influxdata/influxdb-client-python/pull/412): `DeleteApi` uses default value from `InfluxDBClient.org` if an `org` parameter is not specified
5+
2. [#405](https://github.com/influxdata/influxdb-client-python/pull/405): Add `InfluxLoggingHandler`. A handler to use the influx client in native python logging.
56

67
### CI
78
1. [#411](https://github.com/influxdata/influxdb-client-python/pull/411): Use new Codecov uploader for reporting code coverage
@@ -45,8 +46,6 @@ This release introduces a support for new version of InfluxDB OSS API definition
4546
1. [#408](https://github.com/influxdata/influxdb-client-python/pull/408): Improve error message when the client cannot find organization by name
4647
1. [#407](https://github.com/influxdata/influxdb-client-python/pull/407): Use `pandas.concat()` instead of deprecated `DataFrame.append()` [DataFrame]
4748

48-
### Features
49-
1. [#405](https://github.com/influxdata/influxdb-client-python/pull/405): Add `InfluxLoggingHandler`. A handler to use the influx client in native python logging.
5049

5150
## 1.25.0 [2022-01-20]
5251

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [import_data_set_sync_batching.py](import_data_set_sync_batching.py) - How to use [RxPY](https://rxpy.readthedocs.io/en/latest/) to prepare batches for synchronous write into InfluxDB
1010
- [write_api_callbacks.py](write_api_callbacks.py) - How to handle batch events
1111
- [write_structured_data.py](write_structured_data.py) - How to write structured data - [NamedTuple](https://docs.python.org/3/library/collections.html#collections.namedtuple), [Data Classes](https://docs.python.org/3/library/dataclasses.html) - (_requires Python v3.8+_)
12+
- [logging_handler.py](logging_handler.py) - How to set up a python native logging handler that writes to influx.
1213

1314
## Queries
1415
- [query.py](query.py) - How to query data into `FluxTable`s, `Stream` and `CSV`

examples/logging_handler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import time
1111

1212
from influxdb_client import InfluxLoggingHandler, WritePrecision, Point
13+
from influxdb_client.client.write_api import SYNCHRONOUS
1314

1415
DATA_LOGGER_NAME = '…'
1516

@@ -20,9 +21,10 @@ def setup_logger():
2021
2122
This can happen in your core module.
2223
"""
23-
influx_logging_handler = InfluxLoggingHandler(url="…", token="…", org="…", bucket="…",
24-
client_args={'arg1': '…'},
25-
write_api_args={'arg': '…'})
24+
influx_logging_handler = InfluxLoggingHandler(
25+
url="http://localhost:8086", token="my-token", org="my-org", bucket="my-bucket",
26+
client_args={'timeout': 30_000}, # optional configuration of the client
27+
write_api_args={'write_options': SYNCHRONOUS}) # optional configuration of the write api
2628
influx_logging_handler.setLevel(logging.DEBUG)
2729

2830
data_logger = logging.getLogger(DATA_LOGGER_NAME)
@@ -45,3 +47,8 @@ def use_logger():
4547
.field('temperature', 25.3)
4648
.time(datetime.datetime.utcnow(), WritePrecision.MS)
4749
)
50+
51+
52+
if __name__ == "__main__":
53+
setup_logger()
54+
use_logger()

influxdb_client/client/write/point.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class Point(object):
5353
Ref: http://bit.ly/influxdata-point
5454
"""
5555

56-
__str___rep = None
57-
5856
@staticmethod
5957
def measurement(measurement):
6058
"""Create a new Point with specified measurement name."""
@@ -201,17 +199,8 @@ def set_str_rep(cls, rep_function):
201199
cls.__str___rep = rep_function
202200

203201
def __str__(self):
204-
"""
205-
Create string representation of this Point.
206-
207-
Can be set via `Point.set_str_rep`. Defaults to `to_line_protocol`
208-
Example:
209-
.. code-block:: python
210-
Point.set_str_rep(lambda p: f'{p._name} - {p._tags} - {p._fields} - {p._time}')
211-
"""
212-
if self.__str___rep is None:
213-
return self.to_line_protocol()
214-
return self.__str___rep()
202+
"""Create string representation of this Point."""
203+
return self.to_line_protocol()
215204

216205

217206
def _append_tags(tags):

tests/test_point.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ class PointTest(unittest.TestCase):
1313

1414
def test_ToStr(self):
1515
point = Point.measurement("h2o").tag("location", "europe").field("level", 2.2)
16-
expected_str = "h2o,location=europe level=2.2"
16+
expected_str = point.to_line_protocol()
1717
self.assertEqual(expected_str, str(point))
1818

19-
def my_str_rep(p: Point) -> str:
20-
return f'{p._name} - {p._tags} - {p._fields} - {p._time}'
21-
22-
Point.set_str_rep(my_str_rep)
23-
24-
self.assertEqual(my_str_rep(point), str(point))
25-
2619
def test_MeasurementEscape(self):
2720
point = Point.measurement("h2 o").tag("location", "europe").tag("", "warn").field("level", 2)
2821
self.assertEqual(point.to_line_protocol(), "h2\\ o,location=europe level=2i")

0 commit comments

Comments
 (0)