Skip to content

Commit

Permalink
chore: raise_e optional support in LogstashHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Apr 23, 2024
1 parent c9e283b commit 84b31c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

*
* Optional `raise_e` support in `LogstashHandler`

### Fixed

Expand Down
11 changes: 7 additions & 4 deletions src/netius/base/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def is_ready(cls):
return False
return True

def emit(self, record):
def emit(self, record, raise_e=False):
from . import common

# verifies if the API structure is defined and set and if
Expand Down Expand Up @@ -145,9 +145,12 @@ def emit(self, record):
should_flush = len(self.messages) >= self.max_length
should_flush = should_flush or time.time() - self._last_flush > self.timeout
if should_flush:
self.flush()
try:
self.flush(raise_e=raise_e)
except Exception:
if raise_e: raise

def flush(self, force=False):
def flush(self, force=False, raise_e=False):
logging.Handler.flush(self)

# verifies if the API structure is defined and set and if
Expand All @@ -163,7 +166,7 @@ def flush(self, force=False):

# posts the complete set of messages to logstash and then clears the messages
# and updates the last flush time
self.api.log_bulk(messages, tag="default")
self.api.log_bulk(messages, tag="default", raise_e=raise_e)
self.messages = []
self.last_flush = time.time()

Expand Down

0 comments on commit 84b31c6

Please sign in to comment.