mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Chore: Renamed instrumentation middleware to metrics middleware (#76186)
* Plugins: Chore: Renamed instrumentation middleware to metrics middleware * Removed repeated logger attributes in middleware and contextual logger * renamed loggerParams to logParams * PR review suggestion * Add contextual logger middleware * Removed unused params from logRequest * Removed unwanted changes * Safer FromContext method * Removed traceID from logParams
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package log
|
||||
|
||||
import "context"
|
||||
|
||||
var _ Logger = (*TestLogger)(nil)
|
||||
|
||||
type TestLogger struct {
|
||||
@@ -41,6 +43,10 @@ func (f *TestLogger) Error(msg string, ctx ...any) {
|
||||
f.ErrorLogs.Ctx = ctx
|
||||
}
|
||||
|
||||
func (f *TestLogger) FromContext(_ context.Context) Logger {
|
||||
return NewTestLogger()
|
||||
}
|
||||
|
||||
type Logs struct {
|
||||
Calls int
|
||||
Message string
|
||||
|
||||
@@ -1,35 +1,40 @@
|
||||
package log
|
||||
|
||||
import "context"
|
||||
|
||||
// Logger is the default logger
|
||||
type Logger interface {
|
||||
// New returns a new contextual Logger that has this logger's context plus the given context.
|
||||
New(ctx ...interface{}) Logger
|
||||
New(ctx ...any) Logger
|
||||
|
||||
// Debug logs a message with debug level and key/value pairs, if any.
|
||||
Debug(msg string, ctx ...interface{})
|
||||
Debug(msg string, ctx ...any)
|
||||
|
||||
// Info logs a message with info level and key/value pairs, if any.
|
||||
Info(msg string, ctx ...interface{})
|
||||
Info(msg string, ctx ...any)
|
||||
|
||||
// Warn logs a message with warning level and key/value pairs, if any.
|
||||
Warn(msg string, ctx ...interface{})
|
||||
Warn(msg string, ctx ...any)
|
||||
|
||||
// Error logs a message with error level and key/value pairs, if any.
|
||||
Error(msg string, ctx ...interface{})
|
||||
Error(msg string, ctx ...any)
|
||||
|
||||
// FromContext returns a new contextual Logger that has this logger's context plus the given context.
|
||||
FromContext(ctx context.Context) Logger
|
||||
}
|
||||
|
||||
// PrettyLogger is used primarily to facilitate logging/user feedback for both
|
||||
// the grafana-cli and the grafana backend when managing plugin installs
|
||||
type PrettyLogger interface {
|
||||
Successf(format string, args ...interface{})
|
||||
Failuref(format string, args ...interface{})
|
||||
Successf(format string, args ...any)
|
||||
Failuref(format string, args ...any)
|
||||
|
||||
Info(args ...interface{})
|
||||
Infof(format string, args ...interface{})
|
||||
Debug(args ...interface{})
|
||||
Debugf(format string, args ...interface{})
|
||||
Warn(args ...interface{})
|
||||
Warnf(format string, args ...interface{})
|
||||
Error(args ...interface{})
|
||||
Errorf(format string, args ...interface{})
|
||||
Info(args ...any)
|
||||
Infof(format string, args ...any)
|
||||
Debug(args ...any)
|
||||
Debugf(format string, args ...any)
|
||||
Warn(args ...any)
|
||||
Warnf(format string, args ...any)
|
||||
Error(args ...any)
|
||||
Errorf(format string, args ...any)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
)
|
||||
|
||||
@@ -42,3 +44,13 @@ func (d *grafanaInfraLogWrapper) Warn(msg string, ctx ...any) {
|
||||
func (d *grafanaInfraLogWrapper) Error(msg string, ctx ...any) {
|
||||
d.l.Error(msg, ctx...)
|
||||
}
|
||||
|
||||
func (d *grafanaInfraLogWrapper) FromContext(ctx context.Context) Logger {
|
||||
concreteInfraLogger, ok := d.l.FromContext(ctx).(*log.ConcreteLogger)
|
||||
if !ok {
|
||||
return d.New()
|
||||
}
|
||||
return &grafanaInfraLogWrapper{
|
||||
l: concreteInfraLogger,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user