diff --git a/logstash_async/constants.py b/logstash_async/constants.py index f04167c..37d0b21 100644 --- a/logstash_async/constants.py +++ b/logstash_async/constants.py @@ -32,11 +32,11 @@ class Constants: # Usually this list does not need to be modified. Add/Remove elements to # exclude/include them in the Logstash event, for the full list see: # http://docs.python.org/library/logging.html#logrecord-attributes - FORMATTER_RECORD_FIELD_SKIP_LIST = [ + FORMATTER_RECORD_FIELD_SKIP_LIST = { 'args', 'asctime', 'created', 'exc_info', 'exc_text', 'filename', 'funcName', 'id', 'levelname', 'levelno', 'lineno', 'module', 'msecs', 'msg', 'name', 'pathname', 'process', - 'processName', 'relativeCreated', 'stack_info', 'thread', 'threadName'] + 'processName', 'relativeCreated', 'stack_info', 'thread', 'threadName'} # fields to be set on the top-level of a Logstash event/message, do not modify this # unless you know what you are doing FORMATTER_LOGSTASH_MESSAGE_FIELD_LIST = [ diff --git a/logstash_async/formatter.py b/logstash_async/formatter.py index 173f7b1..83d2bfa 100644 --- a/logstash_async/formatter.py +++ b/logstash_async/formatter.py @@ -133,7 +133,9 @@ def _format_timestamp(self, time_): # ---------------------------------------------------------------------- def _get_record_fields(self, record): - return {k: self._value_repr(v) for k, v in record.__dict__.items()} + return {k: self._value_repr(v) + for k, v in record.__dict__.items() + if k not in constants.FORMATTER_RECORD_FIELD_SKIP_LIST} # ---------------------------------------------------------------------- def _value_repr(self, value): diff --git a/tests/formatter_test.py b/tests/formatter_test.py index 92a6ae4..1a004c0 100644 --- a/tests/formatter_test.py +++ b/tests/formatter_test.py @@ -29,6 +29,15 @@ def test_format(self): self.assertIsNone(file_handler.exception) + def test_fields_are_excluded_in_get_record_fields(self): + formatter = LogstashFormatter() + log_record = makeLogRecord({ + 'filename': 'foo.py', + 'dummy': 'foobar' + }) + self.assertDictEqual(formatter._get_record_fields(log_record), { + 'dummy': 'foobar' + }) if __name__ == "__main__": unittest.main()