mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
feat: 引入 Logger 接口抽象,支持自定义日志实现
- 新增 Logger 接口定义,支持 zap/slog 等自定义实现 - 新增 CloserLogger 接口用于支持关闭操作 - Engine 新增 SetLogger/GetLogger 方法使用接口 - 新增 compat.go 兼容层,保留 reco 兼容方法 - 新增 slog 适配器示例 - 删除 zap 示例 - Context.GetLogger() 返回接口类型
This commit is contained in:
parent
58fd877ae2
commit
c8b14ef43a
7 changed files with 575 additions and 17 deletions
37
compat.go
Normal file
37
compat.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
// Copyright 2024 WJQSERVER. All rights reserved.
|
||||
// All rights reserved by WJQSERVER, related rights can be exercised by the infinite-iroha organization.
|
||||
package touka
|
||||
|
||||
import "github.com/fenthope/reco"
|
||||
|
||||
// GetLogReco 返回底层的 reco.Logger 实例
|
||||
// 用于需要访问 reco 特定功能的场景
|
||||
// 如果当前 logger 不是 *reco.Logger 类型,返回 nil
|
||||
//
|
||||
//go:fix inline
|
||||
func (engine *Engine) GetLogReco() *reco.Logger {
|
||||
return engine.LogReco
|
||||
}
|
||||
|
||||
// SetLogReco 设置 reco.Logger 实例
|
||||
// 用于向后兼容,等价于 SetLogger(l)
|
||||
//
|
||||
//go:fix inline
|
||||
func (engine *Engine) SetLogReco(l *reco.Logger) {
|
||||
engine.LogReco = l
|
||||
engine.logger = l
|
||||
}
|
||||
|
||||
// GetLoggerReco 返回底层的 reco.Logger 实例
|
||||
// 用于需要访问 reco 特定功能的场景
|
||||
// 如果当前 logger 不是 *reco.Logger 类型,返回 nil
|
||||
//
|
||||
//go:fix inline
|
||||
func (c *Context) GetLoggerReco() *reco.Logger {
|
||||
if rl, ok := c.engine.logger.(*reco.Logger); ok {
|
||||
return rl
|
||||
}
|
||||
return c.engine.LogReco
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue