-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to use custom json lib for encoding #12
Comments
@mahenzon Good suggestion. formatter = JsonFormatter(dumps=json.dumps, *args, **kwargs) |
Hi! Yeah, it'll be a good option I can do a PR, but we need to agree on a solution. |
@mahenzon Thank you and welcome to commit PR. |
Sure! Will work on it |
how to modify the default parameters in Django configuaration,like set ensure_ascii=False |
@toplove LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'class': 'jsonformatter.JsonFormatter',
'format': OrderedDict([
("Name", "name"),
("Levelno", "levelno"),
("Levelname", "levelname"),
("Pathname", "pathname"),
("Filename", "filename"),
("Module", "module"),
("Lineno", "lineno"),
("FuncName", "funcName"),
("Created", "created"),
("Asctime", "asctime"),
("Msecs", "msecs"),
("RelativeCreated", "relativeCreated"),
("Thread", "thread"),
("ThreadName", "threadName"),
("Process", "process"),
("Message", "message")
]),
"mix_extra": True,
"ensure_ascii": False,
# the other optional arguments
},
},
'handlers': {
'console': {
'level': 'INFO',
'formatter': 'standard',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False
},
}
} |
thanks for your answer,tried configuration like yours,but don't work it
{"name": "django", "asctime": "2021-08-17 17:56:20,374", "levelname": "INFO", "process": 6372, "processName": "MainProcess", "thread": 24544, "threadName": "ThreadPoolExecutor-0_0", "module": "cmdb_consump", "pathname": "common\cmdb_consump.py", "funcName": "cmdb_consump", "lineno": 57, "message": "cmdb\u67e5\u8be2system_apps,view_ida86de242caad4489bcd8f0375b7eb130\uff0c\u63a5\u53e3\u54cd\u5e94\u65f6\u95f40.5826475620269775\u79d2"} |
@toplove LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'class': 'jsonformatter.JsonFormatter',
'fmt': OrderedDict([
("Name", "name"),
("Levelno", "levelno"),
("Levelname", "levelname"),
("Pathname", "pathname"),
("Filename", "filename"),
("Module", "module"),
("Lineno", "lineno"),
("FuncName", "funcName"),
("Created", "created"),
("Asctime", "asctime"),
("Msecs", "msecs"),
("RelativeCreated", "relativeCreated"),
("Thread", "thread"),
("ThreadName", "threadName"),
("Process", "process"),
("Message", "message")
]),
"mix_extra": True,
"ensure_ascii": False,
# the other optional arguments
},
},
'handlers': {
'console': {
'level': 'INFO',
'formatter': 'standard',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False
},
}
} |
thank you very much! |
Right now builtin json lib is used:
jsonformatter/jsonformatter/jsonformatter.py
Line 12 in a5561e5
jsonformatter/jsonformatter/jsonformatter.py
Line 165 in a5561e5
jsonformatter/jsonformatter/jsonformatter.py
Line 427 in a5561e5
But there're other libs that are faster, for example orjson, ujson, rapidjson, simplejson.. and more. It'll be cool to have an ability to change encoder (for speed and compatibility purposes).
Possible solution to make it flexible:
https://github.com/aiogram/aiogram/blob/dev-2.x/aiogram/utils/json.py
The text was updated successfully, but these errors were encountered: