mirror of
https://github.com/KevinMidboe/transatlanticTorrentExpress.git
synced 2025-12-29 05:11:26 +00:00
Elastic logging handler now dependency free (urllib in favor of requests)
This commit is contained in:
11
logger.py
11
logger.py
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import requests
|
import json
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
LOG_FILE = os.path.join(BASE_DIR, 'output.log')
|
LOG_FILE = os.path.join(BASE_DIR, 'output.log')
|
||||||
@@ -37,8 +38,12 @@ class ESHandler(logging.Handler):
|
|||||||
'@timestamp': int(record.created*1000)
|
'@timestamp': int(record.created*1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = requests.post(indexURL, json=doc, headers={"Content-type": "application/json"})
|
payload = json.dumps(doc).encode('utf8')
|
||||||
return resp.content
|
req = urllib.request.Request(indexURL, data=payload,
|
||||||
|
headers={'content-type': 'application/json'})
|
||||||
|
response = urllib.request.urlopen(req)
|
||||||
|
response = response.read().decode('utf8')
|
||||||
|
return response
|
||||||
|
|
||||||
eh = ESHandler(host='localhost')
|
eh = ESHandler(host='localhost')
|
||||||
eh.setLevel(logging.DEBUG)
|
eh.setLevel(logging.DEBUG)
|
||||||
|
|||||||
Reference in New Issue
Block a user