Fix plugin logging missing context fields
Fix an issue where context fields logged by server on behalf of plugins didn't contain correct name/value pairs:
- bump Logr version to add key/value methods to sugar logger
- expose factory args when configuring logging with custom target types (needed for FocalBoard to create log target adapter that converts typed fields into slices of interface{} as per plugin logging API)
Этот коммит содержится в:
@@ -108,7 +108,7 @@ func TestLoggingAfterInitialized(t *testing.T) {
|
||||
}
|
||||
|
||||
logger, _ := mlog.NewLogger()
|
||||
err := logger.ConfigureTargets(map[string]mlog.TargetCfg{testCase.description: testCase.cfg})
|
||||
err := logger.ConfigureTargets(map[string]mlog.TargetCfg{testCase.description: testCase.cfg}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
mlog.InitGlobalLogger(logger)
|
||||
|
||||
@@ -49,6 +49,9 @@ type LogRec = logr.LogRec
|
||||
type LogCloner = logr.LogCloner
|
||||
type MetricsCollector = logr.MetricsCollector
|
||||
type TargetCfg = logrcfg.TargetCfg
|
||||
type TargetFactory = logrcfg.TargetFactory
|
||||
type FormatterFactory = logrcfg.FormatterFactory
|
||||
type Factories = logrcfg.Factories
|
||||
type Sugar = logr.Sugar
|
||||
|
||||
// LoggerConfiguration is a map of LogTarget configurations.
|
||||
@@ -179,7 +182,10 @@ func NewLogger(options ...Option) (*Logger, error) {
|
||||
// For each case JSON containing log targets is provided. Target name collisions are resolved
|
||||
// using the following precedence:
|
||||
// cfgFile > cfgEscaped
|
||||
func (l *Logger) Configure(cfgFile string, cfgEscaped string) error {
|
||||
//
|
||||
// An optional set of factories can be provided which will be called to create any target
|
||||
// types or formatters not built-in.
|
||||
func (l *Logger) Configure(cfgFile string, cfgEscaped string, factories *Factories) error {
|
||||
if atomic.LoadInt32(l.lockConfig) != 0 {
|
||||
return ErrConfigurationLock
|
||||
}
|
||||
@@ -213,16 +219,18 @@ func (l *Logger) Configure(cfgFile string, cfgEscaped string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return logrcfg.ConfigureTargets(l.log.Logr(), cfgMap.toTargetCfg(), nil)
|
||||
return logrcfg.ConfigureTargets(l.log.Logr(), cfgMap.toTargetCfg(), factories)
|
||||
}
|
||||
|
||||
// ConfigureTargets provides a new configuration for this logger via a `LoggerConfig` map.
|
||||
// Typically `mlog.Configure` is used instead which accepts JSON formatted configuration.
|
||||
func (l *Logger) ConfigureTargets(cfg LoggerConfiguration) error {
|
||||
// An optional set of factories can be provided which will be called to create any target
|
||||
// types or formatters not built-in.
|
||||
func (l *Logger) ConfigureTargets(cfg LoggerConfiguration, factories *Factories) error {
|
||||
if atomic.LoadInt32(l.lockConfig) != 0 {
|
||||
return ErrConfigurationLock
|
||||
}
|
||||
return logrcfg.ConfigureTargets(l.log.Logr(), cfg.toTargetCfg(), nil)
|
||||
return logrcfg.ConfigureTargets(l.log.Logr(), cfg.toTargetCfg(), factories)
|
||||
}
|
||||
|
||||
// LockConfiguration disallows further configuration changes until `UnlockConfiguration`
|
||||
@@ -405,6 +413,22 @@ func GetPackageName(f string) string {
|
||||
return f
|
||||
}
|
||||
|
||||
// ShouldQuote returns true if val contains any characters that might be unsafe
|
||||
// when injecting log output into an aggregator, viewer or report.
|
||||
// Returning true means that val should be surrounded by quotation marks before being
|
||||
// output into logs.
|
||||
func ShouldQuote(val string) bool {
|
||||
for _, c := range val {
|
||||
if !((c >= '0' && c <= '9') ||
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
c == '-' || c == '.' || c == '_' || c == '/' || c == '@' || c == '^' || c == '+') {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type logWriter struct {
|
||||
logger *Logger
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user