refactor: 全面集成 slog 日志到 handler、service、middleware

- cmd/main.go: 集成 logger.Init 和日志中间件,替换标准 log 包
- handler 层: 5xx 错误记录完整日志,返回通用消息(防内部信息泄露)
- service 层: LLM/图片生成/存储/认证等关键操作补充结构化日志
- auth 中间件: 记录认证失败原因
- generate.go: 后台管线任务使用带 task_id 的 logger
This commit is contained in:
2026-05-25 14:31:04 +08:00
parent 681bc8f472
commit 25c11ed649
13 changed files with 159 additions and 39 deletions
+14
View File
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
"gen2d/internal/logger"
"github.com/cloudwego/eino/compose"
)
@@ -82,20 +84,32 @@ func NewGenerateGraph() (*compose.Graph[PipelineInput, PipelineOutput], error) {
// RunPipeline 编译并执行生成管线。
func RunPipeline(ctx context.Context, in PipelineInput) (*PipelineOutput, error) {
l := logger.FromCtx(ctx)
l.Info("pipeline started",
"asset_type", in.AssetType,
"tags", in.Tags,
"resolution", in.Params.Resolution,
)
g, err := NewGenerateGraph()
if err != nil {
l.Error("pipeline create graph failed", "error", err)
return nil, fmt.Errorf("create graph: %w", err)
}
r, err := g.Compile(ctx, compose.WithMaxRunSteps(20))
if err != nil {
l.Error("pipeline compile failed", "error", err)
return nil, fmt.Errorf("compile graph: %w", err)
}
output, err := r.Invoke(ctx, in)
if err != nil {
l.Error("pipeline invoke failed", "error", err)
return nil, fmt.Errorf("invoke pipeline: %w", err)
}
l.Info("pipeline completed", "asset_count", len(output.Assets))
return &output, nil
}