U vâ’i£ã@s.dZddlZddlmZGdd„dejƒZdS)z3Use the influxdb_client with python native logging.éN)ÚInfluxDBClientcs€eZdZdZee i¡j ¡ƒdgZ dddœ‡fdd„ Z dd„Z dd œ‡fd d „ Z ej dd œd d„Zej ed œdd„Z‡ZS)ÚInfluxLoggingHandlerz² InfluxLoggingHandler instances dispatch logging events to influx. There is no need to set a Formatter. The raw input will be passed on to the influx write api. ÚmessageN)Ú client_argsÚwrite_api_argscs\tƒ ¡||_|dkrin|}tf|||dœ|—Ž|_|dkrDin|}|jjf|Ž|_dS)zË Initialize defaults. The arguments `client_args` and `write_api_args` can be dicts of kwargs. They are passed on to the InfluxDBClient and write_api calls respectively. N)ÚurlÚtokenÚorg)ÚsuperÚ__init__ÚbucketrÚclientÚ write_api)Úselfrrr r rr©Ú __class__©úW/opt/alt/python38/lib/python3.8/site-packages/influxdb_client/client/logging_handler.pyr s  zInfluxLoggingHandler.__init__cCs | ¡dS)z#Make sure all resources are closed.N)Úclose©rrrrÚ__del__"szInfluxLoggingHandler.__del__)Úreturncs"|j ¡|j ¡tƒ ¡dS)z'Close the write_api, client and logger.N)rrr r rrrrr&s  zInfluxLoggingHandler.close)Úrecordrc Csjz,| |¡}| |¡}|jjfd|i|—ŽWSttfk rF‚Yn tfk rd| |¡YnXdS)z(Emit a record via the influxDB WriteApi.rN)ÚformatÚ_get_extra_valuesrÚwriteÚKeyboardInterruptÚ SystemExitÚ ExceptionÚ handleError)rrrÚextrarrrÚemit,s  zInfluxLoggingHandler.emitcs,dˆji}| ‡fdd„|j ¡Dƒ¡|S)z’ Extract all items from the record that were injected via extra. Example: `logging.debug(msg, extra={key: value, ...})`. r cs i|]\}}|ˆjkr||“qSr)ÚDEFAULT_LOG_RECORD_KEYS)Ú.0ÚkeyÚvaluerrrÚ >s ÿz:InfluxLoggingHandler._get_extra_values..)r ÚupdateÚ__dict__Úitems)rrr rrrr7s z&InfluxLoggingHandler._get_extra_values)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚlistÚloggingÚ makeLogRecordr(Úkeysr"r rrÚ LogRecordr!ÚdictrÚ __classcell__rrrrrs r)r-r/Zinfluxdb_clientrÚHandlerrrrrrÚs