Skip to content

Commit 9053931

Browse files
committed
add timeout to request, if an error is thrown print it. If buffer limit is reached and connection is faulty older messages will be dropped
1 parent b6d7cf9 commit 9053931

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

logdna/configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'CONTENT_TYPE': 'application/json; charset=UTF-8',
33
'DEFAULT_REQUEST_TIMEOUT': 180000,
44
'MS_IN_A_DAY': 86400000,
5-
'MAX_REQUEST_TIMEOUT': 300000,
5+
'MAX_REQUEST_TIMEOUT': 30,
66
'MAX_LINE_LENGTH': 32000,
77
'MAX_INPUT_LENGTH': 32,
88
'FLUSH_INTERVAL': 5,

logdna/logdna.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ def flush(self):
5050
if not self.buf or len(self.buf) < 0:
5151
return
5252
data = {'e': 'ls', 'ls': self.buf}
53-
resp = requests.post(url=defaults['LOGDNA_URL'], json=data, auth=('user', self.token), params={ 'hostname': self.hostname }, stream=True)
54-
# print(self.buf)
55-
self.buf = []
56-
self.bufByteLength = 0
57-
if self.flusher:
58-
self.flusher.cancel()
59-
self.flusher = None
53+
try:
54+
resp = requests.post(url=defaults['LOGDNA_URL'], json=data, auth=('user', self.token), params={ 'hostname': self.hostname }, stream=True, timeout=defaults['MAX_REQUEST_TIMEOUT'])
55+
self.buf = []
56+
self.bufByteLength = 0
57+
if self.flusher:
58+
self.flusher.cancel()
59+
self.flusher = None
60+
except requests.exceptions.RequestException as e:
61+
print e
6062

6163
def emit(self, record):
6264
record = record.__dict__

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
setup(
33
name = 'logdna',
44
packages = ['logdna'],
5-
version = '1.0.4',
5+
version = '1.0.6',
66
description = 'A python package for sending logs to LogDNA',
77
author = 'Answerbook Inc.',
88
author_email = 'help@logdna.com',
99
url = 'https://github.com/logdna/python',
10-
download_url = 'https://github.com/logdna/python/tarball/1.0.3',
10+
download_url = 'https://github.com/logdna/python/tarball/1.0.6',
1111
keywords = ['logdna', 'logging', 'logs', 'python', 'logdna.com', 'logger'],
1212
install_requires=[
1313
'requests',

0 commit comments

Comments
 (0)