Make elastic logging optional with config flag

This commit is contained in:
2023-08-25 19:30:50 +02:00
parent 948eeb1d31
commit ed2a1d9a53

View File

@@ -74,7 +74,7 @@ class ESHandler(logging.Handler):
return response
except urllib.error.HTTPError as e:
print('Unable to reach elastic, error:', e)
return asdf
return
class ElasticFieldParameterAdapter(logging.LoggerAdapter):
def __init__(self, logger, extra={}):
@@ -93,12 +93,15 @@ esHost = config['ELASTIC']['host']
esPort = config['ELASTIC']['port']
esSSL = config['ELASTIC']['ssl']
esApiKey = config['ELASTIC']['api_key']
eh = ESHandler(host=esHost, port=esPort, ssl=esSSL, apiKey=esApiKey)
eh.setLevel(logging.DEBUG)
esEnabled = config['ELASTIC']['enabled']
if esEnabled == 'True':
eh = ESHandler(host=esHost, port=esPort, ssl=esSSL, apiKey=esApiKey)
eh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s %(levelname)8s | %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
logger.addHandler(eh)
if esEnabled == 'True':
logger.addHandler(eh)
logger = ElasticFieldParameterAdapter(logger)