Browse Source

Merge pull request #8 from johnraz/Fix-issue-7

Fix #7 Return formatted message if format string
opensearch
Roi Rav-Hon 7 years ago
committed by GitHub
parent
commit
d127a5bd6a
2 changed files with 29 additions and 1 deletions
  1. +1
    -1
      logzio/handler.py
  2. +28
    -0
      tests/test_logzioHandler.py

+ 1
- 1
logzio/handler.py View File

@ -39,7 +39,7 @@ class LogzioHandler(logging.Handler):
"path_name": message.pathname,
"log_level": message.levelname,
"type": self.logzio_type,
"message": message.msg,
"message": message.getMessage(),
"@timestamp": timestamp
}


+ 28
- 0
tests/test_logzioHandler.py View File

@ -77,6 +77,34 @@ class TestLogzioHandler(TestCase):
}
)
def test_format_string_message(self):
record = logging.LogRecord(
name='my-logger',
level=0,
pathname='handler_test.py',
lineno=10,
msg="this is a test: %s.",
args=('moo',),
exc_info=None,
func='test_json'
)
formatted_message = self.handler.format_message(record)
formatted_message["@timestamp"] = None
self.assertDictEqual(
formatted_message,
{
'@timestamp': None,
'line_number': 10,
'log_level': 'NOTSET',
'logger': 'my-logger',
'message': 'this is a test: moo.',
'path_name': 'handler_test.py',
'type': 'python'
}
)
def test_exc(self):
try:
raise ValueError("oops.")


Loading…
Cancel
Save