Skip to content

Commit cd18e87

Browse files
committed
Fix for #322
1 parent 243867b commit cd18e87

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ target/
7272
.python-version
7373

7474
# virtualenv
75-
venv/
76-
.venv/
75+
venv*/
76+
?venv*/
7777

7878
# pycharm
7979
.idea/

reportportal_client/logs/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, name, level=0):
3535
super(RPLogger, self).__init__(name, level=level)
3636

3737
def _log(self, level, msg, args,
38-
exc_info=None, extra=None, stack_info=False, attachment=None):
38+
exc_info=None, extra=None, stack_info=False, attachment=None, **kwargs):
3939
"""
4040
Low-level logging routine which creates a LogRecord and then calls.
4141
@@ -59,7 +59,10 @@ def _log(self, level, msg, args,
5959
# and returns 3 elements
6060
fn, lno, func = self.findCaller()
6161
else:
62-
fn, lno, func, sinfo = self.findCaller(stack_info)
62+
if 'stacklevel' in kwargs:
63+
fn, lno, func, sinfo = self.findCaller(stack_info, kwargs['stacklevel'])
64+
else:
65+
fn, lno, func, sinfo = self.findCaller(stack_info)
6366

6467
except ValueError: # pragma: no cover
6568
fn, lno, func = '(unknown file)', 0, '(unknown function)'

tests/logs/test_rp_logger.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License
13+
import sys
1314
import logging
15+
import inspect
1416
from logging import LogRecord
1517

1618
import pytest
@@ -65,3 +67,12 @@ def test_log_level_filter(handler_level, log_level, expected_calls):
6567
getattr(logger, log_level)('test_log')
6668

6769
assert mock_client.log.call_count == expected_calls
70+
71+
72+
@pytest.skipif(sys.version_info < (3, 8), '"stacklevel" introduced in Python 3.8, so not actual for earlier versions')
73+
@mock.patch('reportportal_client.logs.logging.Logger.handle')
74+
def test_stacklevel_record_make(logger_handler):
75+
logger = RPLogger('test_logger')
76+
logger.error('test_log', exc_info=RuntimeError('test'), stack_info=inspect.stack(), stacklevel=2)
77+
record = verify_record(logger_handler)
78+
assert record.stack_info.endswith('return func(*newargs, **newkeywargs)')

0 commit comments

Comments
 (0)