Skip to content

Commit

Permalink
Charmhub: Introduce a client logger
Browse files Browse the repository at this point in the history
To aid with debugging and to not cripple the controller when turning on
trace logger, create a child logger so we can effectively turn it off if
required.
  • Loading branch information
SimonRichardson committed May 27, 2021
1 parent a6380f3 commit 4b9dbb8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
5 changes: 4 additions & 1 deletion charmhub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/juju/charm/v8"
"github.com/juju/errors"
"github.com/juju/loggo"

charmhubpath "github.com/juju/juju/charmhub/path"
"github.com/juju/juju/charmhub/transport"
Expand Down Expand Up @@ -59,6 +60,8 @@ type Logger interface {
Errorf(string, ...interface{})
Debugf(string, ...interface{})
Tracef(string, ...interface{})

Child(string) loggo.Logger
}

// Config holds configuration for creating a new charm hub client.
Expand Down Expand Up @@ -162,7 +165,7 @@ func CharmHubConfig(logger Logger, options ...Option) (Config, error) {
Version: CharmHubServerVersion,
Entity: CharmHubServerEntity,
Headers: headers,
Transport: opts.transportFunc(logger),
Transport: opts.transportFunc(logger.Child("transport")),
Logger: logger,
}, nil
}
Expand Down
32 changes: 32 additions & 0 deletions charmhub/client_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions charmhub/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package charmhub

import "github.com/juju/loggo"

type FakeLogger struct {
}

Expand All @@ -15,3 +17,7 @@ func (l *FakeLogger) Errorf(format string, args ...interface{}) {}
func (l *FakeLogger) Debugf(format string, args ...interface{}) {}

func (l *FakeLogger) Tracef(format string, args ...interface{}) {}

func (l *FakeLogger) Child(string) loggo.Logger {
return loggo.Logger{}
}
5 changes: 5 additions & 0 deletions cmd/juju/charmhub/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/juju/collections/set"
"github.com/juju/errors"
"github.com/juju/gnuflag"
"github.com/juju/loggo"
"github.com/juju/os/v2/series"

"github.com/juju/juju/charmhub"
Expand Down Expand Up @@ -423,6 +424,10 @@ func (d downloadLogger) Debugf(msg string, args ...interface{}) {

func (d downloadLogger) Tracef(msg string, args ...interface{}) {}

func (d downloadLogger) Child(name string) loggo.Logger {
return loggo.Logger{}
}

type stdoutFileSystem struct{}

// Create creates or truncates the named file. If the file already exists,
Expand Down

0 comments on commit 4b9dbb8

Please sign in to comment.