Skip to content

Commit

Permalink
ensure that LogDNA module recovers after internet reconnects
Browse files Browse the repository at this point in the history
respectus committed Sep 12, 2017
1 parent 20b2ecc commit 23e7044
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions logdna/logdna.py
Original file line number Diff line number Diff line change
@@ -77,9 +77,13 @@ def flush(self):
self.buf = self.buf + self.secondary;
self.secondary = [];
except requests.exceptions.RequestException as e:
if self.flusher:
self.flusher.cancel()
self.flusher = None
self.lock.release();
logger.error('Error in request to LogDNA: ' + str(e))


def emit(self, record):
msg = self.format(record)
record = record.__dict__
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@
setup(
name = 'logdna',
packages = ['logdna'],
version = '1.1.2',
version = '1.1.4',
description = 'A python package for sending logs to LogDNA',
author = 'Answerbook Inc.',
author_email = '[email protected]',
url = 'https://github.com/logdna/python',
download_url = 'https://github.com/logdna/python/tarball/1.1.2',
download_url = 'https://github.com/logdna/python/tarball/1.1.4',
keywords = ['logdna', 'logging', 'logs', 'python', 'logdna.com', 'logger'],
install_requires=[
'requests',
23 changes: 17 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
@@ -5,8 +5,9 @@
import logging
import timeit
import sys
import time

from logdna import LogDNAHandler
from logdna.logdna import LogDNAHandler

# from guppy import hpy
# h = hpy()
@@ -24,10 +25,20 @@

# Lines will be in order upon refresh
def timeThis():
for x in range(100):
log.info('DINGLEBOP ' + str(x))
log.info('%s before you %s', 'Look', 'Leap')

print (timeit.timeit(timeThis, number=2))
for x in range(7):
log.info('GORPGORP ' + str(x))
#log.info('%s before you %s', 'Look', 'Leap')

def main_loop():
while 1:
print (timeit.timeit(timeThis, number=2))
time.sleep(10)

if __name__ == '__main__':
try:
main_loop()
except KeyboardInterrupt:
print >> sys.stderr, '\nExiting by user request.\n'
sys.exit(0)

# print h.heap()

0 comments on commit 23e7044

Please sign in to comment.