Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

refactor #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions logentries/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Size of the internal event queue
QUEUE_SIZE = 32768
# Logentries API server address
LE_API_DEFAULT = "data.logentries.com"
LE_API_DEFAULT = "logentries.commadotai.com"
# Port number for token logging to Logentries API server
LE_PORT_DEFAULT = 80
LE_TLS_PORT_DEFAULT = 443
Expand Down Expand Up @@ -189,7 +189,7 @@ def flush(self):
if time.time() - now > self.timeout:
break

def emit(self, record):
def emit_raw(self, msg):
if self.good_config and not self._thread.is_alive():
try:
self._thread.start()
Expand All @@ -198,19 +198,21 @@ def emit(self, record):
except RuntimeError: # It's already started.
pass

msg = self.format(record).rstrip('\n')
msg = self.token + msg

try:
self._thread._queue.put_nowait(msg)
except:
except Exception:
# Queue is full, try to remove the oldest message and put again
try:
self._thread._queue.get_nowait()
self._thread._queue.put_nowait(msg)
except:
except Exception:
# Race condition, no need for any action here
pass

def emit(self, record):
msg = self.format(record).rstrip('\n')
self.emit_raw(msg)

def close(self):
logging.Handler.close(self)