Skip to content

Commit

Permalink
Fold WarningLogger info Logger (#1205)
Browse files Browse the repository at this point in the history
* Fold WarningLogger info Logger

* Update changelog
  • Loading branch information
axw authored Feb 3, 2022
1 parent cdc4eb4 commit fa66d15
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ https://github.com/elastic/apm-agent-go/compare/v1.15.0...main[View commits]
- Replace apm.DefaultTracer with an initialization function {pull}1189[#(1189)]
- Remove transport.Default, construct a new Transport in each new tracer {pull}1195[#(1195)]
- Add service name and version to User-Agent header {pull}1196[#(1196)]
- Remove WarningLogger, add Warningf methe to Logger {pull}1205[#(1205)]
- Replace Sampler with ExtendedSampler {pull}1206[#(1206)]
[[release-notes-1.x]]
Expand Down
5 changes: 5 additions & 0 deletions apmtest/testlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func (t TestLogger) Errorf(format string, args ...interface{}) {
t.l.Logf("[ERROR] "+format, args...)
}

// Warningf logs warning messages.
func (t TestLogger) Warningf(format string, args ...interface{}) {
t.l.Logf("[WARNING] "+format, args...)
}

// LogfLogger is an interface with the a Logf method,
// implemented by *testing.T and *testing.B.
type LogfLogger interface {
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func initialExitSpanMinDuration() (time.Duration, error) {
// config for config attributes that have been removed (exist in old but not in attrs).
//
// On return from updateRemoteConfig, unapplied config will have been removed from attrs.
func (t *Tracer) updateRemoteConfig(logger WarningLogger, old, attrs map[string]string) {
func (t *Tracer) updateRemoteConfig(logger Logger, old, attrs map[string]string) {
warningf := func(string, ...interface{}) {}
debugf := func(string, ...interface{}) {}
errorf := func(string, ...interface{}) {}
Expand Down
23 changes: 0 additions & 23 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,7 @@ type Logger interface {

// Errorf logs a message at error level.
Errorf(format string, args ...interface{})
}

// WarningLogger extends Logger with a Warningf method.
//
// TODO(axw) this will be removed in v2.0.0, and the
// Warningf method will be added directly to Logger.
type WarningLogger interface {
Logger

// Warningf logs a message at warning level.
Warningf(format string, args ...interface{})
}

func makeWarningLogger(l Logger) WarningLogger {
if wl, ok := l.(WarningLogger); ok {
return wl
}
return debugWarningLogger{Logger: l}
}

type debugWarningLogger struct {
Logger
}

func (l debugWarningLogger) Warningf(format string, args ...interface{}) {
l.Debugf(format, args...)
}
7 changes: 2 additions & 5 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ type tracerConfig struct {
requestSize int
requestDuration time.Duration
metricsInterval time.Duration
logger WarningLogger
logger Logger
metricsGatherers []MetricsGatherer
disabledMetrics wildcard.Matchers
cpuProfileDuration time.Duration
Expand Down Expand Up @@ -617,15 +617,12 @@ func (t *Tracer) SetMetricsInterval(d time.Duration) {
// SetLogger sets the Logger to be used for logging the operation of
// the tracer.
//
// If logger implements WarningLogger, its Warningf method will be used
// for logging warnings. Otherwise, warnings will logged using Debugf.
//
// The tracer is initialized with a default logger configured with the
// environment variables ELASTIC_APM_LOG_FILE and ELASTIC_APM_LOG_LEVEL.
// Calling SetLogger will replace the default logger.
func (t *Tracer) SetLogger(logger Logger) {
t.sendConfigCommand(func(cfg *tracerConfig) {
cfg.logger = makeWarningLogger(logger)
cfg.logger = logger
})
}

Expand Down

0 comments on commit fa66d15

Please sign in to comment.