refactor(templates):重构模板执行日志记录方式

- 移除对 logging.Logger 的依赖- 使用 fmt.Printf 替代 Debugf 记录模板执行信息- 统一模板执行日志格式- 简化 LayoutTemplateProcessor 结构体定义
This commit is contained in:
2025-11-09 15:38:30 +08:00
parent c310a6b373
commit b228678813
2 changed files with 3 additions and 4 deletions

View File

@@ -1,14 +1,13 @@
package templates
import (
"fmt"
"html/template"
"io"
"platform/logging"
"strings"
)
type LayoutTemplateProcessor struct {
logging.Logger
}
// 定义一个获取模板函数
@@ -23,7 +22,7 @@ func (proc *LayoutTemplateProcessor) ExecTemplate(writer io.Writer, name string,
}
func (proc *LayoutTemplateProcessor) ExecTemplateWithFunc(writer io.Writer, name string, data interface{}, handlerFunc InvokeHandlerFunc) (err error) {
proc.Logger.Debugf("加载模板: %v 参数: %v ", name, data)
fmt.Printf("模板执行开始: %v 模板参数: %v \n", name, data)
var sb strings.Builder
layoutName := ""
// 获取模板列表
@@ -40,8 +39,8 @@ func (proc *LayoutTemplateProcessor) ExecTemplateWithFunc(writer io.Writer, name
// 获取首个模板内容将模板内容写入sb,并调用layout函数设置布局模板名称
err = localTemplates.ExecuteTemplate(&sb, name, data)
if layoutName != "" {
fmt.Printf("模板执行开始: %v 模板参数: %v \n", layoutName, data)
// 通过布局模板加载内容
proc.Logger.Debugf("加载模板: %v 参数: %v ", layoutName, data)
err = localTemplates.ExecuteTemplate(writer, layoutName, data)
} else {
_, err = io.WriteString(writer, sb.String())

Binary file not shown.