python中以json格式输出log日志
import json
import logging
import datetime
import socket
class HostIp:
host_name = None
host_ip = None
@classmethod
def get_host_ip(cls):
if not cls.host_name or not HostIp.host_ip:
try:
cls.host_name = socket.gethostname()
cls.host_ip = socket.gethostbyname(cls.host_name)
except ConnectionError:
cls.host_name = "unknown hostname"
cls.host_ip = "unknown ip"
return cls.host_name, cls.host_ip
REMOVE_ATTR = ["filename", "module", "exc_text", "stack_info", "created", "msecs", "relativeCreated", "exc_info", "msg",
"args", "name", "levelname", "levelno", "pathname", "lineno", "funcName", "thread", "threadName",