Skip to content

Commit

Permalink
Fixes #182
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Apr 28, 2022
1 parent 33261cd commit 6295280
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Changelog

## [Unreleased]
### Fixed
- Issue [#182](https://github.com/reportportal/client-Python/issues/182): logger crash on attachments, by @HardNorth

## [5.2.1]
### Fixed
- Issue [#180](https://github.com/reportportal/client-Python/issues/180):
logger crash on attachments, by @HardNorth
- Issue [#180](https://github.com/reportportal/client-Python/issues/180): logger crash on attachments, by @HardNorth
### Changed
- Log processing does not stop on the first error now, by @HardNorth

Expand Down
17 changes: 9 additions & 8 deletions reportportal_client/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def emit(self, record):
Emit function.
:param record: a log Record of requests
:return: log ID
"""
msg = ''

Expand All @@ -152,10 +151,12 @@ def emit(self, record):
for level in self._sorted_levelnos:
if level <= record.levelno:
rp_client = current()
return rp_client.log(
timestamp(),
msg,
level=self._loglevel_map[level],
attachment=getattr(record, 'attachment'),
item_id=rp_client.current_item()
)
if rp_client:
rp_client.log(
timestamp(),
msg,
level=self._loglevel_map[level],
attachment=getattr(record, 'attachment'),
item_id=rp_client.current_item()
)
return
3 changes: 1 addition & 2 deletions reportportal_client/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ def log(self, time, message, level=None, attachment=None, item_id=None):
:param level:
:param attachment: files
:param item_id: id of item
:return: id of item from response
"""
data = {
"launchUuid": self.launch_id,
Expand All @@ -509,7 +508,7 @@ def log(self, time, message, level=None, attachment=None, item_id=None):
data["itemUuid"] = item_id
if attachment:
data["attachment"] = attachment
return self._log_batch(data)
self._log_batch(data)

def _log_batch(self, log_data, force=False):
"""
Expand Down
12 changes: 12 additions & 0 deletions tests/logs/test_rp_log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,15 @@ def test_emit_custom_level(mocked_handle):
assert mock_client.log.call_count == 1
call_kwargs = mock_client.log.call_args[1]
assert call_kwargs['level'] == 'WARN'


@mock.patch('reportportal_client.logs.logging.Logger.handle')
def test_emit_null_client_no_error(mocked_handle):
test_message = 'test message'
RPLogger('test_logger').log(30, test_message)
record = mocked_handle.call_args[0][0]

set_current(None)

log_handler = RPLogHandler()
log_handler.emit(record)

0 comments on commit 6295280

Please sign in to comment.