Opened 6 months ago

Closed 6 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:
Author:

Description

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'
        <stdin>:2:<module>
        /home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_logger.py:178:failure
        /home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_logger.py:132:emit
        --- <exception caught here> ---
        /home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_observer.py:131:__call__
        /home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_file.py:50:__call__
        /home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_json.py:248:<lambda>
        /home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_json.py:199:eventAsJSON
        /home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_flatten.py:87:flattenEvent
        /usr/lib/python2.7/string.py:635:parse
        ]
        Traceback (most recent call last):
          File "<stdin>", line 2, in <module>
            
          File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_logger.py", line 178, in failure
            self.emit(level, format, log_failure=failure, **kwargs)
          File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_logger.py", line 132, in emit
            self.observer(event)
        --- <exception caught here> ---
          File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_observer.py", line 131, in __call__
            observer(event)
          File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_file.py", line 50, in __call__
            text = self.formatEvent(event)
          File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_json.py", line 248, in <lambda>
            lambda event: u"{0}{1}\n".format(recordSeparator, eventAsJSON(event))
          File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_json.py", line 199, in eventAsJSON
            flattenEvent(event)
          File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/logger/_flatten.py", line 87, in flattenEvent
            aFormatter.parse(event["log_format"])
          File "/usr/lib/python2.7/string.py", line 635, in parse
            return format_string._formatter_parser()
        exceptions.AttributeError: 'NoneType' object has no attribute '_formatter_parser'

Change History (3)

comment:1 Changed 6 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 6 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.