mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove the old log format (#51526)
* remove the old log format * fix CI Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
@@ -1,264 +0,0 @@
|
||||
package level
|
||||
|
||||
import (
|
||||
"github.com/go-kit/log"
|
||||
gokitlevel "github.com/go-kit/log/level"
|
||||
)
|
||||
|
||||
// Error returns a logger that includes a Key/ErrorValue pair.
|
||||
func Error(logger log.Logger) log.Logger {
|
||||
return log.WithPrefix(logger, Key(), ErrorValue())
|
||||
}
|
||||
|
||||
// Warn returns a logger that includes a Key/WarnValue pair.
|
||||
func Warn(logger log.Logger) log.Logger {
|
||||
return log.WithPrefix(logger, Key(), WarnValue())
|
||||
}
|
||||
|
||||
// Info returns a logger that includes a Key/InfoValue pair.
|
||||
func Info(logger log.Logger) log.Logger {
|
||||
return log.WithPrefix(logger, Key(), InfoValue())
|
||||
}
|
||||
|
||||
// Debug returns a logger that includes a Key/DebugValue pair.
|
||||
func Debug(logger log.Logger) log.Logger {
|
||||
return log.WithPrefix(logger, Key(), DebugValue())
|
||||
}
|
||||
|
||||
// NewFilter wraps next and implements level filtering. See the commentary on
|
||||
// the Option functions for a detailed description of how to configure levels.
|
||||
// If no options are provided, all leveled log events created with Debug,
|
||||
// Info, Warn or Error helper methods are squelched and non-leveled log
|
||||
// events are passed to next unmodified.
|
||||
func NewFilter(next log.Logger, options ...Option) log.Logger {
|
||||
l := &logger{
|
||||
next: next,
|
||||
}
|
||||
for _, option := range options {
|
||||
option(l)
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
type logger struct {
|
||||
next log.Logger
|
||||
allowed level
|
||||
squelchNoLevel bool
|
||||
errNotAllowed error
|
||||
errNoLevel error
|
||||
}
|
||||
|
||||
func (l *logger) Log(keyvals ...interface{}) error {
|
||||
var hasLevel, levelAllowed bool
|
||||
for i := 1; i < len(keyvals); i += 2 {
|
||||
if v, ok := keyvals[i].(*levelValue); ok {
|
||||
hasLevel = true
|
||||
levelAllowed = l.allowed&v.level != 0
|
||||
break
|
||||
}
|
||||
|
||||
if v, ok := keyvals[i].(gokitlevel.Value); ok {
|
||||
hasLevel = true
|
||||
levelAllowed = l.allowed&levelFromGokitLevel(v) != 0
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasLevel && l.squelchNoLevel {
|
||||
return l.errNoLevel
|
||||
}
|
||||
if hasLevel && !levelAllowed {
|
||||
return l.errNotAllowed
|
||||
}
|
||||
return l.next.Log(keyvals...)
|
||||
}
|
||||
|
||||
// Option sets a parameter for the leveled logger.
|
||||
type Option func(*logger)
|
||||
|
||||
// AllowAll is an alias for AllowDebug.
|
||||
func AllowAll() Option {
|
||||
return AllowDebug()
|
||||
}
|
||||
|
||||
// AllowDebug allows error, warn, info and debug level log events to pass.
|
||||
func AllowDebug() Option {
|
||||
return allowed(levelError | levelWarn | levelInfo | levelDebug)
|
||||
}
|
||||
|
||||
// AllowInfo allows error, warn and info level log events to pass.
|
||||
func AllowInfo() Option {
|
||||
return allowed(levelError | levelWarn | levelInfo)
|
||||
}
|
||||
|
||||
// AllowWarn allows error and warn level log events to pass.
|
||||
func AllowWarn() Option {
|
||||
return allowed(levelError | levelWarn)
|
||||
}
|
||||
|
||||
// AllowError allows only error level log events to pass.
|
||||
func AllowError() Option {
|
||||
return allowed(levelError)
|
||||
}
|
||||
|
||||
// AllowNone allows no leveled log events to pass.
|
||||
func AllowNone() Option {
|
||||
return allowed(0)
|
||||
}
|
||||
|
||||
func allowed(allowed level) Option {
|
||||
return func(l *logger) { l.allowed = allowed }
|
||||
}
|
||||
|
||||
// ErrNotAllowed sets the error to return from Log when it squelches a log
|
||||
// event disallowed by the configured Allow[Level] option. By default,
|
||||
// ErrNotAllowed is nil; in this case the log event is squelched with no
|
||||
// error.
|
||||
func ErrNotAllowed(err error) Option {
|
||||
return func(l *logger) { l.errNotAllowed = err }
|
||||
}
|
||||
|
||||
// SquelchNoLevel instructs Log to squelch log events with no level, so that
|
||||
// they don't proceed through to the wrapped logger. If SquelchNoLevel is set
|
||||
// to true and a log event is squelched in this way, the error value
|
||||
// configured with ErrNoLevel is returned to the caller.
|
||||
func SquelchNoLevel(squelch bool) Option {
|
||||
return func(l *logger) { l.squelchNoLevel = squelch }
|
||||
}
|
||||
|
||||
// ErrNoLevel sets the error to return from Log when it squelches a log event
|
||||
// with no level. By default, ErrNoLevel is nil; in this case the log event is
|
||||
// squelched with no error.
|
||||
func ErrNoLevel(err error) Option {
|
||||
return func(l *logger) { l.errNoLevel = err }
|
||||
}
|
||||
|
||||
// NewInjector wraps next and returns a logger that adds a Key/level pair to
|
||||
// the beginning of log events that don't already contain a level. In effect,
|
||||
// this gives a default level to logs without a level.
|
||||
func NewInjector(next log.Logger, level Value) log.Logger {
|
||||
return &injector{
|
||||
next: next,
|
||||
level: level,
|
||||
}
|
||||
}
|
||||
|
||||
type injector struct {
|
||||
next log.Logger
|
||||
level interface{}
|
||||
}
|
||||
|
||||
func (l *injector) Log(keyvals ...interface{}) error {
|
||||
for i := 1; i < len(keyvals); i += 2 {
|
||||
if _, ok := keyvals[i].(*levelValue); ok {
|
||||
return l.next.Log(keyvals...)
|
||||
}
|
||||
}
|
||||
kvs := make([]interface{}, len(keyvals)+2)
|
||||
kvs[0], kvs[1] = key, l.level
|
||||
copy(kvs[2:], keyvals)
|
||||
return l.next.Log(kvs...)
|
||||
}
|
||||
|
||||
// Value is the interface that each of the canonical level values implement.
|
||||
// It contains unexported methods that prevent types from other packages from
|
||||
// implementing it and guaranteeing that NewFilter can distinguish the levels
|
||||
// defined in this package from all other values.
|
||||
type Value interface {
|
||||
String() string
|
||||
levelVal()
|
||||
}
|
||||
|
||||
// Key returns the unique key added to log events by the loggers in this
|
||||
// package.
|
||||
func Key() interface{} { return key }
|
||||
|
||||
// ErrorValue returns the unique value added to log events by Error.
|
||||
func ErrorValue() Value { return errorValue }
|
||||
|
||||
// WarnValue returns the unique value added to log events by Warn.
|
||||
func WarnValue() Value { return warnValue }
|
||||
|
||||
// InfoValue returns the unique value added to log events by Info.
|
||||
func InfoValue() Value { return infoValue }
|
||||
|
||||
// DebugValue returns the unique value added to log events by Debug.
|
||||
func DebugValue() Value { return debugValue }
|
||||
|
||||
var (
|
||||
// key is of type interface{} so that it allocates once during package
|
||||
// initialization and avoids allocating every time the value is added to a
|
||||
// []interface{} later.
|
||||
key interface{} = "lvl"
|
||||
|
||||
errorValue = &levelValue{level: levelError, name: "eror"}
|
||||
warnValue = &levelValue{level: levelWarn, name: "warn"}
|
||||
infoValue = &levelValue{level: levelInfo, name: "info"}
|
||||
debugValue = &levelValue{level: levelDebug, name: "dbug"}
|
||||
)
|
||||
|
||||
func SetLevelKeyAndValuesToGokitLog() {
|
||||
key = "level"
|
||||
errorValue = &levelValue{level: levelError, name: "error"}
|
||||
warnValue = &levelValue{level: levelWarn, name: "warn"}
|
||||
infoValue = &levelValue{level: levelInfo, name: "info"}
|
||||
debugValue = &levelValue{level: levelDebug, name: "debug"}
|
||||
}
|
||||
|
||||
type level byte
|
||||
|
||||
const (
|
||||
levelDebug level = 1 << iota
|
||||
levelInfo
|
||||
levelWarn
|
||||
levelError
|
||||
)
|
||||
|
||||
func IsKey(v interface{}) bool {
|
||||
return v != nil && (v == Key() || v == gokitlevel.Key())
|
||||
}
|
||||
|
||||
func GetValue(v interface{}) Value {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if val, ok := v.(Value); ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := v.(gokitlevel.Value); ok {
|
||||
switch val {
|
||||
case gokitlevel.InfoValue():
|
||||
return InfoValue()
|
||||
case gokitlevel.WarnValue():
|
||||
return WarnValue()
|
||||
case gokitlevel.ErrorValue():
|
||||
return ErrorValue()
|
||||
case gokitlevel.DebugValue():
|
||||
return DebugValue()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type levelValue struct {
|
||||
name string
|
||||
level
|
||||
}
|
||||
|
||||
func (v *levelValue) String() string { return v.name }
|
||||
func (v *levelValue) levelVal() {}
|
||||
|
||||
func levelFromGokitLevel(l gokitlevel.Value) level {
|
||||
switch l.String() {
|
||||
case gokitlevel.ErrorValue().String():
|
||||
return levelError
|
||||
case gokitlevel.WarnValue().String():
|
||||
return levelWarn
|
||||
case gokitlevel.DebugValue().String():
|
||||
return levelDebug
|
||||
}
|
||||
|
||||
return levelInfo
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
package level_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
gokitlog "github.com/go-kit/log"
|
||||
gokitlevel "github.com/go-kit/log/level"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
)
|
||||
|
||||
func TestNewFilter(t *testing.T) {
|
||||
newFilteredLoggerScenario(t, "Given all levels is allowed should log all messages", level.AllowAll(), func(t *testing.T, ctx *scenarioContext) {
|
||||
logTestMessages(t, ctx)
|
||||
|
||||
require.Len(t, ctx.loggedArgs, 8)
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[0][2].(string))
|
||||
require.Equal(t, "info", ctx.loggedArgs[0][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[1][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[1][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[2][2].(string))
|
||||
require.Equal(t, "eror", ctx.loggedArgs[2][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[3][2].(string))
|
||||
require.Equal(t, "dbug", ctx.loggedArgs[3][3].(level.Value).String())
|
||||
|
||||
require.Equal(t, "level", ctx.loggedArgs[4][2].(string))
|
||||
require.Equal(t, "info", ctx.loggedArgs[4][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[5][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[5][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[6][2].(string))
|
||||
require.Equal(t, "error", ctx.loggedArgs[6][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[7][2].(string))
|
||||
require.Equal(t, "debug", ctx.loggedArgs[7][3].(gokitlevel.Value).String())
|
||||
})
|
||||
|
||||
newFilteredLoggerScenario(t, "Given error, warnings, info, debug is allowed should log all messages", level.AllowDebug(), func(t *testing.T, ctx *scenarioContext) {
|
||||
logTestMessages(t, ctx)
|
||||
|
||||
require.Len(t, ctx.loggedArgs, 8)
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[0][2].(string))
|
||||
require.Equal(t, "info", ctx.loggedArgs[0][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[1][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[1][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[2][2].(string))
|
||||
require.Equal(t, "eror", ctx.loggedArgs[2][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[3][2].(string))
|
||||
require.Equal(t, "dbug", ctx.loggedArgs[3][3].(level.Value).String())
|
||||
|
||||
require.Equal(t, "level", ctx.loggedArgs[4][2].(string))
|
||||
require.Equal(t, "info", ctx.loggedArgs[4][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[5][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[5][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[6][2].(string))
|
||||
require.Equal(t, "error", ctx.loggedArgs[6][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[7][2].(string))
|
||||
require.Equal(t, "debug", ctx.loggedArgs[7][3].(gokitlevel.Value).String())
|
||||
})
|
||||
|
||||
newFilteredLoggerScenario(t, "Given error, warnings is allowed should log error and warning messages", level.AllowWarn(), func(t *testing.T, ctx *scenarioContext) {
|
||||
logTestMessages(t, ctx)
|
||||
|
||||
require.Len(t, ctx.loggedArgs, 4)
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[0][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[0][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[1][2].(string))
|
||||
require.Equal(t, "eror", ctx.loggedArgs[1][3].(level.Value).String())
|
||||
|
||||
require.Equal(t, "level", ctx.loggedArgs[2][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[2][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[3][2].(string))
|
||||
require.Equal(t, "error", ctx.loggedArgs[3][3].(gokitlevel.Value).String())
|
||||
})
|
||||
|
||||
newFilteredLoggerScenario(t, "Given error allowed should log error messages", level.AllowError(), func(t *testing.T, ctx *scenarioContext) {
|
||||
logTestMessages(t, ctx)
|
||||
|
||||
require.Len(t, ctx.loggedArgs, 2)
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[0][2].(string))
|
||||
require.Equal(t, "eror", ctx.loggedArgs[0][3].(level.Value).String())
|
||||
|
||||
require.Equal(t, "level", ctx.loggedArgs[1][2].(string))
|
||||
require.Equal(t, "error", ctx.loggedArgs[1][3].(gokitlevel.Value).String())
|
||||
})
|
||||
|
||||
newFilteredLoggerScenario(t, "Given error, warnings, info is allowed should log error, warning and info messages", level.AllowInfo(), func(t *testing.T, ctx *scenarioContext) {
|
||||
logTestMessages(t, ctx)
|
||||
|
||||
require.Len(t, ctx.loggedArgs, 6)
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[0][2].(string))
|
||||
require.Equal(t, "info", ctx.loggedArgs[0][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[1][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[1][3].(level.Value).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[2][2].(string))
|
||||
require.Equal(t, "eror", ctx.loggedArgs[2][3].(level.Value).String())
|
||||
|
||||
require.Equal(t, "level", ctx.loggedArgs[3][2].(string))
|
||||
require.Equal(t, "info", ctx.loggedArgs[3][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[4][2].(string))
|
||||
require.Equal(t, "warn", ctx.loggedArgs[4][3].(gokitlevel.Value).String())
|
||||
require.Equal(t, "level", ctx.loggedArgs[5][2].(string))
|
||||
require.Equal(t, "error", ctx.loggedArgs[5][3].(gokitlevel.Value).String())
|
||||
})
|
||||
|
||||
newFilteredLoggerScenario(t, "Given no levels is allowed should not log any messages", level.AllowNone(), func(t *testing.T, ctx *scenarioContext) {
|
||||
logTestMessages(t, ctx)
|
||||
|
||||
require.Len(t, ctx.loggedArgs, 0)
|
||||
})
|
||||
}
|
||||
|
||||
func logTestMessages(t *testing.T, ctx *scenarioContext) {
|
||||
t.Helper()
|
||||
|
||||
ctx.logger.Info("info msg")
|
||||
ctx.logger.Warn("warn msg")
|
||||
ctx.logger.Error("error msg")
|
||||
ctx.logger.Debug("debug msg")
|
||||
err := gokitlevel.Info(ctx.logger).Log("msg", "gokit info msg")
|
||||
require.NoError(t, err)
|
||||
err = gokitlevel.Warn(ctx.logger).Log("msg", "gokit warn msg")
|
||||
require.NoError(t, err)
|
||||
err = gokitlevel.Error(ctx.logger).Log("msg", "gokit error msg")
|
||||
require.NoError(t, err)
|
||||
err = gokitlevel.Debug(ctx.logger).Log("msg", "gokit debug msg")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
type scenarioContext struct {
|
||||
loggedArgs [][]interface{}
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func newFilteredLoggerScenario(t *testing.T, desc string, option level.Option, fn func(t *testing.T, ctx *scenarioContext)) {
|
||||
t.Helper()
|
||||
|
||||
ctx := &scenarioContext{
|
||||
loggedArgs: [][]interface{}{},
|
||||
}
|
||||
|
||||
l := gokitlog.LoggerFunc(func(i ...interface{}) error {
|
||||
ctx.loggedArgs = append(ctx.loggedArgs, i)
|
||||
return nil
|
||||
})
|
||||
filteredLogger := level.NewFilter(l, option)
|
||||
testLogger := log.New("test")
|
||||
testLogger.Swap(filteredLogger)
|
||||
|
||||
ctx.logger = testLogger
|
||||
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
fn(t, ctx)
|
||||
})
|
||||
}
|
||||
@@ -11,17 +11,16 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
gokitlog "github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/go-stack/stack"
|
||||
"github.com/mattn/go-isatty"
|
||||
"gopkg.in/ini.v1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
"github.com/grafana/grafana/pkg/infra/log/term"
|
||||
"github.com/grafana/grafana/pkg/infra/log/text"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
@@ -32,7 +31,7 @@ var (
|
||||
loggersToReload []ReloadableHandler
|
||||
root *logManager
|
||||
now = time.Now
|
||||
logTimeFormat = "2006-01-02T15:04:05.99-0700"
|
||||
logTimeFormat = time.RFC3339Nano
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -56,10 +55,9 @@ func init() {
|
||||
// logManager manage loggers
|
||||
type logManager struct {
|
||||
*ConcreteLogger
|
||||
loggersByName map[string]*ConcreteLogger
|
||||
logFilters []logWithFilters
|
||||
mutex sync.RWMutex
|
||||
gokitLogActivated bool
|
||||
loggersByName map[string]*ConcreteLogger
|
||||
logFilters []logWithFilters
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
func newManager(logger gokitlog.Logger) *logManager {
|
||||
@@ -73,12 +71,6 @@ func (lm *logManager) initialize(loggers []logWithFilters) {
|
||||
lm.mutex.Lock()
|
||||
defer lm.mutex.Unlock()
|
||||
|
||||
if lm.gokitLogActivated {
|
||||
level.SetLevelKeyAndValuesToGokitLog()
|
||||
term.SetTimeFormatGokitLog()
|
||||
logTimeFormat = time.RFC3339Nano
|
||||
}
|
||||
|
||||
defaultLoggers := make([]gokitlog.Logger, len(loggers))
|
||||
for index, logger := range loggers {
|
||||
defaultLoggers[index] = level.NewFilter(logger.val, logger.maxLevel)
|
||||
@@ -452,58 +444,9 @@ func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) error {
|
||||
handler.maxLevel = leveloption
|
||||
configLoggers = append(configLoggers, handler)
|
||||
}
|
||||
|
||||
var err error
|
||||
isOldLoggerActivated, err := isOldLoggerActivated(cfg)
|
||||
root.gokitLogActivated = !isOldLoggerActivated
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(configLoggers) > 0 {
|
||||
root.initialize(configLoggers)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// This would be removed eventually, no need to make a fancy design.
|
||||
// For the sake of important cycle I just copied the function
|
||||
func isOldLoggerActivated(cfg *ini.File) (bool, error) {
|
||||
section := cfg.Section("feature_toggles")
|
||||
toggles, err := readFeatureTogglesFromInitFile(section)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return toggles["oldlog"], nil
|
||||
}
|
||||
|
||||
func readFeatureTogglesFromInitFile(featureTogglesSection *ini.Section) (map[string]bool, error) {
|
||||
featureToggles := make(map[string]bool, 10)
|
||||
|
||||
// parse the comma separated list in `enable`.
|
||||
featuresTogglesStr := valueAsString(featureTogglesSection, "enable", "")
|
||||
for _, feature := range util.SplitString(featuresTogglesStr) {
|
||||
featureToggles[feature] = true
|
||||
}
|
||||
|
||||
// read all other settings under [feature_toggles]. If a toggle is
|
||||
// present in both the value in `enable` is overridden.
|
||||
for _, v := range featureTogglesSection.Keys() {
|
||||
if v.Name() == "enable" {
|
||||
continue
|
||||
}
|
||||
|
||||
b, err := strconv.ParseBool(v.Value())
|
||||
if err != nil {
|
||||
return featureToggles, err
|
||||
}
|
||||
|
||||
featureToggles[v.Name()] = b
|
||||
}
|
||||
return featureToggles, nil
|
||||
}
|
||||
|
||||
func valueAsString(section *ini.Section, keyName string, defaultValue string) string {
|
||||
return section.Key(keyName).MustString(defaultValue)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
gokitlog "github.com/go-kit/log"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestLogger(t *testing.T) {
|
||||
require.Equal(t, "logger", ctx.loggedArgs[0][0].(string))
|
||||
require.Equal(t, "one", ctx.loggedArgs[0][1].(string))
|
||||
require.Equal(t, "t", ctx.loggedArgs[0][2].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format("2006-01-02T15:04:05.99-0700"), ctx.loggedArgs[0][3].(fmt.Stringer).String())
|
||||
require.Equal(t, ctx.mockedTime.Format(time.RFC3339Nano), ctx.loggedArgs[0][3].(fmt.Stringer).String())
|
||||
require.Equal(t, "msg", ctx.loggedArgs[0][4].(string))
|
||||
require.Equal(t, "hello 1", ctx.loggedArgs[0][5].(string))
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestLogger(t *testing.T) {
|
||||
require.Equal(t, "logger", ctx.loggedArgs[1][0].(string))
|
||||
require.Equal(t, "two", ctx.loggedArgs[1][1].(string))
|
||||
require.Equal(t, "t", ctx.loggedArgs[0][2].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format("2006-01-02T15:04:05.99-0700"), ctx.loggedArgs[0][3].(fmt.Stringer).String())
|
||||
require.Equal(t, ctx.mockedTime.Format(time.RFC3339Nano), ctx.loggedArgs[0][3].(fmt.Stringer).String())
|
||||
require.Equal(t, "msg", ctx.loggedArgs[1][4].(string))
|
||||
require.Equal(t, "hello 2", ctx.loggedArgs[1][5].(string))
|
||||
|
||||
@@ -54,8 +54,8 @@ func TestLogger(t *testing.T) {
|
||||
require.Equal(t, "logger", ctx.loggedArgs[2][0].(string))
|
||||
require.Equal(t, "three", ctx.loggedArgs[2][1].(string))
|
||||
require.Equal(t, "t", ctx.loggedArgs[2][2].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format("2006-01-02T15:04:05.99-0700"), ctx.loggedArgs[2][3].(fmt.Stringer).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[2][4].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format(time.RFC3339Nano), ctx.loggedArgs[2][3].(fmt.Stringer).String())
|
||||
require.Equal(t, level.Key().(string), ctx.loggedArgs[2][4].(string))
|
||||
require.Equal(t, level.ErrorValue(), ctx.loggedArgs[2][5].(level.Value))
|
||||
require.Equal(t, "msg", ctx.loggedArgs[2][6].(string))
|
||||
require.Equal(t, "hello 3", ctx.loggedArgs[2][7].(string))
|
||||
@@ -66,7 +66,7 @@ func TestLogger(t *testing.T) {
|
||||
require.Equal(t, "key", ctx.loggedArgs[3][2].(string))
|
||||
require.Equal(t, "value", ctx.loggedArgs[3][3].(string))
|
||||
require.Equal(t, "t", ctx.loggedArgs[3][4].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format("2006-01-02T15:04:05.99-0700"), ctx.loggedArgs[3][5].(fmt.Stringer).String())
|
||||
require.Equal(t, ctx.mockedTime.Format(time.RFC3339Nano), ctx.loggedArgs[3][5].(fmt.Stringer).String())
|
||||
require.Equal(t, "msg", ctx.loggedArgs[3][6].(string))
|
||||
require.Equal(t, "hello 4", ctx.loggedArgs[3][7].(string))
|
||||
|
||||
@@ -74,8 +74,8 @@ func TestLogger(t *testing.T) {
|
||||
require.Equal(t, "logger", ctx.loggedArgs[4][0].(string))
|
||||
require.Equal(t, "three", ctx.loggedArgs[4][1].(string))
|
||||
require.Equal(t, "t", ctx.loggedArgs[4][2].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format("2006-01-02T15:04:05.99-0700"), ctx.loggedArgs[4][3].(fmt.Stringer).String())
|
||||
require.Equal(t, "lvl", ctx.loggedArgs[4][4].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format(time.RFC3339Nano), ctx.loggedArgs[4][3].(fmt.Stringer).String())
|
||||
require.Equal(t, level.Key().(string), ctx.loggedArgs[4][4].(string))
|
||||
require.Equal(t, level.ErrorValue(), ctx.loggedArgs[4][5].(level.Value))
|
||||
require.Equal(t, "msg", ctx.loggedArgs[4][6].(string))
|
||||
require.Equal(t, "hello 3 again", ctx.loggedArgs[4][7].(string))
|
||||
@@ -124,8 +124,8 @@ func TestWithPrefix(t *testing.T) {
|
||||
require.Equal(t, "k1", args[2].(string))
|
||||
require.Equal(t, "v1", args[3].(string))
|
||||
require.Equal(t, "t", args[4].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format("2006-01-02T15:04:05.99-0700"), args[5].(fmt.Stringer).String())
|
||||
require.Equal(t, "lvl", args[6].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format(time.RFC3339Nano), args[5].(fmt.Stringer).String())
|
||||
require.Equal(t, level.Key().(string), args[6].(string))
|
||||
require.Equal(t, level.InfoValue(), args[7].(level.Value))
|
||||
require.Equal(t, "msg", args[8].(string))
|
||||
require.Equal(t, "hello", args[9].(string))
|
||||
@@ -145,8 +145,8 @@ func TestWithSuffix(t *testing.T) {
|
||||
require.Equal(t, "logger", args[0].(string))
|
||||
require.Equal(t, "test", args[1].(string))
|
||||
require.Equal(t, "t", args[2].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format("2006-01-02T15:04:05.99-0700"), args[3].(fmt.Stringer).String())
|
||||
require.Equal(t, "lvl", args[4].(string))
|
||||
require.Equal(t, ctx.mockedTime.Format(time.RFC3339Nano), args[3].(fmt.Stringer).String())
|
||||
require.Equal(t, level.Key().(string), args[4].(string))
|
||||
require.Equal(t, level.InfoValue(), args[5].(level.Value))
|
||||
require.Equal(t, "msg", args[6].(string))
|
||||
require.Equal(t, "hello", args[7].(string))
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
gokitsyslog "github.com/go-kit/log/syslog"
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
@@ -25,8 +25,8 @@ type SysLogHandler struct {
|
||||
|
||||
var selector = func(keyvals ...interface{}) syslog.Priority {
|
||||
for i := 0; i < len(keyvals); i += 2 {
|
||||
if level.IsKey(keyvals[i]) {
|
||||
val := level.GetValue(keyvals[i+1])
|
||||
if keyvals[i] == level.Key() {
|
||||
val := keyvals[i+1]
|
||||
if val != nil {
|
||||
switch val {
|
||||
case level.ErrorValue():
|
||||
@@ -39,11 +39,9 @@ var selector = func(keyvals ...interface{}) syslog.Priority {
|
||||
return syslog.LOG_DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return syslog.LOG_INFO
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"time"
|
||||
|
||||
gokitlog "github.com/go-kit/log"
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
"github.com/go-kit/log/level"
|
||||
)
|
||||
|
||||
var (
|
||||
timeFormat = "2006-01-02T15:04:05-0700"
|
||||
timeFormat = time.RFC3339Nano
|
||||
termTimeFormat = "01-02|15:04:05"
|
||||
)
|
||||
|
||||
@@ -25,10 +25,6 @@ const (
|
||||
errorKey = "LOG15_ERROR"
|
||||
)
|
||||
|
||||
func SetTimeFormatGokitLog() {
|
||||
timeFormat = time.RFC3339Nano
|
||||
}
|
||||
|
||||
type terminalLogger struct {
|
||||
w io.Writer
|
||||
}
|
||||
@@ -96,7 +92,6 @@ func getRecord(keyvals ...interface{}) *record {
|
||||
if len(keyvals)%2 == 1 {
|
||||
keyvals = append(keyvals, nil)
|
||||
}
|
||||
|
||||
for i := 0; i < len(keyvals); i += 2 {
|
||||
k, v := keyvals[i], keyvals[i+1]
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/log/level"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"go.etcd.io/etcd/api/v3/version"
|
||||
jaegerpropagator "go.opentelemetry.io/contrib/propagators/jaeger"
|
||||
|
||||
Reference in New Issue
Block a user