Browse Source

Retry sending to logz.io

opensearch
Roi Rav-Hon 8 years ago
parent
commit
ffc5191e40
2 changed files with 13 additions and 11 deletions
  1. +12
    -10
      logzio/handler.py
  2. +1
    -1
      setup.py

+ 12
- 10
logzio/handler.py View File

@ -155,24 +155,27 @@ class LogzioHandler(logging.Handler):
self.buffer_event.set() self.buffer_event.set()
# Not configurable from the outside # Not configurable from the outside
sleep_between_retries = 2000
sleep_between_retries = 2
number_of_retries = 4 number_of_retries = 4
success_in_send = False success_in_send = False
headers = {"Content-type": "text/plain"} headers = {"Content-type": "text/plain"}
for current_try in range(number_of_retries): for current_try in range(number_of_retries):
response = requests.post(self.url, headers=headers, data='\n'.join(temp_logs))
try:
response = requests.post(self.url, headers=headers, data='\n'.join(temp_logs))
if response.status_code != 200: # 429 400, on 400 print stdout
if response.status_code == 400:
if response.status_code != 200: # 429 400, on 400 print stdout
if response.status_code == 400:
print("Got unexpected 400 code from logz.io, response: {0}".format(response.text))
self.backup_logs(temp_logs)
print("Got unexpected 400 code from logz.io, response: {0}".format(response.text))
self.backup_logs(temp_logs)
if response.status_code == 401:
print("You are not authorized with logz.io! dropping..")
break
if response.status_code == 401:
print("You are not authorized with logz.io! dropping..")
break
except Exception as e:
print("Got exception while sending logs to Logz.io, Try ({}/{}). Message: {}".format(current_try + 1, number_of_retries, e.message))
sleep(sleep_between_retries) sleep(sleep_between_retries)
sleep_between_retries *= 2 sleep_between_retries *= 2
@ -181,7 +184,6 @@ class LogzioHandler(logging.Handler):
break break
if not success_in_send: if not success_in_send:
# Write to file # Write to file
self.backup_logs(temp_logs) self.backup_logs(temp_logs)


+ 1
- 1
setup.py View File

@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup( setup(
name="logzio-python-handler", name="logzio-python-handler",
version='1.0.4',
version='1.0.5',
description="Logging handler to send logs to your Logz.io account with bulk SSL", description="Logging handler to send logs to your Logz.io account with bulk SSL",
keywords="logging handler logz.io bulk https", keywords="logging handler logz.io bulk https",
author="roiravhon", author="roiravhon",


Loading…
Cancel
Save