def _log_stats(self, request, options, error=None):

        # def args_to_unicode(args):
        #     unicode_args = {}
        #     for key, val in args.items():
        #         key = to_unicode(key)
        #         if isinstance(val, list):
        #             val = [args_to_unicode(item)item.decode('utf-8') for item in val]
        #         else:
        #             val = val.decode('utf-8')
        #         unicode_args[key] = val
        #         return unicode_args

        msg = {
            # Anything we retrieve from Twisted request object contains bytes.
            # We have to convert it to unicode first for json.dump to succeed.
            "path": request.path.decode('utf-8'),
            "rendertime": request.starttime - time.time(),
            "maxrss": resource.getrusage(resource.RUSAGE_SELF).ru_maxrss,
            "load": os.getloadavg(),
            "fds": get_num_fds(),
            "active": len(self.pool.active),
            "qsize": len(self.pool.queue.pending),
            "_id": id(request),
            "method": request.method.decode('ascii'),
            "timestamp": int(time.time()),
            "user-agent": (request.getHeader(b"user-agent").decode('utf-8')
                           if request.getHeader(b"user-agent") else None),
            "args": options,
            "status_code": request.code,
            "client_ip": request.client.host
        }
        if error:
            msg["error"] = error
        msg = json.dumps(msg).encode("utf8")
        log.msg(msg, system="events")
dataset/ETHPy150Open scrapinghub/splash/splash/resources.py/BaseRenderResource._log_stats/swapped operands of `-`