Opened 9 months ago

Closed 9 months ago

#9163 enhancement closed duplicate (duplicate)

flattenEvent should handle a None format

Reported by: Wilfredo Sánchez Vega Owned by:
Priority: highest Milestone:
Component: logger Keywords:
Cc: Branch:


flattenEvent will raise if the "log_format" key in the even it is given is None.

formatEvent has code to handle a None format, so it's at least legal there, and raising an exception in an observer is quite problematic, so flattenEvent needs to not blow up.

Here's an example of this failing from exarkun:

2017-06-06T15:14:03-0400 [twisted.logger._observer#critical] Temporarily disabling observer <twisted.logger._file.FileLogObserver object at 0x7f8555ba0a10> due to exception: [Failure instance: Traceback: <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute '_formatter_parser'
        --- <exception caught here> ---
        Traceback (most recent call last):
          File "<stdin>", line 2, in <module>
          File "/home/exarkun/Environments/", line 178, in failure
            self.emit(level, format, log_failure=failure, **kwargs)
          File "/home/exarkun/Environments/", line 132, in emit
        --- <exception caught here> ---
          File "/home/exarkun/Environments/", line 131, in __call__
          File "/home/exarkun/Environments/", line 50, in __call__
            text = self.formatEvent(event)
          File "/home/exarkun/Environments/", line 248, in <lambda>
            lambda event: u"{0}{1}\n".format(recordSeparator, eventAsJSON(event))
          File "/home/exarkun/Environments/", line 199, in eventAsJSON
          File "/home/exarkun/Environments/", line 87, in flattenEvent
          File "/usr/lib/python2.7/", line 635, in parse
            return format_string._formatter_parser()
        exceptions.AttributeError: 'NoneType' object has no attribute '_formatter_parser'

Change History (3)

comment:1 Changed 9 months ago by Wilfredo Sánchez Vega

Hrm, actually, test_flattenEventWithNoneFormat tests already for and that passes…

flattenEvent returns right away if if event.get("log_format", None) is None (line 76).

So I'm confused about how in line 87, the same key in the same event is None.

comment:3 Changed 9 months ago by Wilfredo Sánchez Vega

Resolution: duplicate
Status: newclosed

Never mind, this was a bug in 16.6.0 and has since been fixed.

Note: See TracTickets for help on using tickets.