feat: add SysWarn and SysWarnf logging functions; handle SMTP short response warning

This commit is contained in:
JustSong 2025-02-02 17:13:41 +08:00
parent 9e1f06df5c
commit ececfe5ba0
2 changed files with 13 additions and 0 deletions

View File

@ -57,6 +57,14 @@ func SysLogf(format string, a ...any) {
logHelper(nil, loggerINFO, fmt.Sprintf(format, a...))
}
func SysWarn(s string) {
logHelper(nil, loggerWarn, s)
}
func SysWarnf(format string, a ...any) {
logHelper(nil, loggerWarn, fmt.Sprintf(format, a...))
}
func SysError(s string) {
logHelper(nil, loggerError, s)
}

View File

@ -11,6 +11,7 @@ import (
"time"
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/common/logger"
)
func shouldAuth() bool {
@ -102,5 +103,9 @@ func SendEmail(subject string, receiver string, content string) error {
return nil
}
err = smtp.SendMail(addr, auth, config.SMTPAccount, to, mail)
if err != nil && strings.Contains(err.Error(), "short response") { // 部分提供商返回该错误,但实际上邮件已经发送成功
logger.SysWarnf("short response from SMTP server, return nil instead of error: %s", err.Error())
return nil
}
return err
}