diff --git a/internal/accesslogs/storage_base.go b/internal/accesslogs/storage_base.go index f125d617..fe7af2ba 100644 --- a/internal/accesslogs/storage_base.go +++ b/internal/accesslogs/storage_base.go @@ -44,7 +44,7 @@ func (this *BaseStorage) Marshal(accessLog *pb.HTTPAccessLog) ([]byte, error) { // FormatVariables 格式化字符串中的变量 func (this *BaseStorage) FormatVariables(s string) string { - now := time.Now() + var now = time.Now() return configutils.ParseVariables(s, func(varName string) (value string) { switch varName { case "year": diff --git a/internal/accesslogs/storage_syslog.go b/internal/accesslogs/storage_syslog.go index 4ddc60e7..2c878a3a 100644 --- a/internal/accesslogs/storage_syslog.go +++ b/internal/accesslogs/storage_syslog.go @@ -1,7 +1,9 @@ package accesslogs import ( + "bytes" "errors" + "github.com/TeaOSLab/EdgeAPI/internal/remotelogs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/iwind/TeaGo/logs" @@ -95,7 +97,10 @@ func (this *SyslogStorage) Write(accessLogs []*pb.HTTPAccessLog) error { args = append(args, "-S", "10240") - cmd := exec.Command(this.exe, args...) + var cmd = exec.Command(this.exe, args...) + var stderrBuffer = &bytes.Buffer{} + cmd.Stderr = stderrBuffer + w, err := cmd.StdinPipe() if err != nil { return err @@ -111,7 +116,7 @@ func (this *SyslogStorage) Write(accessLogs []*pb.HTTPAccessLog) error { } data, err := this.Marshal(accessLog) if err != nil { - logs.Error(err) + remotelogs.Error("ACCESS_LOG_POLICY_SYSLOG", "marshal accesslog failed: "+err.Error()) continue } _, err = w.Write(data) @@ -121,14 +126,15 @@ func (this *SyslogStorage) Write(accessLogs []*pb.HTTPAccessLog) error { _, err = w.Write([]byte("\n")) if err != nil { - logs.Error(err) + remotelogs.Error("ACCESS_LOG_POLICY_SYSLOG", "write accesslog failed: "+err.Error()) } } _ = w.Close() + err = cmd.Wait() if err != nil { - return err + return errors.New("send syslog failed: " + err.Error() + ", stderr: " + stderrBuffer.String()) } return nil diff --git a/internal/const/const.go b/internal/const/const.go index 0904b532..8f800212 100644 --- a/internal/const/const.go +++ b/internal/const/const.go @@ -22,7 +22,7 @@ const ( UserNodeVersion = "0.3.4" AuthorityNodeVersion = "0.0.2" MonitorNodeVersion = "0.0.3" - DNSNodeVersion = "0.2.2" + DNSNodeVersion = "0.2.3" ReportNodeVersion = "0.1.0" // SQLVersion SQL版本号 diff --git a/internal/nodes/api_node.go b/internal/nodes/api_node.go index 6a522cc2..18709163 100644 --- a/internal/nodes/api_node.go +++ b/internal/nodes/api_node.go @@ -5,7 +5,6 @@ import ( "crypto/tls" "encoding/json" "errors" - "fmt" "github.com/TeaOSLab/EdgeAPI/internal/accesslogs" "github.com/TeaOSLab/EdgeAPI/internal/configs" teaconst "github.com/TeaOSLab/EdgeAPI/internal/const" @@ -292,7 +291,7 @@ func (this *APINode) checkDB() error { return err } else { if i%10 == 0 { // 这让提示不会太多 - logs.Println("[API_NODE]reconnecting to database (" + fmt.Sprintf("%.1f", float32(i*100)/float32(maxTries+1)) + "%) ...") + logs.Println("[API_NODE]check database connection failed: " + err.Error() + ", reconnecting to database ...") } time.Sleep(1 * time.Second) } @@ -764,8 +763,8 @@ func (this *APINode) dbIssueSuggestion(errString string) string { } // 权限错误 - if strings.Contains(errString, "Error 1045") { - return "使用的用户和密码没有权限连接到指定数据库,请检查:数据库配置文件中的用户名(" + dsnConfig.User + ")和密码(" + dsnConfig.Passwd + ")是否正确;(当前数据库配置为:" + dsn + ",配置文件位置:" + dbConfigPath + ")。" + if strings.Contains(errString, "Error 1045") || strings.Contains(errString, "Error 1044") { + return "使用的用户和密码没有权限连接到指定数据库,请检查:1)数据库配置文件中的用户名(" + dsnConfig.User + ")和密码(" + dsnConfig.Passwd + ")是否正确;2)使用的用户是否已经在数据库中设置了正确的权限;(当前数据库配置为:" + dsn + ",配置文件位置:" + dbConfigPath + ")。" } // 数据库名称错误