#625 [backend] encode 'msg' in LogRecord sooner
Merged 5 years ago by frostyx. Opened 5 years ago by praiskup.
Unknown source log-record-msg-encode  into  master

@@ -414,6 +414,12 @@

                  _, error, tb = msg.get("exc_info")

                  msg["traceback"] = format_tb(error, tb)

  

+             # For the message arguments, it is better to expand them right now

+             # instead of relying on method in json.dumps(..., default=default)

+             # and even worse rely on it's reverse action in RedisLogHandler.

+             msg['msg'] = msg['msg'] % msg['args']

+             msg['args'] = ()

+ 

              self.rc.publish(constants.LOG_PUB_SUB, json.dumps(msg, default=default))

          # pylint: disable=W0703

          except Exception as error:

RedisPublishHandler sends serialized LogRecord to RedisLogHandler,
and when the log message and its arguments isn't really carefully
typed - the path through serializer isn't lossless and
RedisLogHandler doesn't have enough information for proper log
entry formatting (when it comes to finally writing to the log
file).

So expand the message arguments rather early (before it is
json.dumps() serialized), when it is much easier to call str
(and friends..) on the objects automatically.

Fix: #488, #621

Based on the meeting discussion, I am merging this.

rebased onto 3d642d7

5 years ago

Pull-Request has been merged by frostyx

5 years ago