Skip to content

Commit db36282

Browse files
chore: add pydocstyle docs
1 parent 9c93dfc commit db36282

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

influxdb_client/client/loggingHandler.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
"""
2-
Use the influxdb_client together with python native logging
3-
"""
1+
"""Use the influxdb_client with python native logging."""
42
import logging
53

64
from influxdb_client import InfluxDBClient
75

86

97
class InfluxLoggingHandler(logging.Handler):
8+
"""
9+
InfluxLoggingHandler instances dispatch logging events to influx.
10+
11+
There is no need to set a Formater.
12+
The raw input will be passed on to the influx write api.
13+
"""
14+
1015
DEFAULT_LOG_RECORD_KEYS = logging.makeLogRecord({}).__dict__.keys()
1116

1217
def __init__(self, *, url, token, org, bucket, client_args=None, write_api_args=None):
18+
"""
19+
Initialize defaults.
20+
21+
The arguments `client_args` and `write_api_args` can be dicts of kwargs.
22+
They are passed on to the InfluxDBClient and write_api calls respectively.
23+
"""
1324
super().__init__()
1425

1526
self.bucket = bucket
@@ -21,15 +32,17 @@ def __init__(self, *, url, token, org, bucket, client_args=None, write_api_args=
2132
self.write_api = self.client.write_api(**write_api_args)
2233

2334
def __del__(self):
35+
"""Make sure all resources are closed."""
2436
self.close()
2537

2638
def close(self) -> None:
39+
"""Close the write_api, client and logger."""
2740
self.write_api.close()
2841
self.client.close()
2942
super().close()
3043

3144
def emit(self, record: logging.LogRecord) -> None:
32-
""" Emit a record via the influxDB WriteApi """
45+
"""Emit a record via the influxDB WriteApi."""
3346
try:
3447
extra = self._get_extra_values(record)
3548
return self.write_api.write(record=record.msg, **extra)
@@ -39,7 +52,11 @@ def emit(self, record: logging.LogRecord) -> None:
3952
self.handleError(record)
4053

4154
def _get_extra_values(self, record: logging.LogRecord) -> dict:
42-
"""extracts all items from the record that were injected by logging.debug(msg, extra={key: value, ...})"""
55+
"""
56+
Extract all items from the record that were injected via extra.
57+
58+
Example: `logging.debug(msg, extra={key: value, ...})`.
59+
"""
4360
extra = {key: value
4461
for key, value in record.__dict__.items() if key not in self.DEFAULT_LOG_RECORD_KEYS}
4562
if 'bucket' not in extra.keys():

0 commit comments

Comments
 (0)