severb / graypy

Python logging handler for Graylog that sends messages in GELF (Graylog Extended Log Format).
https://www.graylog.org/
BSD 3-Clause "New" or "Revised" License
258 stars 90 forks source link

Truncate oversized GELFRabbitHandler messages #112

Closed higherorderfunctor closed 4 years ago

higherorderfunctor commented 5 years ago

Is there a recommended way of handling large messages so they are not completely dropped by graylog? I added the following patch, but only having used graylog/GELF for a couple days, I imagine there is a better way to handle this case as it drops all but the base set of fields.

class GELFRabbitHandler(BaseGELFHandler, SocketHandler):
     def makePickle(self, record):
         message_dict = self._make_gelf_dict(record)
         data = json.dumps(message_dict)
         if len(data) > 32766:
             data = json.dumps({
                 'version': message_dict['version'],
                 'host': message_dict['host'],
                 'short_message': 'OVERSIZED_MESSAGE: ' + message_dict['short_message'][:2048],
                 'timestamp': message_dict['timestamp'],
                 'level': message_dict['level'],
                 'facility': message_dict['facility'],
             }, cls=self.serializer)
         return data