Files
dify-plugin-sdks/python/dify_plugin/logger_format.py
T
2024-08-30 12:16:09 +08:00

23 lines
607 B
Python

import json
import logging
import sys
class DifyPluginLoggerFormatter(logging.Formatter):
def format(self, record: logging.LogRecord) -> str:
return json.dumps(
{
"event": "log",
"data": {
"level": record.levelname,
"message": record.getMessage(),
"timestamp": record.created,
},
}
)
plugin_logger_handler = logging.StreamHandler(sys.stdout)
plugin_logger_handler.setLevel(logging.INFO)
plugin_logger_handler.setFormatter(DifyPluginLoggerFormatter())