mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-22 10:25:23 -04:00
21 lines
605 B
Python
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()) |