+
Skip to content
This repository was archived by the owner on Sep 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 0 additions & 2 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ func getSuggestion(word string, validProps map[string]struct{}) string {
}

func mergeContext(config *map[interface{}]interface{}) {
// TODO: Create some sort of log buffer so verbose logs can be added
// before the config is complete.
contextHandler := NewContextHandler()
contextName := viper.GetString("context")

Expand Down
46 changes: 44 additions & 2 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,37 @@ const (
verbose
)

type logBuffer struct {
levels []logLevel
messages []string
}

func newBuffer() *logBuffer {
buf := &logBuffer{
levels: []logLevel{},
messages: []string{},
}
return buf
}

func (b *logBuffer) add(lvl logLevel, a ...interface{}) {
b.levels = append(b.levels, lvl)
b.messages = append(b.messages, fmt.Sprint(a...))
// If it's fatal, we just want to dump everything in the buffer
if lvl == fatal {
buffering = false
b.flush()
}
}

func (b *logBuffer) flush() {
for i, lvl := range b.levels {
print(lvl, b.messages[i])
}
b.levels = []logLevel{}
b.messages = []string{}
}

var level logLevel

// printJSON represents whether all output should be in JSON format or not.
Expand All @@ -49,6 +80,9 @@ var printJSON bool
// Traffic represents wether traffic should be printed or not.
var Traffic bool

var buffering bool
var buffer *logBuffer

// Init reads the log-related viper flags json, verbose, traffic and quiet and sets the
// internal (log.) level, printJSON and traffic variables accordingly.
func Init() {
Expand All @@ -67,10 +101,14 @@ func Init() {
} else {
level = info
}
buffering = false
buffer.flush()
}

func init() {
level = info
buffer = newBuffer()
buffering = true
}

func Quietln(a ...interface{}) {
Expand Down Expand Up @@ -175,8 +213,12 @@ func print(lvl logLevel, a ...interface{}) {
if prefix != "" {
prefix += ": "
}
str := prefix + fmt.Sprint(a...)
fmt.Print(str)
if buffering {
buffer.add(lvl, a...)
} else {
str := prefix + fmt.Sprint(a...)
fmt.Print(str)
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/corectl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ func TestQuietCommands(t *testing.T) {
}
}

func TestLogBuffer(t *testing.T) {
p := toolkit.Params{T: t, Config: "test/projects/quiet/corectl.yml", Engine: *toolkit.EngineStdIP, App: t.Name()}
p.ExpectOK().Run("context", "set", t.Name())
// The quiest flag should mute the warnings
p.ExpectEmptyOK().Run("app", "ls", "-q")
// We should have a warning saying something about context here
p.ExpectIncludes("context").Run("app", "ls")
p.ExpectOK().Run("context", "rm", t.Name())
}

func TestConnectionManagementCommands(t *testing.T) {
p := toolkit.Params{T: t, Config: "test/projects/using-entities/corectl.yml", Engine: *toolkit.EngineStdIP, App: t.Name()}
defer p.Reset()
Expand Down
1 change: 1 addition & 0 deletions test/projects/quiet/corectl.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
engine: ${ENGINE_STD_URL}
connections:
data:
connectionstring: /data
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载