refactor: centralize logging and update resource initialization

This commit refactors the logging mechanism across the application by replacing direct logger calls with a centralized logging approach using the `common` package. Key changes include:

- Replaced instances of `logger.SysLog` and `logger.FatalLog` with `common.SysLog` and `common.FatalLog` for consistent logging practices.
- Updated resource initialization error handling to utilize the new logging structure, enhancing maintainability and readability.
- Minor adjustments to improve code clarity and organization throughout various modules.

This change aims to streamline logging and improve the overall architecture of the codebase.
This commit is contained in:
CaIon
2025-08-14 21:10:04 +08:00
parent e2037ad756
commit 6748b006b7
101 changed files with 537 additions and 568 deletions

View File

@@ -10,7 +10,6 @@ import (
"one-api/common"
"one-api/constant"
"one-api/dto"
"one-api/logger"
relaycommon "one-api/relay/common"
"one-api/types"
"strings"
@@ -32,9 +31,9 @@ var tokenEncoderMap = make(map[string]tokenizer.Codec)
var tokenEncoderMutex sync.RWMutex
func InitTokenEncoders() {
logger.SysLog("initializing token encoders")
common.SysLog("initializing token encoders")
defaultTokenEncoder = codec.NewCl100kBase()
logger.SysLog("token encoders initialized")
common.SysLog("token encoders initialized")
}
func getTokenEncoder(model string) tokenizer.Codec {
@@ -158,7 +157,7 @@ func getImageToken(fileMeta *types.FileMeta, model string, stream bool) (int, er
if strings.HasPrefix(fileMeta.Data, "http") {
config, format, err = DecodeUrlImageData(fileMeta.Data)
} else {
logger.SysLog(fmt.Sprintf("decoding image"))
common.SysLog(fmt.Sprintf("decoding image"))
config, format, b64str, err = DecodeBase64ImageData(fileMeta.Data)
}
if err != nil {
@@ -248,6 +247,11 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
if meta == nil {
return 0, errors.New("token count meta is nil")
}
if info.RelayFormat == types.RelayFormatOpenAIRealtime {
return 0, nil
}
model := common.GetContextKeyString(c, constant.ContextKeyOriginalModel)
tkm := CountTextToken(meta.CombineText, model)