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

@@ -7,7 +7,6 @@ import (
"net/http"
"net/url"
"one-api/common"
"one-api/logger"
"one-api/model"
"one-api/setting"
"one-api/setting/system_setting"
@@ -59,7 +58,7 @@ func getOidcUserInfoByCode(code string) (*OidcUser, error) {
}
res, err := client.Do(req)
if err != nil {
logger.SysLog(err.Error())
common.SysLog(err.Error())
return nil, errors.New("无法连接至 OIDC 服务器,请稍后重试!")
}
defer res.Body.Close()
@@ -70,7 +69,7 @@ func getOidcUserInfoByCode(code string) (*OidcUser, error) {
}
if oidcResponse.AccessToken == "" {
logger.SysError("OIDC 获取 Token 失败,请检查设置!")
common.SysLog("OIDC 获取 Token 失败,请检查设置!")
return nil, errors.New("OIDC 获取 Token 失败,请检查设置!")
}
@@ -81,12 +80,12 @@ func getOidcUserInfoByCode(code string) (*OidcUser, error) {
req.Header.Set("Authorization", "Bearer "+oidcResponse.AccessToken)
res2, err := client.Do(req)
if err != nil {
logger.SysLog(err.Error())
common.SysLog(err.Error())
return nil, errors.New("无法连接至 OIDC 服务器,请稍后重试!")
}
defer res2.Body.Close()
if res2.StatusCode != http.StatusOK {
logger.SysError("OIDC 获取用户信息失败!请检查设置!")
common.SysLog("OIDC 获取用户信息失败!请检查设置!")
return nil, errors.New("OIDC 获取用户信息失败!请检查设置!")
}
@@ -96,7 +95,7 @@ func getOidcUserInfoByCode(code string) (*OidcUser, error) {
return nil, err
}
if oidcUser.OpenID == "" || oidcUser.Email == "" {
logger.SysError("OIDC 获取用户信息为空!请检查设置!")
common.SysLog("OIDC 获取用户信息为空!请检查设置!")
return nil, errors.New("OIDC 获取用户信息为空!请检查设置!")
}
return &oidcUser, nil