update slog/logger (#351)
Изменено (методы logger без форматирования): - Добавлена подготовка и выравнивание аттрибутов для logger - Выравнивание за счет добавления !BADKEY до процессинга log/slog - Добавлено переиспользование метода Log - Удалены методы [Logf, Infof, Debugf, Errorf, Warnf, Fatalf, Tracef] - Обновлены юниттесты - Удален wrapper в пакете logger - Изменен интерфейс logger - Отрефакторены вызовы logger'a в micro Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org> Reviewed-on: #351 Co-authored-by: Evstigneev Denis <danteevstigneev@yandex.ru> Co-committed-by: Evstigneev Denis <danteevstigneev@yandex.ru>
This commit is contained in:
@@ -23,7 +23,7 @@ type Options struct {
|
||||
Name string
|
||||
// Fields holds additional metadata
|
||||
Fields []interface{}
|
||||
// CallerSkipCount number of frmaes to skip
|
||||
// callerSkipCount number of frmaes to skip
|
||||
CallerSkipCount int
|
||||
// ContextAttrFuncs contains funcs that executed before log func on context
|
||||
ContextAttrFuncs []ContextAttrFunc
|
||||
@@ -57,7 +57,6 @@ func NewOptions(opts ...Option) Options {
|
||||
Level: DefaultLevel,
|
||||
Fields: make([]interface{}, 0, 6),
|
||||
Out: os.Stderr,
|
||||
CallerSkipCount: DefaultCallerSkipCount,
|
||||
Context: context.Background(),
|
||||
ContextAttrFuncs: DefaultContextAttrFuncs,
|
||||
AddSource: true,
|
||||
@@ -102,27 +101,20 @@ func WithOutput(out io.Writer) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WitAddStacktrace controls writing stacktrace on error
|
||||
// WithAddStacktrace controls writing stacktrace on error
|
||||
func WithAddStacktrace(v bool) Option {
|
||||
return func(o *Options) {
|
||||
o.AddStacktrace = v
|
||||
}
|
||||
}
|
||||
|
||||
// WitAddSource controls writing source file and pos in log
|
||||
// WithAddSource controls writing source file and pos in log
|
||||
func WithAddSource(v bool) Option {
|
||||
return func(o *Options) {
|
||||
o.AddSource = v
|
||||
}
|
||||
}
|
||||
|
||||
// WithCallerSkipCount set frame count to skip
|
||||
func WithCallerSkipCount(c int) Option {
|
||||
return func(o *Options) {
|
||||
o.CallerSkipCount = c
|
||||
}
|
||||
}
|
||||
|
||||
// WithContext set context
|
||||
func WithContext(ctx context.Context) Option {
|
||||
return func(o *Options) {
|
||||
@@ -198,6 +190,8 @@ func WithMicroKeys() Option {
|
||||
// WithAddCallerSkipCount add skip count for copy logger
|
||||
func WithAddCallerSkipCount(n int) Option {
|
||||
return func(o *Options) {
|
||||
o.CallerSkipCount += n
|
||||
if n > 0 {
|
||||
o.CallerSkipCount += n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user