Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion sap/cf_logging/record/simple_log_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def format(self):
'msg': self.getMessage(),
})

if self.levelno == logging.ERROR:
if self.levelno == logging.ERROR and self.exc_info:
stacktrace = ''.join(traceback.format_exception(*self.exc_info))
record['stacktrace'] = format_stacktrace(stacktrace)

Expand Down
2 changes: 1 addition & 1 deletion tests/schema_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
IP = r'[[0-9]+|.?]+\d$'
HOST_NAME = r'[[0-9]+|.?]+\d$'

LEVEL = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'NOTSET']
LEVEL = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET']


def num(val=None):
Expand Down
11 changes: 9 additions & 2 deletions tests/test_job_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ def before_each():
cf_logging._SETUP_DONE = False


def test_log_in_expected_format():
@pytest.mark.parametrize('log_callback', [
lambda logger, msg: logger.debug('message: %s', msg),
lambda logger, msg: logger.info('message: %s', msg),
lambda logger, msg: logger.warning('message: %s', msg),
lambda logger, msg: logger.error('message: %s', msg),
lambda logger, msg: logger.critical('message: %s', msg)
])
def test_log_in_expected_format(log_callback):
""" Test the cf_logger as a standalone """
cf_logging.init(level=logging.DEBUG)
logger, stream = config_logger('cli.test')
logger.info('hi')
log_callback(logger, 'hi')
log_json = JSONDecoder().decode(stream.getvalue())
_, error = JsonValidator(JOB_LOG_SCHEMA).validate(log_json)

Expand Down