You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2020/11/16 04:17:59 UTC
[servicecomb-service-center] branch master updated: SCB-2094 No
longer support Go version before 1.8 (#744)
This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 321aa8a SCB-2094 No longer support Go version before 1.8 (#744)
321aa8a is described below
commit 321aa8a4206f0487c2324cf68fd547a7f3673fdd
Author: little-cui <su...@qq.com>
AuthorDate: Mon Nov 16 12:17:51 2020 +0800
SCB-2094 No longer support Go version before 1.8 (#744)
---
README.md | 2 +-
go.mod | 1 -
go.sum | 2 -
pkg/log/lager.go | 102 ---------------------------------------------
pkg/log/log.go | 105 ----------------------------------------------
pkg/log/log_test.go | 117 ----------------------------------------------------
pkg/log/log_zap.go | 2 -
pkg/log/zap.go | 2 -
8 files changed, 1 insertion(+), 332 deletions(-)
diff --git a/README.md b/README.md
index 65a1b1d..8d3379d 100644
--- a/README.md
+++ b/README.md
@@ -93,7 +93,7 @@ httpport = 30100
Requirements
-+ [Go](https://golang.org) version 1.8+ is required to build the latest version of Service-Center.
++ [Go](https://golang.org) version 1.9+ is required to build the latest version of Service-Center.
Download the Code
```sh
diff --git a/go.mod b/go.mod
index 69973fd..3d3d632 100644
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,6 @@ require (
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3
github.com/go-chassis/go-archaius v1.3.6-0.20201103103813-43dd1680ebfb
github.com/go-chassis/go-chassis/v2 v2.0.5-0.20201112082226-c3cc3c1ae17c
- github.com/go-chassis/paas-lager v1.1.1
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d
github.com/golang/protobuf v1.4.2
github.com/gorilla/websocket v1.4.0
diff --git a/go.sum b/go.sum
index 3760efd..de404c3 100644
--- a/go.sum
+++ b/go.sum
@@ -102,7 +102,6 @@ github.com/go-chassis/go-restful-swagger20 v1.0.3-0.20200310030431-17d80f34264f/
github.com/go-chassis/openlog v1.1.1/go.mod h1:ZZOS68OvrFIKEJbuBa4YnYzmxyVx3lmcMfMKb+Hx/yQ=
github.com/go-chassis/openlog v1.1.2 h1:LgGfwwOhpU8c6URV6ADpaRBPVY7Ph1C28jCQ6zzQawQ=
github.com/go-chassis/openlog v1.1.2/go.mod h1:+eYCADVxWyJkwsFMUBrMxyQlNqW+UUsCxvR2LrYZUaA=
-github.com/go-chassis/paas-lager v1.1.1 h1:/6wqawUGjPCpd57A/tzJzgC4MnEhNuigbayQS+2VWPQ=
github.com/go-chassis/paas-lager v1.1.1/go.mod h1:tILYbn3+0jjCxhY6/ue9L8eRq+VJ60U6VYIdugqchB4=
github.com/go-chassis/seclog v1.3.0/go.mod h1:a/zGvX5BRiwtq/O0fRqS6VWjrBaXYtqFJBx3EX9xzSE=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
@@ -111,7 +110,6 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
-github.com/go-mesh/openlogging v1.0.1 h1:6raaXo8SK+wuQX1VoNi6QJCSf1fTOFWh7f5f6b2ZEmY=
github.com/go-mesh/openlogging v1.0.1/go.mod h1:qaKi+amO+hsGin2q1GmW+/NcbZpMPnTufwrWzDmIuuU=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
diff --git a/pkg/log/lager.go b/pkg/log/lager.go
deleted file mode 100644
index 62b1de0..0000000
--- a/pkg/log/lager.go
+++ /dev/null
@@ -1,102 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements. See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// +build !go1.9
-
-package log
-
-import (
- "github.com/apache/servicecomb-service-center/pkg/util"
- stlager "github.com/go-chassis/paas-lager"
- "github.com/go-chassis/paas-lager/third_party/forked/cloudfoundry/lager"
- "runtime/debug"
-)
-
-var (
- defaultLagerConfig = stlager.DefaultConfig()
- stdOutWriters = []string{"stdout"}
- fileWriters = []string{"file"}
-)
-
-// Config struct for lager and rotate parameters
-type Config struct {
- LoggerLevel string
- LoggerFile string
- LogFormatText bool
- // MB
- LogRotateSize int
- LogBackupCount int
- CallerSkip int
-}
-
-func (c Config) WithCallerSkip(s int) Config {
- c.CallerSkip = s
- return c
-}
-
-func (c Config) WithFile(path string) Config {
- c.LoggerFile = path
- return c
-}
-
-func Configure() Config {
- return fromLagerConfig(defaultLagerConfig)
-}
-
-func fromLagerConfig(c *stlager.Config) Config {
- return Config{
- LoggerLevel: c.LoggerLevel,
- LoggerFile: c.LoggerFile,
- LogFormatText: c.LogFormatText,
- }
-}
-
-func toLagerConfig(c Config) stlager.Config {
- w := fileWriters
- if len(c.LoggerFile) == 0 {
- w = stdOutWriters
- }
- return stlager.Config{
- Writers: w,
- LoggerLevel: c.LoggerLevel,
- LoggerFile: c.LoggerFile,
- LogFormatText: c.LogFormatText,
- }
-}
-
-// newLog new log, unsafe
-func NewLogger(cfg Config) *Logger {
- if cfg.CallerSkip == 0 {
- cfg.CallerSkip = globalCallerSkip
- }
- stlager.Init(toLagerConfig(cfg))
- return &Logger{
- Config: cfg,
- Logger: stlager.NewLogger(cfg.LoggerFile),
- }
-}
-
-type Logger struct {
- Config Config
- lager.Logger
-}
-
-func (l *Logger) Recover(r interface{}, callerSkip int) {
- l.Errorf(nil, "recover from panic, %v", r)
- l.Error(util.BytesToStringWithNoCopy(debug.Stack()), nil)
-}
-
-func (l *Logger) Sync() {
-}
diff --git a/pkg/log/log.go b/pkg/log/log.go
deleted file mode 100644
index 8d7e324..0000000
--- a/pkg/log/log.go
+++ /dev/null
@@ -1,105 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements. See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// +build nozap
-
-package log
-
-import (
- "fmt"
- "github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/go-chassis/paas-lager/third_party/forked/cloudfoundry/lager"
- "os"
- "path/filepath"
- "strings"
- "time"
-)
-
-const (
- defaultLogLevel = "DEBUG"
- globalCallerSkip = 1
- defaultLogRotatePeriod = 30 * time.Second
-)
-
-//log var
-var (
- logger = NewLogger(Configure())
- globalConfig Config
- globalLogLevel lager.LogLevel
-)
-
-func SetGlobal(cfg Config) {
- // renew the global logger
- if len(cfg.LoggerLevel) == 0 {
- cfg.LoggerLevel = defaultLogLevel
- }
- globalConfig = cfg
- logger = NewLogger(cfg)
- // recreate the deleted log file
- switch strings.ToUpper(cfg.LoggerLevel) {
- case "INFO":
- globalLogLevel = lager.INFO
- case "WARN":
- globalLogLevel = lager.WARN
- case "ERROR":
- globalLogLevel = lager.ERROR
- case "FATAL":
- globalLogLevel = lager.FATAL
- default:
- globalLogLevel = lager.DEBUG
- }
-
- runLogDirRotate(cfg)
-
- monitorLogFile()
-}
-
-func runLogDirRotate(cfg Config) {
- if len(cfg.LoggerFile) == 0 {
- return
- }
- go func() {
- for {
- <-time.After(defaultLogRotatePeriod)
- Rotate(filepath.Dir(cfg.LoggerFile), cfg.LogRotateSize, cfg.LogBackupCount)
- }
- }()
-}
-
-func monitorLogFile() {
- if len(globalConfig.LoggerFile) == 0 {
- return
- }
- go func() {
- for {
- <-time.After(time.Minute)
- Debug(fmt.Sprintf("Check log file at %s", time.Now()))
- if util.PathExist(globalConfig.LoggerFile) {
- continue
- }
-
- file, err := os.OpenFile(globalConfig.LoggerFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
- if err != nil {
- Errorf(err, "Create log file failed.")
- continue
- }
-
- // TODO Here will lead to file handle leak
- sink := lager.NewReconfigurableSink(lager.NewWriterSink("file", file, lager.DEBUG), globalLogLevel)
- logger.RegisterSink(sink)
- Errorf(nil, "log file is removed, create again.")
- }
- }()
-}
diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go
deleted file mode 100644
index bbbe9d8..0000000
--- a/pkg/log/log_test.go
+++ /dev/null
@@ -1,117 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more
-// contributor license agreements. See the NOTICE file distributed with
-// this work for additional information regarding copyright ownership.
-// The ASF licenses this file to You under the Apache License, Version 2.0
-// (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package log
-
-import (
- "errors"
- "os"
- "testing"
- "time"
-)
-
-func TestNewLogger(t *testing.T) {
- l := NewLogger(Configure())
- defer func() {
- r := recover()
- Panic(r)
- l.Recover(r, 3)
- defer func() {
- l.Recover(recover(), 3)
-
- defer func() {
- l.Recover(recover(), 3)
-
- defer func() {
- l.Recover(recover(), 3)
- }()
- Fatalf(nil, "a")
- }()
- Fatal("a", nil)
- }()
- l.Fatalf(nil, "%s", "b")
- }()
-
- os.Remove("test.log")
- SetGlobal(Configure().WithCallerSkip(2).WithFile("test.log"))
-
- Debug("a")
- l.Debug("a")
- Debugf("%s", "b")
- l.Debugf("%s", "b")
-
- Info("a")
- l.Info("a")
- Infof("%s", "b")
- l.Infof("%s", "b")
-
- Warn("a")
- l.Warn("a")
- Warnf("%s", "b")
- l.Warnf("%s", "b")
-
- Error("a", nil)
- l.Error("a", nil)
- Errorf(nil, "%s", "a")
- l.Errorf(nil, "%s", "a")
- Error("a", errors.New("error"))
- l.Error("a", errors.New("error"))
- Errorf(errors.New("error"), "%s", "a")
- l.Errorf(errors.New("error"), "%s", "a")
-
- Sync()
- l.Sync()
-
- NilOrWarnf(time.Now(), "a")
- NilOrWarnf(time.Now().Add(-time.Second), "a")
- DebugOrWarnf(time.Now(), "a")
- DebugOrWarnf(time.Now().Add(-time.Second), "a")
- InfoOrWarnf(time.Now(), "a")
- InfoOrWarnf(time.Now().Add(-time.Second), "a")
-
- l.Fatal("a", nil)
-}
-
-func TestNewLoggerWithEmptyConfig(t *testing.T) {
- l := NewLogger(Config{})
- l.Info("a")
-}
-
-func TestLogPanic(t *testing.T) {
- defer func() {
- defer func() {
- Panic(recover())
- }()
- panic("bbb")
- }()
- defer Recover()
- var a *int
- *a = 0
-}
-
-func BenchmarkLogger(b *testing.B) {
- cfg := Configure().WithFile("test.log")
- l := NewLogger(cfg)
- defer os.Remove("test.log")
-
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- l.Infof("error test %s", "x")
- }
- l.Sync()
- // go1.9+ 300000 6078 ns/op 176 B/op 7 allocs/op
- // go1.9- 200000 8217 ns/op 912 B/op 15 allocs/op
- b.ReportAllocs()
-}
diff --git a/pkg/log/log_zap.go b/pkg/log/log_zap.go
index f0c6abf..8333776 100644
--- a/pkg/log/log_zap.go
+++ b/pkg/log/log_zap.go
@@ -13,8 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// +build !nozap
-
package log
import (
diff --git a/pkg/log/zap.go b/pkg/log/zap.go
index 3dd9018..5aea7e1 100644
--- a/pkg/log/zap.go
+++ b/pkg/log/zap.go
@@ -13,8 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// +build go1.9
-
package log
import (