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

21 lines
605 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())